Use ftp for the service in getaddrinfo/getnameinfo/getservbyname specs

* Solaris cannot resolve 'http' but can resolve 'ftp'.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2018-08-18 19:36:57 +00:00
Родитель 61a33fa8e2
Коммит 10f642ba02
4 изменённых файлов: 55 добавлений и 64 удалений

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

@ -5,26 +5,17 @@ describe 'Addrinfo#getnameinfo' do
describe 'using an IP Addrinfo' do describe 'using an IP Addrinfo' do
SocketSpecs.each_ip_protocol do |family, ip_address| SocketSpecs.each_ip_protocol do |family, ip_address|
before do before do
@addr = Addrinfo.tcp(ip_address, 80) @addr = Addrinfo.tcp(ip_address, 21)
end end
platform_is_not :solaris do it 'returns the node and service names' do
it 'returns the node and service names' do host, service = @addr.getnameinfo
host, service = @addr.getnameinfo service.should == 'ftp'
service.should == 'http'
end
end
platform_is :solaris do
it 'returns the node and service names' do
host, service = @addr.getnameinfo
service.should == '80'
end
end end
it 'accepts flags as a Fixnum as the first argument' do it 'accepts flags as a Fixnum as the first argument' do
host, service = @addr.getnameinfo(Socket::NI_NUMERICSERV) host, service = @addr.getnameinfo(Socket::NI_NUMERICSERV)
service.should == '80' service.should == '21'
end end
end end
end end

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

