dnsruby 1.57.0 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.travis.yml +1 -1
  4. data/README.md +2 -2
  5. data/RELEASE_NOTES.md +16 -0
  6. data/Rakefile +2 -0
  7. data/dnsruby.gemspec +2 -0
  8. data/lib/dnsruby.rb +5 -0
  9. data/lib/dnsruby/bit_mapping.rb +138 -0
  10. data/lib/dnsruby/bitmap.rb +108 -0
  11. data/lib/dnsruby/message/decoder.rb +90 -80
  12. data/lib/dnsruby/message/message.rb +16 -3
  13. data/lib/dnsruby/message/section.rb +3 -3
  14. data/lib/dnsruby/name.rb +2 -2
  15. data/lib/dnsruby/packet_sender.rb +73 -1
  16. data/lib/dnsruby/resolv.rb +56 -42
  17. data/lib/dnsruby/resolver.rb +95 -73
  18. data/lib/dnsruby/resource/GPOS.rb +9 -3
  19. data/lib/dnsruby/resource/HIP.rb +1 -1
  20. data/lib/dnsruby/resource/IN.rb +3 -1
  21. data/lib/dnsruby/resource/NAPTR.rb +2 -2
  22. data/lib/dnsruby/resource/NSEC3.rb +2 -2
  23. data/lib/dnsruby/resource/NXT.rb +302 -0
  24. data/lib/dnsruby/resource/OPT.rb +2 -2
  25. data/lib/dnsruby/resource/TXT.rb +2 -2
  26. data/lib/dnsruby/resource/generic.rb +1 -0
  27. data/lib/dnsruby/resource/type_bitmap.rb +0 -0
  28. data/lib/dnsruby/select_thread.rb +174 -83
  29. data/lib/dnsruby/single_resolver.rb +2 -2
  30. data/lib/dnsruby/version.rb +1 -1
  31. data/lib/dnsruby/zone_reader.rb +19 -9
  32. data/lib/dnsruby/zone_transfer.rb +1 -1
  33. data/test/spec_helper.rb +9 -1
  34. data/test/tc_axfr.rb +17 -4
  35. data/test/tc_gpos.rb +3 -3
  36. data/test/tc_message.rb +7 -1
  37. data/test/tc_nxt.rb +192 -0
  38. data/test/tc_recur.rb +2 -1
  39. data/test/tc_resolv.rb +73 -0
  40. data/test/tc_resolver.rb +22 -4
  41. data/test/tc_rr-opt.rb +9 -8
  42. data/test/tc_rr.rb +22 -0
  43. data/test/tc_single_resolver.rb +15 -15
  44. data/test/tc_soak.rb +154 -65
  45. data/test/tc_soak_base.rb +15 -15
  46. data/test/tc_tcp.rb +1 -1
  47. data/test/tc_tcp_pipelining.rb +203 -0
  48. data/test/tc_zone_reader.rb +73 -0
  49. data/test/test_dnsserver.rb +208 -0
  50. data/test/test_utils.rb +49 -0
  51. data/test/ts_offline.rb +59 -41
  52. data/test/ts_online.rb +92 -63
  53. metadata +40 -3
  54. data/test/tc_dnsruby.rb +0 -51
@@ -114,7 +114,7 @@ module Dnsruby
114
114
  end
115
115
  end
116
116
 
