Project

General

Profile

Bug #15900 ยป resolv_dns_each_name.patch

Tietew (Toru Iwase), 06/05/2019 11:04 AM

View differences:

lib/resolv.rb
451 451
      case address
452 452
      when Name
453 453
        ptr = address
454
      when IPv4, IPv6
455
        ptr = address.to_name
454 456
      when IPv4::Regex
455 457
        ptr = IPv4.create(address).to_name
456 458
      when IPv6::Regex
test/resolv/test_dns.rb
265 265
  def test_no_fd_leak_unconnected
266 266
    assert_no_fd_leak {Resolv::DNS.new}
267 267
  end
268

  
269
  def test_each_name
270
    dns = Resolv::DNS.new
271
    def dns.each_resource(name, typeclass)
272
      yield typeclass.new(name)
273
    end
274

  
275
    dns.each_name('127.0.0.1') do |ptr|
276
      assert_equal('1.0.0.127.in-addr.arpa', ptr.to_s)
277
    end
278
    dns.each_name(Resolv::IPv4.create('127.0.0.1')) do |ptr|
279
      assert_equal('1.0.0.127.in-addr.arpa', ptr.to_s)
280
    end
281
    dns.each_name('::1') do |ptr|
282
      assert_equal('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa', ptr.to_s)
283
    end
284
    dns.each_name(Resolv::IPv6.create('::1')) do |ptr|
285
      assert_equal('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa', ptr.to_s)
286
    end
287
    dns.each_name(Resolv::DNS::Name.create('1.0.0.127.in-addr.arpa.')) do |ptr|
288
      assert_equal('1.0.0.127.in-addr.arpa', ptr.to_s)
289
    end
290
    assert_raise(Resolv::ResolvError) { dns.each_name('example.com') }
291
  end
268 292
end