@ -112,14 +112,14 @@ end
describe 'Socket.getaddrinfo' do describe 'Socket.getaddrinfo' do
describe 'without global reverse lookups' do describe 'without global reverse lookups' do
it 'returns an Array' do it 'returns an Array' do
Socket.getaddrinfo(nil, 'http').should be_an_instance_of(Array) Socket.getaddrinfo(nil, 'ftp').should be_an_instance_of(Array)
end end
it 'accepts a Fixnum as the address family' do it 'accepts a Fixnum as the address family' do
array = Socket.getaddrinfo(nil, 'http', Socket::AF_INET)[0] array = Socket.getaddrinfo(nil, 'ftp', Socket::AF_INET)[0]
array[0].should == 'AF_INET' array[0].should == 'AF_INET'
array[1].should == 80 array[1].should == 21
array[2].should == '127.0.0.1' array[2].should == '127.0.0.1'
array[3].should == '127.0.0.1' array[3].should == '127.0.0.1'
array[4].should == Socket::AF_INET array[4].should == Socket::AF_INET
@ -128,10 +128,10 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a Fixnum as the address family using IPv6' do it 'accepts a Fixnum as the address family using IPv6' do
array = Socket.getaddrinfo(nil, 'http', Socket::AF_INET6)[0] array = Socket.getaddrinfo(nil, 'ftp', Socket::AF_INET6)[0]
array[0].should == 'AF_INET6' array[0].should == 'AF_INET6'
array[1].should == 80 array[1].should == 21
array[2].should == '::1' array[2].should == '::1'
array[3].should == '::1' array[3].should == '::1'
array[4].should == Socket::AF_INET6 array[4].should == Socket::AF_INET6
@ -140,10 +140,10 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a Symbol as the address family' do it 'accepts a Symbol as the address family' do
array = Socket.getaddrinfo(nil, 'http', :INET)[0] array = Socket.getaddrinfo(nil, 'ftp', :INET)[0]
array[0].should == 'AF_INET' array[0].should == 'AF_INET'
array[1].should == 80 array[1].should == 21
array[2].should == '127.0.0.1' array[2].should == '127.0.0.1'
array[3].should == '127.0.0.1' array[3].should == '127.0.0.1'
array[4].should == Socket::AF_INET array[4].should == Socket::AF_INET
@ -152,10 +152,10 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a Symbol as the address family using IPv6' do it 'accepts a Symbol as the address family using IPv6' do
array = Socket.getaddrinfo(nil, 'http', :INET6)[0] array = Socket.getaddrinfo(nil, 'ftp', :INET6)[0]
array[0].should == 'AF_INET6' array[0].should == 'AF_INET6'
array[1].should == 80 array[1].should == 21
array[2].should == '::1' array[2].should == '::1'
array[3].should == '::1' array[3].should == '::1'
array[4].should == Socket::AF_INET6 array[4].should == Socket::AF_INET6
@ -164,10 +164,10 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a String as the address family' do it 'accepts a String as the address family' do
array = Socket.getaddrinfo(nil, 'http', 'INET')[0] array = Socket.getaddrinfo(nil, 'ftp', 'INET')[0]
array[0].should == 'AF_INET' array[0].should == 'AF_INET'
array[1].should == 80 array[1].should == 21
array[2].should == '127.0.0.1' array[2].should == '127.0.0.1'
array[3].should == '127.0.0.1' array[3].should == '127.0.0.1'
array[4].should == Socket::AF_INET array[4].should == Socket::AF_INET
@ -176,10 +176,10 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a String as the address family using IPv6' do it 'accepts a String as the address family using IPv6' do
array = Socket.getaddrinfo(nil, 'http', 'INET6')[0] array = Socket.getaddrinfo(nil, 'ftp', 'INET6')[0]
array[0].should == 'AF_INET6' array[0].should == 'AF_INET6'
array[1].should == 80 array[1].should == 21
array[2].should == '::1' array[2].should == '::1'
array[3].should == '::1' array[3].should == '::1'
array[4].should == Socket::AF_INET6 array[4].should == Socket::AF_INET6
@ -192,10 +192,10 @@ describe 'Socket.getaddrinfo' do
dummy.stub!(:to_str).and_return('127.0.0.1') dummy.stub!(:to_str).and_return('127.0.0.1')
array = Socket.getaddrinfo(dummy, 'http')[0] array = Socket.getaddrinfo(dummy, 'ftp')[0]
array[0].should == 'AF_INET' array[0].should == 'AF_INET'
array[1].should == 80 array[1].should == 21
array[2].should == '127.0.0.1' array[2].should == '127.0.0.1'
array[3].should == '127.0.0.1' array[3].should == '127.0.0.1'
array[4].should == Socket::AF_INET array[4].should == Socket::AF_INET
@ -208,10 +208,10 @@ describe 'Socket.getaddrinfo' do
dummy.stub!(:to_str).and_return('INET') dummy.stub!(:to_str).and_return('INET')
array = Socket.getaddrinfo(nil, 'http', dummy)[0] array = Socket.getaddrinfo(nil, 'ftp', dummy)[0]
array[0].should == 'AF_INET' array[0].should == 'AF_INET'
array[1].should == 80 array[1].should == 21
array[2].should == '127.0.0.1' array[2].should == '127.0.0.1'
array[3].should == '127.0.0.1' array[3].should == '127.0.0.1'
array[4].should == Socket::AF_INET array[4].should == Socket::AF_INET
@ -225,9 +225,9 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a Fixnum as the socket type' do it 'accepts a Fixnum as the socket type' do
Socket.getaddrinfo(nil, 'http', :INET, Socket::SOCK_STREAM)[0].should == [ Socket.getaddrinfo(nil, 'ftp', :INET, Socket::SOCK_STREAM)[0].should == [
'AF_INET', 'AF_INET',
80, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
@ -237,9 +237,9 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a Symbol as the socket type' do it 'accepts a Symbol as the socket type' do
Socket.getaddrinfo(nil, 'http', :INET, :STREAM)[0].should == [ Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM)[0].should == [
'AF_INET', 'AF_INET',
80, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
@ -249,9 +249,9 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a String as the socket type' do it 'accepts a String as the socket type' do
Socket.getaddrinfo(nil, 'http', :INET, 'STREAM')[0].should == [ Socket.getaddrinfo(nil, 'ftp', :INET, 'STREAM')[0].should == [
'AF_INET', 'AF_INET',
80, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
@ -265,9 +265,9 @@ describe 'Socket.getaddrinfo' do
dummy.stub!(:to_str).and_return('STREAM') dummy.stub!(:to_str).and_return('STREAM')
Socket.getaddrinfo(nil, 'http', :INET, dummy)[0].should == [ Socket.getaddrinfo(nil, 'ftp', :INET, dummy)[0].should == [
'AF_INET', 'AF_INET',
80, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
@ -293,12 +293,12 @@ describe 'Socket.getaddrinfo' do
end end
it 'accepts a Fixnum as the flags' do it 'accepts a Fixnum as the flags' do
addr = Socket.getaddrinfo(nil, 'http', :INET, :STREAM, addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
Socket::IPPROTO_TCP, Socket::AI_PASSIVE) Socket::IPPROTO_TCP, Socket::AI_PASSIVE)
addr[0].should == [ addr[0].should == [
'AF_INET', 'AF_INET',
80, 21,
'0.0.0.0', '0.0.0.0',
'0.0.0.0', '0.0.0.0',
Socket::AF_INET, Socket::AF_INET,
@ -308,11 +308,11 @@ describe 'Socket.getaddrinfo' do
end end
it 'performs a reverse lookup when the reverse_lookup argument is true' do it 'performs a reverse lookup when the reverse_lookup argument is true' do
addr = Socket.getaddrinfo(nil, 'http', :INET, :STREAM, addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
Socket::IPPROTO_TCP, 0, true)[0] Socket::IPPROTO_TCP, 0, true)[0]
addr[0].should == 'AF_INET' addr[0].should == 'AF_INET'
addr[1].should == 80 addr[1].should == 21
addr[2].should be_an_instance_of(String) addr[2].should be_an_instance_of(String)
addr[2].should_not == addr[3] addr[2].should_not == addr[3]
@ -321,11 +321,11 @@ describe 'Socket.getaddrinfo' do
end end
it 'performs a reverse lookup when the reverse_lookup argument is :hostname' do it 'performs a reverse lookup when the reverse_lookup argument is :hostname' do
addr = Socket.getaddrinfo(nil, 'http', :INET, :STREAM, addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
Socket::IPPROTO_TCP, 0, :hostname)[0] Socket::IPPROTO_TCP, 0, :hostname)[0]
addr[0].should == 'AF_INET' addr[0].should == 'AF_INET'
addr[1].should == 80 addr[1].should == 21
addr[2].should be_an_instance_of(String) addr[2].should be_an_instance_of(String)
addr[2].should_not == addr[3] addr[2].should_not == addr[3]
@ -334,12 +334,12 @@ describe 'Socket.getaddrinfo' do
end end
it 'performs a reverse lookup when the reverse_lookup argument is :numeric' do it 'performs a reverse lookup when the reverse_lookup argument is :numeric' do
addr = Socket.getaddrinfo(nil, 'http', :INET, :STREAM, addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
Socket::IPPROTO_TCP, 0, :numeric)[0] Socket::IPPROTO_TCP, 0, :numeric)[0]
addr.should == [ addr.should == [
'AF_INET', 'AF_INET',
80, 21,
'127.0.0.1', '127.0.0.1',
'127.0.0.1', '127.0.0.1',
Socket::AF_INET, Socket::AF_INET,
@ -360,10 +360,10 @@ describe 'Socket.getaddrinfo' do
end end
it 'returns an address honoring the global lookup option' do it 'returns an address honoring the global lookup option' do
addr = Socket.getaddrinfo(nil, 'http', :INET)[0] addr = Socket.getaddrinfo(nil, 'ftp', :INET)[0]
addr[0].should == 'AF_INET' addr[0].should == 'AF_INET'
addr[1].should == 80 addr[1].should == 21
# We don't have control over this value and there's no way to test this # We don't have control over this value and there's no way to test this
# without relying on Socket.getaddrinfo()'s own behaviour (meaning this # without relying on Socket.getaddrinfo()'s own behaviour (meaning this

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

@ -65,7 +65,7 @@ end
describe 'Socket.getnameinfo' do describe 'Socket.getnameinfo' do
describe 'using a String as the first argument' do describe 'using a String as the first argument' do
before do before do
@addr = Socket.sockaddr_in(80, '127.0.0.1') @addr = Socket.sockaddr_in(21, '127.0.0.1')
end end
it 'raises SocketError or TypeError when using an invalid String' do it 'raises SocketError or TypeError when using an invalid String' do
@ -76,7 +76,7 @@ describe 'Socket.getnameinfo' do
describe 'without custom flags' do describe 'without custom flags' do
it 'returns an Array containing the hostname and service name' do it 'returns an Array containing the hostname and service name' do
Socket.getnameinfo(@addr).should == [SocketSpecs.hostname_reverse_lookup, 'http'] Socket.getnameinfo(@addr).should == [SocketSpecs.hostname_reverse_lookup, 'ftp']
end end
end end
@ -86,7 +86,7 @@ describe 'Socket.getnameinfo' do
%w{127.0.0.1 ::1}.include?(array[0]).should == true %w{127.0.0.1 ::1}.include?(array[0]).should == true
array[1].should == 'http' array[1].should == 'ftp'
end end
end end
end end
@ -98,7 +98,7 @@ describe 'Socket.getnameinfo' do
describe 'using a 3 element Array as the first argument' do describe 'using a 3 element Array as the first argument' do
before do before do
@addr = [family_name, 80, @hostname] @addr = [family_name, 21, @hostname]
end end
it 'raises ArgumentError when using an invalid Array' do it 'raises ArgumentError when using an invalid Array' do
@ -110,14 +110,14 @@ describe 'Socket.getnameinfo' do
array = Socket.getnameinfo(@addr) array = Socket.getnameinfo(@addr)
array.should be_an_instance_of(Array) array.should be_an_instance_of(Array)
array[0].should include(@hostname) array[0].should include(@hostname)
array[1].should == 'http' array[1].should == 'ftp'
end end
end end
platform_is_not :windows do platform_is_not :windows do
describe 'using NI_NUMERICHOST as the flag' do describe 'using NI_NUMERICHOST as the flag' do
it 'returns an Array containing the numeric hostname and service name' do it 'returns an Array containing the numeric hostname and service name' do
Socket.getnameinfo(@addr, Socket::NI_NUMERICHOST).should == [ip_address, 'http'] Socket.getnameinfo(@addr, Socket::NI_NUMERICHOST).should == [ip_address, 'ftp']
end end
end end
end end
@ -125,7 +125,7 @@ describe 'Socket.getnameinfo' do
describe 'using a 4 element Array as the first argument' do describe 'using a 4 element Array as the first argument' do
before do before do
@addr = [family_name, 80, ip_address, ip_address] @addr = [family_name, 21, ip_address, ip_address]
end end
describe 'without custom flags' do describe 'without custom flags' do
@ -133,22 +133,22 @@ describe 'Socket.getnameinfo' do
array = Socket.getnameinfo(@addr) array = Socket.getnameinfo(@addr)
array.should be_an_instance_of(Array) array.should be_an_instance_of(Array)
array[0].should == @hostname array[0].should == @hostname
array[1].should == 'http' array[1].should == 'ftp'
end end
it 'uses the 3rd value as the hostname if the 4th is not present' do it 'uses the 3rd value as the hostname if the 4th is not present' do
addr = [family_name, 80, ip_address, nil] addr = [family_name, 21, ip_address, nil]
array = Socket.getnameinfo(addr) array = Socket.getnameinfo(addr)
array.should be_an_instance_of(Array) array.should be_an_instance_of(Array)
array[0].should == @hostname array[0].should == @hostname
array[1].should == 'http' array[1].should == 'ftp'
end end
end end
describe 'using NI_NUMERICHOST as the flag' do describe 'using NI_NUMERICHOST as the flag' do
it 'returns an Array containing the numeric hostname and service name' do it 'returns an Array containing the numeric hostname and service name' do
Socket.getnameinfo(@addr, Socket::NI_NUMERICHOST).should == [ip_address, 'http'] Socket.getnameinfo(@addr, Socket::NI_NUMERICHOST).should == [ip_address, 'ftp']
end end
end end
end end

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

@ -10,12 +10,12 @@ describe "Socket#getservbyname" do
Socket.getservbyname('discard', 'tcp').should == 9 Socket.getservbyname('discard', 'tcp').should == 9
end end
it 'returns the port for service "http"' do it 'returns the port for service "ftp"' do
Socket.getservbyname('http').should == 80 Socket.getservbyname('ftp').should == 21
end end
it 'returns the port for service "http" with protocol "tcp"' do it 'returns the port for service "ftp" with protocol "tcp"' do
Socket.getservbyname('http', 'tcp').should == 80 Socket.getservbyname('ftp', 'tcp').should == 21
end end
it "returns the port for service 'domain' with protocol 'udp'" do it "returns the port for service 'domain' with protocol 'udp'" do