* 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
This commit is contained in:
shugo 2012-03-26 10:52:06 +00:00
Родитель 8c89d8ef72
Коммит cae1d532f5
2 изменённых файлов: 107 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Mon Mar 26 19:49:49 2012 Shugo Maeda <shugo@ruby-lang.org>
* 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 <shugo@ruby-lang.org>
* lib/net/ftp.rb (parse227, parse228, parse229): refactored.

102
test/net/ftp/test_ftp.rb Normal file
Просмотреть файл

@ -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