summaryrefslogtreecommitdiff
path: root/test/net/ftp
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-26 10:52:06 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-26 10:52:06 +0000
commitcae1d532f5969d794179f398a6c867d5f402c21c (patch)
treee215010e353881256ed8732dd8f909c678c6bf2f /test/net/ftp
parent8c89d8ef727d7c7099ed92b21bf8de12ffbeb197 (diff)
* 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
Diffstat (limited to 'test/net/ftp')
-rw-r--r--test/net/ftp/test_ftp.rb102
1 files changed, 102 insertions, 0 deletions
diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb
new file mode 100644
index 0000000..2423940
--- /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