Backport #3711: IPAddr must not make DNS lookups via IPSocket.getaddress
http://redmine.ruby-lang.org/issues/show/3711

Author: Philipp Kempgen
Status: Open, Priority: Normal
Category: lib

class MustNotCallError < NotImplementedError ; end

class IpAddrNoResolvTestCase < Test::Unit::TestCase
	def setup()
		class << IPSocket
			alias original_getaddress getaddress
			def getaddress( host )
				# DNS lookups are slow and totally unnecessary for IP addresses
				raise MustNotCallError.new( 'IPAddr.new() must not call IPSocket.getaddress()!' )
			end
		end
	end
	def test_ipaddr_must_not_resolve_valid_ipv4_address
		assert_nothing_raised { IPAddr.new( '1.2.3.4', Socket::AF_INET ) }
	end
	def test_ipaddr_must_not_resolve_invalid_ipv4_style_address
		assert_raise( ArgumentError ) { IPAddr.new( '1.2.3.400', Socket::AF_INET ) }
	end
	def test_ipaddr_must_not_resolve_valid_ipv6_address
		assert_nothing_raised { IPAddr.new( '::', Socket::AF_INET6 ) }
	end
	def test_ipaddr_must_not_resolve_invalid_ipv6_style_address
		assert_raise( ArgumentError ) { IPAddr.new( '::1::', Socket::AF_INET6 ) }
	end
end


----------------------------------------
http://redmine.ruby-lang.org