"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/net/ftp/test_ftp.rb" between
ruby-2.7.3.tar.gz and ruby-2.7.4.tar.gz

About: Ruby is an interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). Stable release of 2.7 series.

test_ftp.rb  (ruby-2.7.3):test_ftp.rb  (ruby-2.7.4)
skipping to change at line 64 skipping to change at line 64
begin begin
ftp = Net::FTP.new ftp = Net::FTP.new
assert_raise(Net::FTPTempError){ ftp.connect(SERVER_ADDR, server.port) } assert_raise(Net::FTPTempError){ ftp.connect(SERVER_ADDR, server.port) }
ensure ensure
ftp.close if ftp ftp.close if ftp
server.close server.close
end end
end end
def test_parse227 def test_parse227
ftp = Net::FTP.new ftp = Net::FTP.new(nil, use_pasv_ip: true)
host, port = ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1,12, 34)") host, port = ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1,12, 34)")
assert_equal("192.168.0.1", host) assert_equal("192.168.0.1", host)
assert_equal(3106, port) assert_equal(3106, port)
assert_raise(Net::FTPReplyError) do assert_raise(Net::FTPReplyError) do
ftp.send(:parse227, "500 Syntax error") ftp.send(:parse227, "500 Syntax error")
end end
assert_raise(Net::FTPProtoError) do assert_raise(Net::FTPProtoError) do
ftp.send(:parse227, "227 Entering Passive Mode") ftp.send(:parse227, "227 Entering Passive Mode")
end end
assert_raise(Net::FTPProtoError) do assert_raise(Net::FTPProtoError) do
ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1,12,34,56)") ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1,12,34,56)")
end end
assert_raise(Net::FTPProtoError) do assert_raise(Net::FTPProtoError) do
ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1)") ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1)")
end end
assert_raise(Net::FTPProtoError) do assert_raise(Net::FTPProtoError) do
ftp.send(:parse227, "227 ) foo bar (") ftp.send(:parse227, "227 ) foo bar (")
end end
ftp = Net::FTP.new
sock = OpenStruct.new
sock.remote_address = OpenStruct.new
sock.remote_address.ip_address = "10.0.0.1"
ftp.instance_variable_set(:@bare_sock, sock)
host, port = ftp.send(:parse227, "227 Entering Passive Mode (192,168,0,1,12,
34)")
assert_equal("10.0.0.1", host)
end end
def test_parse228 def test_parse228
ftp = Net::FTP.new ftp = Net::FTP.new
host, port = ftp.send(:parse228, "228 Entering Long Passive Mode (4,4,192,16 8,0,1,2,12,34)") host, port = ftp.send(:parse228, "228 Entering Long Passive Mode (4,4,192,16 8,0,1,2,12,34)")
assert_equal("192.168.0.1", host) assert_equal("192.168.0.1", host)
assert_equal(3106, port) assert_equal(3106, port)
host, port = ftp.send(:parse228, "228 Entering Long Passive Mode (6,16,16,12 8,0,0,0,0,0,0,0,8,8,0,32,12,65,122,2,12,34)") host, port = ftp.send(:parse228, "228 Entering Long Passive Mode (6,16,16,12 8,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("1080:0000:0000:0000:0008:0800:200c:417a", host)
assert_equal(3106, port) assert_equal(3106, port)
skipping to change at line 2462 skipping to change at line 2470
assert_equal(nil, commands.shift) assert_equal(nil, commands.shift)
ensure ensure
ftp.close if ftp ftp.close if ftp
end end
end end
ensure ensure
server.close server.close
end end
end end
def test_ignore_pasv_ip
commands = []
binary_data = (0..0xff).map {|i| i.chr}.join * 4 * 3
server = create_ftp_server(nil, "127.0.0.1") { |sock|
sock.print("220 (test_ftp).\r\n")
commands.push(sock.gets)
sock.print("331 Please specify the password.\r\n")
commands.push(sock.gets)
sock.print("230 Login successful.\r\n")
commands.push(sock.gets)
sock.print("200 Switching to Binary mode.\r\n")
line = sock.gets
commands.push(line)
data_server = TCPServer.new("127.0.0.1", 0)
port = data_server.local_address.ip_port
sock.printf("227 Entering Passive Mode (999,0,0,1,%s).\r\n",
port.divmod(256).join(","))
commands.push(sock.gets)
sock.print("150 Opening BINARY mode data connection for foo (#{binary_data
.size} bytes)\r\n")
conn = data_server.accept
binary_data.scan(/.{1,1024}/nm) do |s|
conn.print(s)
end
conn.shutdown(Socket::SHUT_WR)
conn.read
conn.close
data_server.close
sock.print("226 Transfer complete.\r\n")
}
begin
begin
ftp = Net::FTP.new
ftp.passive = true
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
# for --jit-wait
ftp.connect("127.0.0.1", server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)
assert_match(/\APASS /, commands.shift)
assert_equal("TYPE I\r\n", commands.shift)
buf = ftp.getbinaryfile("foo", nil)
assert_equal(binary_data, buf)
assert_equal(Encoding::ASCII_8BIT, buf.encoding)
assert_equal("PASV\r\n", commands.shift)
assert_equal("RETR foo\r\n", commands.shift)
assert_equal(nil, commands.shift)
ensure
ftp.close if ftp
end
ensure
server.close
end
end
def test_use_pasv_ip
commands = []
binary_data = (0..0xff).map {|i| i.chr}.join * 4 * 3
server = create_ftp_server(nil, "127.0.0.1") { |sock|
sock.print("220 (test_ftp).\r\n")
commands.push(sock.gets)
sock.print("331 Please specify the password.\r\n")
commands.push(sock.gets)
sock.print("230 Login successful.\r\n")
commands.push(sock.gets)
sock.print("200 Switching to Binary mode.\r\n")
line = sock.gets
commands.push(line)
data_server = TCPServer.new("127.0.0.1", 0)
port = data_server.local_address.ip_port
sock.printf("227 Entering Passive Mode (127,0,0,1,%s).\r\n",
port.divmod(256).join(","))
commands.push(sock.gets)
sock.print("150 Opening BINARY mode data connection for foo (#{binary_data
.size} bytes)\r\n")
conn = data_server.accept
binary_data.scan(/.{1,1024}/nm) do |s|
conn.print(s)
end
conn.shutdown(Socket::SHUT_WR)
conn.read
conn.close
data_server.close
sock.print("226 Transfer complete.\r\n")
}
begin
begin
ftp = Net::FTP.new
ftp.passive = true
ftp.use_pasv_ip = true
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
# for --jit-wait
ftp.connect("127.0.0.1", server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)
assert_match(/\APASS /, commands.shift)
assert_equal("TYPE I\r\n", commands.shift)
buf = ftp.getbinaryfile("foo", nil)
assert_equal(binary_data, buf)
assert_equal(Encoding::ASCII_8BIT, buf.encoding)
assert_equal("PASV\r\n", commands.shift)
assert_equal("RETR foo\r\n", commands.shift)
assert_equal(nil, commands.shift)
ensure
ftp.close if ftp
end
ensure
server.close
end
end
def test_use_pasv_invalid_ip
commands = []
binary_data = (0..0xff).map {|i| i.chr}.join * 4 * 3
server = create_ftp_server(nil, "127.0.0.1") { |sock|
sock.print("220 (test_ftp).\r\n")
commands.push(sock.gets)
sock.print("331 Please specify the password.\r\n")
commands.push(sock.gets)
sock.print("230 Login successful.\r\n")
commands.push(sock.gets)
sock.print("200 Switching to Binary mode.\r\n")
line = sock.gets
commands.push(line)
sock.print("227 Entering Passive Mode (999,0,0,1,48,57).\r\n")
commands.push(sock.gets)
}
begin
begin
ftp = Net::FTP.new
ftp.passive = true
ftp.use_pasv_ip = true
ftp.read_timeout *= 5 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
# for --jit-wait
ftp.connect("127.0.0.1", server.port)
ftp.login
assert_match(/\AUSER /, commands.shift)
assert_match(/\APASS /, commands.shift)
assert_equal("TYPE I\r\n", commands.shift)
assert_raise(SocketError) do
ftp.getbinaryfile("foo", nil)
end
ensure
ftp.close if ftp
end
ensure
server.close
end
end
private private
def create_ftp_server(sleep_time = nil) def create_ftp_server(sleep_time = nil, addr = SERVER_ADDR)
server = TCPServer.new(SERVER_ADDR, 0) server = TCPServer.new(addr, 0)
@thread = Thread.start do @thread = Thread.start do
if sleep_time if sleep_time
sleep(sleep_time) sleep(sleep_time)
end end
sock = server.accept sock = server.accept
begin begin
sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1) sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1)
yield(sock) yield(sock)
sock.shutdown(Socket::SHUT_WR) sock.shutdown(Socket::SHUT_WR)
sock.read unless sock.eof? sock.read unless sock.eof?
 End of changes. 4 change blocks. 
3 lines changed or deleted 162 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)