2010-04-18 05:09:46 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require 'resolv'
|
|
|
|
require 'socket'
|
2013-12-21 04:45:50 -05:00
|
|
|
require 'tempfile'
|
2010-04-18 05:09:46 -04:00
|
|
|
|
|
|
|
class TestResolvAddr < Test::Unit::TestCase
|
|
|
|
def test_invalid_ipv4_address
|
|
|
|
assert_not_match(Resolv::IPv4::Regex, "1.2.3.256", "[ruby-core:29501]")
|
|
|
|
1000.times {|i|
|
|
|
|
if i < 256
|
|
|
|
assert_match(Resolv::IPv4::Regex, "#{i}.#{i}.#{i}.#{i}")
|
|
|
|
else
|
|
|
|
assert_not_match(Resolv::IPv4::Regex, "#{i}.#{i}.#{i}.#{i}")
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2013-12-20 22:37:26 -05:00
|
|
|
|
|
|
|
def test_invalid_byte_comment
|
|
|
|
bug9273 = '[ruby-core:59239] [Bug #9273]'
|
2014-05-25 10:00:16 -04:00
|
|
|
Tempfile.create('resolv_test_addr_') do |tmpfile|
|
2013-12-20 22:37:26 -05:00
|
|
|
tmpfile.print("\xff\x00\x40")
|
|
|
|
tmpfile.close
|
|
|
|
hosts = Resolv::Hosts.new(tmpfile.path)
|
|
|
|
assert_nothing_raised(ArgumentError, bug9273) do
|
|
|
|
hosts.each_address("") {break}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-04-18 05:09:46 -04:00
|
|
|
end
|