* lib/open-uri.rb (URI::FTP#buffer_open): use the port specified in

the URI.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-09-12 13:49:07 +00:00
parent c35f659524
commit 188e9667dc
3 changed files with 46 additions and 1 deletions

View file

@ -385,5 +385,44 @@ class TestOpenURI < Test::Unit::TestCase
}
end
def test_ftp
TCPServer.open("127.0.0.1", 0) {|serv|
_, port, _, host = serv.addr
th = Thread.new {
s = serv.accept
begin
s.print "220 Test FTP Server\r\n"
assert_equal("USER anonymous\r\n", s.gets); s.print "331 name ok\r\n"
assert_match(/\APASS .*\r\n/, s.gets); s.print "230 logged in\r\n"
assert_equal("TYPE I\r\n", s.gets); s.print "200 type set to I\r\n"
assert_equal("CWD foo\r\n", s.gets); s.print "250 CWD successful\r\n"
assert_equal("PASV\r\n", s.gets)
TCPServer.open("127.0.0.1", 0) {|data_serv|
_, data_serv_port, _, data_serv_host = data_serv.addr
hi = data_serv_port >> 8
lo = data_serv_port & 0xff
s.print "227 Entering Passive Mode (127,0,0,1,#{hi},#{lo}).\r\n"
assert_equal("RETR bar\r\n", s.gets); s.print "150 file okay\r\n"
data_sock = data_serv.accept
begin
data_sock << "content"
ensure
data_sock.close
end
s.print "226 transfer complete\r\n"
assert_nil(s.gets)
}
ensure
s.close if s
end
}
begin
content = URI("ftp://#{host}:#{port}/foo/bar").read
assert_equal("content", content)
ensure
Thread.kill(th)
end
}
end
end