Replace SocketError with Socket::ResolutionError in rsock_raise_socket_error

rsock_raise_socket_error is called only when getaddrinfo and getaddrname fail
This commit is contained in:
Misaki Shioi 2023-11-23 16:49:41 +09:00 committed by Yusuke Endoh
parent e9050270d7
commit 52f6de4196
4 changed files with 20 additions and 8 deletions

View file

@ -91,20 +91,20 @@ class TestSocket < Test::Unit::TestCase
def test_getaddrinfo
# This should not send a DNS query because AF_UNIX.
assert_raise(SocketError) { Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") }
assert_raise(Socket::ResolutionError) { Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") }
end
def test_getaddrinfo_raises_no_errors_on_port_argument_of_0 # [ruby-core:29427]
assert_nothing_raised('[ruby-core:29427]'){ Socket.getaddrinfo('localhost', 0, Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
assert_nothing_raised('[ruby-core:29427]'){ Socket.getaddrinfo('localhost', '0', Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
assert_nothing_raised('[ruby-core:29427]'){ Socket.getaddrinfo('localhost', '00', Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
assert_raise(SocketError, '[ruby-core:29427]'){ Socket.getaddrinfo(nil, nil, Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
assert_raise(Socket::ResolutionError, '[ruby-core:29427]'){ Socket.getaddrinfo(nil, nil, Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
assert_nothing_raised('[ruby-core:29427]'){ TCPServer.open('localhost', 0) {} }
end
def test_getnameinfo
assert_raise(SocketError) { Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) }
assert_raise(Socket::ResolutionError) { Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) }
assert_raise(ArgumentError) {Socket.getnameinfo(["AF_INET", "http\0", "example.net"])}
assert_raise(ArgumentError) {Socket.getnameinfo(["AF_INET", "http", "example.net\0"])}
end
@ -770,4 +770,12 @@ class TestSocket < Test::Unit::TestCase
s2.close
end
def test_resolurion_error_error_code
begin
Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX")
rescue => e
assert_equal(e.error_code, Socket::EAI_FAMILY)
end
end
end if defined?(Socket)