From cae1d532f5969d794179f398a6c867d5f402c21c Mon Sep 17 00:00:00 2001 From: shugo Date: Mon, 26 Mar 2012 10:52:06 +0000 Subject: [PATCH] * test/net/ftp/test_ftp.rb: add the test, which was forgotten in the previous commit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++ test/net/ftp/test_ftp.rb | 102 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 test/net/ftp/test_ftp.rb diff --git a/ChangeLog b/ChangeLog index b9487ea201..1975c04ee3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Mar 26 19:49:49 2012 Shugo Maeda + + * test/net/ftp/test_ftp.rb: add the test, which was forgotten in the + previous commit. + Mon Mar 26 19:37:27 2012 Shugo Maeda * lib/net/ftp.rb (parse227, parse228, parse229): refactored. diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb new file mode 100644 index 0000000000..242394063c --- /dev/null +++ b/test/net/ftp/test_ftp.rb @@ -0,0 +1,102 @@ +require "net/ftp" +require "test/unit" +require "ostruct" + +class FTPTest < Test::Unit::TestCase + def test_not_connected + ftp = Net::FTP.new + assert_raise(Net::FTPConnectionError) do + ftp.quit + end + end + + def test_parse227 + ftp = Net::FTP.new + host, port = ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1,12,34)") + assert_equal("192.168.0.1", host) + assert_equal(3106, port) + assert_raise(Net::FTPReplyError) do + ftp.send(:parse227, "500 Syntax error") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse227, "227 Entering Passive Mode") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1,12,34,56)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse227, "227 ) foo bar (") + end + end + + def test_parse228 + ftp = Net::FTP.new + host, port = ftp.send(:parse228, "228 Entering Long Passive Mode (4,4,192,168,0,1,2,12,34)") + assert_equal("192.168.0.1", host) + assert_equal(3106, port) + host, port = ftp.send(:parse228, "228 Entering Long Passive Mode (6,16,16,128,0,0,0,0,0,0,0,8,8,0,32,12,65,122,2,12,34)") + assert_equal("1080:0000:0000:0000:0008:0800:200c:417a", host) + assert_equal(3106, port) + assert_raise(Net::FTPReplyError) do + ftp.send(:parse228, "500 Syntax error") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse228, "228 Entering Passive Mode") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse228, "228 Entering Long Passive Mode (6,4,192,168,0,1,2,12,34)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse228, "228 Entering Long Passive Mode (4,4,192,168,0,1,3,12,34,56)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse228, "228 Entering Long Passive Mode (4,16,16,128,0,0,0,0,0,0,0,8,8,0,32,12,65,122,2,12,34)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse228, "228 Entering Long Passive Mode (6,16,16,128,0,0,0,0,0,0,0,8,8,0,32,12,65,122,3,12,34,56)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse228, "228 Entering Long Passive Mode (6,16,16,128,0,0,0,0,0,0,0,8,8,0,32,12,65,122,2,12,34,56)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse227, "227 ) foo bar (") + end + end + + def test_parse229 + ftp = Net::FTP.new + sock = OpenStruct.new + sock.peeraddr = [nil, nil, nil, "1080:0000:0000:0000:0008:0800:200c:417a"] + ftp.instance_variable_set(:@sock, sock) + host, port = ftp.send(:parse229, "229 Entering Passive Mode (|||3106|)") + assert_equal("1080:0000:0000:0000:0008:0800:200c:417a", host) + assert_equal(3106, port) + host, port = ftp.send(:parse229, "229 Entering Passive Mode (!!!3106!)") + assert_equal("1080:0000:0000:0000:0008:0800:200c:417a", host) + assert_equal(3106, port) + host, port = ftp.send(:parse229, "229 Entering Passive Mode (~~~3106~)") + assert_equal("1080:0000:0000:0000:0008:0800:200c:417a", host) + assert_equal(3106, port) + assert_raise(Net::FTPReplyError) do + ftp.send(:parse229, "500 Syntax error") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse229, "229 Entering Passive Mode") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse229, "229 Entering Passive Mode (|!!3106!)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse229, "229 Entering Passive Mode ( 3106 )") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse229, "229 Entering Passive Mode (\x7f\x7f\x7f3106\x7f)") + end + assert_raise(Net::FTPProtoError) do + ftp.send(:parse229, "229 ) foo bar (") + end + end +end