117
- isr = PacketSender.new({:server=>@server, :dnssec=>@dnssec,
117
+ isr = PacketSender.new({:server=>@server, :port=>@port, :dnssec=>@dnssec,
118
118
  :use_tcp=>@use_tcp, :no_tcp=>@no_tcp, :packet_timeout=>@packet_timeout,
119
119
  :tsig => @tsig, :ignore_truncation=>@ignore_truncation,
120
120
  :src_address=>@src_address, :src_address6=>@src_address6, :src_port=>@src_port,
@@ -174,4 +174,4 @@ module Dnsruby
174
174
  alias :query_timeout :packet_timeout
175
175
  alias :query_timeout= :packet_timeout=
176
176
  end
177
- end
177
+ end
@@ -1,3 +1,3 @@
1
1
  module Dnsruby
2
- VERSION = '1.57.0'
2
+ VERSION = '1.58.0'
3
3
  end
@@ -42,14 +42,24 @@ module Dnsruby
42
42
  @in_quoted_section = false
43
43
  end
44
44
 
45
- # Takes a filename string and attempts to load a zone. Returns a list
46
- # of RRs if successful, nil otherwise.
47
- def process_file(file)
48
- line_num = 0
45
+ # Takes a filename string, or any type of IO object, and attempts to load a zone.
46
+ # Returns a list of RRs if successful, nil otherwise.
47
+ def process_file(source)
48
+ if source.is_a?(String)
49
+ File.open(source) do |file|
50
+ process_io(file)
51
+ end
52
+ else
53
+ process_io(source)
54
+ end
55
+ end
56
+
57
+ # Iterate over each line in a IO object, and process it.
58
+ # Returns a list of RRs if successful, nil otherwise.
59
+ def process_io(io)
49
60
  zone = nil
50
- IO.foreach(file) { |line|
61
+ io.each do |line|
51
62
  begin
52
-
53
63
  ret = process_line(line)
54
64
  if (ret)
55
65
  rr = RR.create(ret)
@@ -59,9 +69,9 @@ module Dnsruby
59
69
  zone.push(rr)
60
70
  end
61
71
  rescue Exception => e
62
- raise ParseException.new("Error reading line #{line_num} of #{file} : [#{line}]")
72
+ raise ParseException.new("Error reading line #{io.lineno} of #{io.inspect} : [#{line}]")
63
73
  end
64
- }
74
+ end
65
75
  return zone
66
76
  end
67
77
 
@@ -345,7 +355,7 @@ module Dnsruby
345
355
  Types::PTR, Types::DNAME].include?type_was)
346
356
  # if (line[line.length-1, 1] != ".")
347
357
  if (!(/\.\z/ =~ line))
348
- line = line + "." + @origin.to_s + "."
358
+ line = line + "." + @origin.to_s
349
359
  end
350
360
  end
351
361
  # Other RRs have several names. These should be parsed by Dnsruby,
@@ -39,7 +39,7 @@ module Dnsruby
39
39
  # * res.tsig=(key_name, key)
40
40
  # * res.tsig=nil # Don't sign the transfer
41
41
  def tsig=(*args)
42
- @tsig = SingleResolver.get_tsig(args)
42
+ @tsig = Resolver.get_tsig(args)
43
43
  end
44
44
 
45
45
 
@@ -14,4 +14,12 @@ end
14
14
 
15
15
  require 'minitest'
16
16
  require 'minitest/autorun'
17
- require 'dnsruby'
17
+
18
+ # This is in a self invoking anonymous lambda so local variables do not
19
+ # leak to the outer scope.
20
+ -> do
21
+ load_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
22
+ $LOAD_PATH.unshift(load_dir) unless $LOAD_PATH.include?(load_dir)
23
+ require_relative '../lib/dnsruby'
24
+ require_relative 'test_utils'
25
+ end.()
@@ -20,12 +20,25 @@ class TestAxfr < Minitest::Test
20
20
  def test_axfr
21
21
  zt = Dnsruby::ZoneTransfer.new
22
22
  zt.transfer_type = Dnsruby::Types.AXFR
23
- zt.server = "ns0.validation-test-servers.nominet.org.uk"
24
- zone = zt.transfer("validation-test-servers.nominet.org.uk")
25
- assert(zone.length > 0)
26
- assert(zt.last_tsigstate==nil)
23
+ zt.server = 'nsztm1.digi.ninja'
24
+
25
+ if contactable?(zt.server)
26
+ zone = zt.transfer('zonetransfer.me')
27
+ assert(zone.length > 0)
28
+ assert_nil(zt.last_tsigstate)
29
+ end
27
30
  end
28
31
 
32
+ def contactable?(server)
33
+ begin
34
+ sock = UDPSocket.new
35
+ sock.connect(server, 25)
36
+ sock.close
37
+ true
38
+ rescue Exception
39
+ false
40
+ end
41
+ end
29
42
 
30
43
  # NB - test_ixfr is in tc_tsig.rg - this is becuase it requires
31
44
  # TSIG to make an update (which we can then test for with ixfr)
@@ -70,9 +70,9 @@ class TestGPOS < Minitest::Test
70
70
 
71
71
  def test_creation_approaches
72
72
 
73
- ans_from_data = RR::GPOS.from_data(*EXAMPLE_GPOS_DATA)
74
- ans_from_string = RR::GPOS.from_string(EXAMPLE_GPOS_STRING)
75
- ans_from_hash = RR::GPOS.from_hash(EXAMPLE_GPOS_HASH)
73
+ ans_from_data = RR::GPOS.new_from_data(*EXAMPLE_GPOS_DATA)
74
+ ans_from_string = RR::GPOS.new_from_string(EXAMPLE_GPOS_STRING)
75
+ ans_from_hash = RR::GPOS.new_from_hash(EXAMPLE_GPOS_HASH)
76
76
 
77
77
  fails_to_populate_rdata = []
78
78
  fails_to_populate_rdata << 'data' if ans_from_data.rdata.nil?
@@ -27,7 +27,7 @@ class TestMessage < Minitest::Test
27
27
  # ;; Security Level : UNCHECKED
28
28
  # ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7195
29
29
  # ;; flags: ; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
30
- def sample_message
30
+ def sample_message
31
31
  Message.new('cnn.com', 'A')
32
32
  end
33
33
 
@@ -84,4 +84,10 @@ class TestMessage < Minitest::Test
84
84
  test.(msg_a, nil, false)
85
85
  # TODO: Add more tests.
86
86
  end
87
+
88
+ def test_equals
89
+ response_as_string = "\x10\a\x81\x90\x00\x01\x00\x04\x00\x00\x00\x06\x03cnn\x03com\x00\x00\x02\x00\x01\xC0\f\x00\x02\x00\x01\x00\x01QC\x00\x14\x03ns3\ntimewarner\x03net\x00\xC0\f\x00\x02\x00\x01\x00\x01QC\x00\x11\x03ns2\x03p42\x06dynect\xC04\xC0\f\x00\x02\x00\x01\x00\x01QC\x00\x06\x03ns1\xC0)\xC0\f\x00\x02\x00\x01\x00\x01QC\x00\x06\x03ns1\xC0I\xC0%\x00\x01\x00\x01\x00\x001\xA2\x00\x04\xC7\aD\xEE\xC0E\x00\x01\x00\x01\x00\x00\xB1\x0E\x00\x04\xCC\r\xFA*\xC0b\x00\x01\x00\x01\x00\x009`\x00\x04\xCCJl\xEE\xC0t\x00\x01\x00\x01\x00\x00\xBDg\x00\x04\xD0NF*\xC0t\x00\x1C\x00\x01\x00\x00\x00\xBB\x00\x10 \x01\x05\x00\x00\x90\x00\x01\x00\x00\x00\x00\x00\x00\x00B\x00\x00)\x0F\xA0\x00\x00\x80\x00\x00\x00".force_encoding("ASCII-8BIT")
90
+ message = Message.decode(response_as_string)
91
+ assert(message == message, message.to_s)
92
+ end
87
93
  end
@@ -0,0 +1,192 @@
1
+ require_relative 'spec_helper'
2
+
3
+ require_relative '../lib/dnsruby/resource/NXT'
4
+ require_relative '../lib/dnsruby/code_mappers'
5
+
6
+ include Dnsruby
7
+
8
+ # Tests NXT resource record. See bottom of file for sample zone file.
9
+ class TestNXT < Minitest::Test
10
+
11
+ # Get this by running the following script:
12
+ # require 'dnsruby'
13
+ # include Dnsruby
14
+ # query = Message.new('a.dnsruby.com', 'NXT')
15
+ # resolver = Resolver.new('127.0.0.1')
16
+ # response, error = resolver.query_raw(query)
17
+ # puts response.encode.inspect # to get a quoted string to be inserted in source code
18
+
19
+
20
+ EXAMPLE_NXT_RESPONSE_AS_BINARY = \
21
+ "\xC2\xE0\x84\x80\x00\x01\x00\x01\x00\x01" +
22
+ "\x00\x01\x01a\adnsruby\x03com\x00" +
23
+ "\x00\x1E\x00\x01\xC0\f\x00\x1E\x00\x01\x00\x00*0\x00\x13\x01b\adnsruby\x03com\x00" +
24
+ "@\x00\x00\n\xC0\x0E\x00\x02\x00\x01\x00\x00*0\x00\x06\x03ns1\xC0\x0E\xC0J\x00\x01\x00" +
25
+ "\x01\x00\x00*0\x00\x04\x7F\x00\x00\x01"
26
+
27
+ def test_type_val_to_string
28
+ assert_equal 'SOA', RR::NXT::NxtTypes.code_to_name(6)
29
+ assert_equal 'AXFR', RR::NXT::NxtTypes.code_to_name(252)
30
+ assert_equal 'TYPE9999', RR::NXT::NxtTypes.code_to_name(9999)
31
+ end
32
+
33
+ def test_type_name_to_code
34
+ assert_equal 6, RR::NXT::NxtTypes.name_to_code('SOA')
35
+ assert_equal 252, RR::NXT::NxtTypes.name_to_code('AXFR')
36
+ assert_equal 9999, RR::NXT::NxtTypes.name_to_code('TYPE9999')
37
+ end
38
+
39
+ def test_type_names_to_codes
40
+ strings = %w(TYPE9999 SOA AXFR)
41
+ assert_equal [9999, 6, 252], RR::NXT::NxtTypes.names_to_codes(strings)
42
+ end
43
+
44
+ def test_type_name_to_codes
45
+ assert_equal [9999, 6, 252], RR::NXT::NxtTypes.names_string_to_codes("TYPE9999 SOA AXFR")
46
+ end
47
+
48
+ def test_codes_to_names
49
+ assert_equal %w(TYPE9999 SOA AXFR), RR::NXT::NxtTypes.codes_to_names([9999, 6, 252])
50
+ end
51
+
52
+ def test_codes_to_string
53
+ assert_equal 'SOA AXFR TYPE9999', RR::NXT::NxtTypes.codes_to_string([6, 252, 9999])
54
+ end
55
+
56
+ def test_codes_to_name_sorts_by_code
57
+ assert_equal 'SOA AXFR TYPE9999', RR::NXT::NxtTypes.codes_to_string([9999, 6, 252])
58
+ end
59
+
60
+ def test_binary_string_to_codes
61
+ test_type_codes_as_code_array = [1, 6, 28, 100]
62
+ test_type_codes_as_name_array = %w(A SOA AAAA UINFO)
63
+ test_type_codes_as_number = 1267650600228229401496971640898 # (2 ** 1) + (2 ** 6) + (2 ** 28) + (2 ** 100)
64
+ test_type_codes_as_binary_string = "\x10\x0\x0\x0\x0\x0\x0\x0\x0\x10\x0\x0\x42"
65
+ assert_equal(test_type_codes_as_code_array, RR::NXT::NxtTypes.binary_string_to_codes(test_type_codes_as_binary_string))
66
+ assert_equal(test_type_codes_as_name_array, RR::NXT::NxtTypes.binary_string_to_names(test_type_codes_as_binary_string))
67
+ assert_equal(test_type_codes_as_binary_string, RR::NXT::NxtTypes.codes_to_binary_string(test_type_codes_as_code_array))
68
+ end
69
+
70
+ def test_that_codes_are_in_range_1_to_127
71
+ TestUtils.assert_not_raised(ArgumentError) { RR::NXT::NxtTypes.codes_to_binary_string([1]) }
72
+ TestUtils.assert_not_raised(ArgumentError) { RR::NXT::NxtTypes.codes_to_binary_string([127]) }
73
+ assert_raises(ArgumentError) { RR::NXT::NxtTypes.codes_to_binary_string([0]) }
74
+ assert_raises(ArgumentError) { RR::NXT::NxtTypes.codes_to_binary_string([128]) }
75
+ end
76
+
77
+ def test_that_zero_bit_set_raises_error
78
+ assert_raises(ArgumentError) { RR::NXT::NxtTypes.codes_to_binary_string([]) }
79
+ end
80
+
81
+ def test_A_AAAA_NXT
82
+ assert_equal([1, 28, 30], RR::NXT::NxtTypes.names_string_to_codes('A AAAA NXT'))
83
+ assert_equal("P\x00\x00\x02", RR::NXT::NxtTypes.codes_to_binary_string([1, 28, 30]))
84
+ end
85
+
86
+ def test_type_bitmap_ctor_is_private
87
+ assert_raises(NoMethodError) { RR::NXT::TypeBitmap.new('') }
88
+ end
89
+
90
+ def test_type_bitmap_to_s
91
+ type_bitmap = RR::NXT::TypeBitmap.from_type_codes([1, 16, 30])
92
+ assert_equal('A TXT NXT', type_bitmap.to_s)
93
+ end
94
+
95
+ def test_parse_response_correctly
96
+ response = Message.decode(EXAMPLE_NXT_RESPONSE_AS_BINARY)
97
+ answer = response.answer
98
+ nxt_record = answer[0]
99
+
100
+ # Note: Although the NXT class is defined as Dnsruby::RR::NXT and not
101
+ # Dnsruby::RR::IN::NXT, the IN module (in IN.rb) creates new classes
102
+ # in the IN module for all class-insensitive resource record classes.
103
+ # When the binary record is parsed, it is a Dnsruby::RR::IN::NXT
104
+ # that is created.
105
+ assert_equal(Dnsruby::RR::IN::NXT, nxt_record.class)
106
+ actual_tokens = nxt_record.to_s.split
107
+ expected_tokens = 'a.dnsruby.com. 10800 IN NXT b.dnsruby.com A AAAA NXT'.split
108
+ assert_equal(actual_tokens, expected_tokens)
109
+ end
110
+
111
+ def assert_rr_content(rr)
112
+ assert_equal(rr.type, 'NXT') # TODO: Should this be a string or a number?
113
+ assert_equal(rr.name, Name.create('b.dnsruby.com.'))
114
+ assert_equal(rr.ttl, 10800)
115
+ assert_equal(rr.klass, 'IN')
116
+ assert_equal(rr.next_domain, Name.create('a.dnsruby.com.'))
117
+ end
118
+
119
+ def test_new_from_string
120
+ rr = RR::NXT.new_from_string('b.dnsruby.com. 10800 IN NXT a.dnsruby.com. SOA NXT')
121
+ assert_rr_content(rr)
122
+ end
123
+
124
+ def test_new_from_hash
125
+ assert_rr_content(sample_nxt_rr)
126
+ end
127
+
128
+ def test_new_from_data
129
+ rdata = RR::NXT.build_rdata('a.dnsruby.com.', [Types::SOA, Types::NXT])
130
+
131
+ rr = RR::NXT.new_from_data('b.dnsruby.com.', Types::NXT, Classes::IN, 10800,
132
+ rdata.size, rdata, 0)
133
+ assert_rr_content(rr)
134
+ end
135
+
136
+ def test_owner_alias
137
+ rr = sample_nxt_rr
138
+ assert_equal('b.dnsruby.com', rr.owner.to_s)
139
+ assert_equal('b.dnsruby.com', rr.name.to_s)
140
+ new_name = Name.create('z.com')
141
+ rr.owner = new_name
142
+ assert_equal(new_name, rr.owner)
143
+ assert_equal(new_name, rr.name)
144
+ end
145
+
146
+
147
+ def test_encode_decode_message
148
+ nxt_rr = sample_nxt_rr
149
+ message = Message.new
150
+ message.add_answer(nxt_rr)
151
+ binary_message = message.encode
152
+ reconstructed_message = Message.decode(binary_message)
153
+ reconstructed_nxt_rr = reconstructed_message.answer[0]
154
+ assert_equal(nxt_rr, reconstructed_nxt_rr)
155
+ end
156
+
157
+ def sample_nxt_rr
158
+ RR::NXT.new_from_hash(
159
+ name: 'b.dnsruby.com.',
160
+ ttl: 10800,
161
+ klass: Classes::IN,
162
+ next_domain: 'a.dnsruby.com.',
163
+ types: [Types::SOA, Types::NXT])
164
+ end
165
+ end
166
+
167
+
168
+
169
+ # Sample zone file for setting up BIND to serve a NXT record:
170
+ =begin
171
+ $TTL 3h
172
+
173
+ @ IN SOA dnsruby.com. foo.dnsruby.com. (
174
+ 1 ; serial
175
+ 3H ; refresh after 3 hours
176
+ 1H ; retry after 1 hour
177
+ 1W ; expire after 1 week
178
+ 1H) ; negative caching TTL of 1 hour
179
+
180
+ dnsruby.com. IN NS ns1
181
+
182
+ ; Addresses for canonical names
183
+
184
+ ns1.dnsruby.com. IN A 127.0.0.1
185
+
186
+ a.dnsruby.com. IN A 2.4.6.8
187
+ IN NXT b A AAAA NXT
188
+
189
+ b.dnsruby.com. IN A 2.4.6.9
190
+ IN GPOS 40 50 60
191
+
192
+ =end
@@ -23,7 +23,8 @@ class TestRecur < Minitest::Test
23
23
  # Dnsruby::TheLog.level = Logger::DEBUG
24
24
  ret = r.query("uk", Dnsruby::Types.DNSKEY)
25
25
  # print ret
26
- assert(ret && ret.answer.length > 0)
26
+ assert ret, "Query result was nil."
27
+ assert ret.answer.length > 0, "Answer length should > 0, but was #{ret.answer.length}."
27
28
  # ret = r.query_dorecursion("aaa.bigzone.uk-dnssec.nic.uk", Dnsruby::Types.DNSKEY)
28
29
  # ret = r.query_dorecursion("uk-dnssec.nic.uk", Dnsruby::Types.DNSKEY)
29
30
  end
@@ -0,0 +1,73 @@
1
+ # --
2
+ # Copyright 2007 Nominet UK
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+
17
+ require_relative 'spec_helper'
18
+ require_relative '../lib/dnsruby/resolv'
19
+
20
+ include Dnsruby
21
+ class TestResolv < Minitest::Test
22
+
23
+ RELATIVE_NAME = 'google-public-dns-a.google.com'
24
+ ABSOLUTE_NAME = RELATIVE_NAME + '.'
25
+ IPV4_ADDR = '8.8.8.8'
26
+ IPV6_ADDR = '2001:4860:4860::8888'
27
+ ADDRESSES = [IPV4_ADDR, IPV6_ADDR]
28
+
29
+
30
+ def test_resolv_name_to_addresses
31
+
32
+ assert_equal(IPV4_ADDR, Dnsruby::Resolv.getaddress(ABSOLUTE_NAME).to_s)
33
+
34
+ addresses = Dnsruby::Resolv.getaddresses(ABSOLUTE_NAME)
35
+
36
+ case addresses.length
37
+ when 1
38
+ assert_equal IPV4_ADDR, addresses.first.to_s
39
+ Dnsruby::Resolv.each_address(ABSOLUTE_NAME) do |address|
40
+ assert_equal IPV4_ADDR, address.to_s
41
+ end
42
+ when 2
43
+ assert_equal ADDRESSES.sort, addresses.map(&:to_s).sort
44
+ addresses_from_each = []
45
+ Dnsruby::Resolv.each_address(ABSOLUTE_NAME) do |address|
46
+ addresses_from_each << address.to_s
47
+ end
48
+ assert_equal ADDRESSES.sort, addresses_from_each.sort
49
+ else
50
+ raise "Addresses length must be 1 or 2 but was #{addresses.length}"
51
+ end
52
+ end
53
+
54
+
55
+ def test_resolv_address_to_name
56
+
57
+ assert_equal(RELATIVE_NAME, Dnsruby::Resolv.getname(IPV4_ADDR).to_s)
58
+
59
+ assert_raises(Dnsruby::Resolv::ResolvError) do
60
+ Dnsruby::Resolv.getname(RELATIVE_NAME)
61
+ end
62
+
63
+ names = Dnsruby::Resolv.getnames(IPV4_ADDR)
64
+ assert_equal(1, names.size)
65
+ assert_equal(RELATIVE_NAME, names.first.to_s)
66
+ Dnsruby::Resolv.each_name(IPV4_ADDR) { |name| assert_equal(RELATIVE_NAME, name.to_s)}
67
+ end
68
+
69
+ def test_resolv_address_to_address
70
+ local = '127.0.0.1'
71
+ assert_equal(local, Dnsruby::Resolv.new.getaddress(local))
72
+ end
73
+ end
@@ -1,12 +1,12 @@
1
1
  # --
2
2
  # Copyright 2007 Nominet UK
3
- #
3
+ #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
- #
7
+ #
8
8
  # http://www.apache.org/licenses/LICENSE-2.0
9
- #
9
+ #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
12
12
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either tmexpress or implied.
@@ -157,7 +157,7 @@ class TestResolver < Minitest::Test
157
157
  # assert(m == nil)
158
158
  # assert(err.kind_of?(OtherResolvError) || err.kind_of?(IOError), "OtherResolvError or IOError expected : got #{err.class}")
159
159
  # end
160
- #
160
+ #
161
161
  def test_nxdomain
162
162
  resolver = Resolver.new
163
163
  q = Queue.new
@@ -291,6 +291,10 @@ end
291
291
  # Tests to see that query_raw handles send_plain_message's return values correctly.
292
292
  class TestRawQuery < Minitest::Test
293
293
 
294
+ KEY_NAME = 'key-name'
295
+ KEY = '0123456789'
296
+ ALGO = 'hmac-md5'
297
+
294
298
  class CustomError < RuntimeError; end
295
299
 
296
300
  # Returns a new resolver whose send_plain_message method always returns
@@ -357,5 +361,19 @@ class TestRawQuery < Minitest::Test
357
361
  assert_nil error
358
362
  assert_equal :response_from_send_plain_message, response
359
363
  end
364
+
365
+ def test_2_args_init
366
+ options = Resolver.create_tsig_options(KEY_NAME, KEY)
367
+ assert_equal KEY_NAME, options[:name]
368
+ assert_equal KEY, options[:key]
369
+ assert_nil options[:algorithm]
370
+ end
371
+
372
+ def test_3_args_init
373
+ options = Resolver.create_tsig_options(KEY_NAME,KEY,ALGO)
374
+ assert_equal KEY_NAME, options[:name]
375
+ assert_equal KEY, options[:key]
376
+ assert_equal ALGO, options[:algorithm]
377
+ end
360
378
  end
361
379