dnsruby 1.55 → 1.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +96 -0
  3. data/Rakefile +30 -29
  4. data/demo/axfr.rb +93 -93
  5. data/demo/check_soa.rb +99 -99
  6. data/demo/check_zone.rb +59 -59
  7. data/demo/digdlv.rb +43 -43
  8. data/demo/digroot.rb +34 -34
  9. data/demo/example_recurse.rb +14 -14
  10. data/demo/mresolv.rb +30 -30
  11. data/demo/mx.rb +31 -31
  12. data/demo/rubydig.rb +37 -37
  13. data/demo/to_resolve.txt +3088 -3088
  14. data/demo/trace_dns.rb +46 -46
  15. data/lib/dnsruby.rb +161 -526
  16. data/lib/dnsruby/DNS.rb +305 -0
  17. data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
  18. data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
  19. data/lib/dnsruby/code_mappers.rb +295 -0
  20. data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
  21. data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
  22. data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
  23. data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
  24. data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
  25. data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
  26. data/lib/dnsruby/message/decoder.rb +164 -0
  27. data/lib/dnsruby/message/encoder.rb +75 -0
  28. data/lib/dnsruby/message/header.rb +249 -0
  29. data/lib/dnsruby/message/message.rb +629 -0
  30. data/lib/dnsruby/message/question.rb +86 -0
  31. data/lib/dnsruby/message/section.rb +96 -0
  32. data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
  33. data/lib/dnsruby/packet_sender.rb +661 -0
  34. data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
  35. data/lib/dnsruby/resolv.rb +113 -0
  36. data/lib/dnsruby/resolver.rb +1192 -0
  37. data/lib/dnsruby/resource/A.rb +56 -0
  38. data/lib/dnsruby/resource/AAAA.rb +54 -0
  39. data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
  40. data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
  41. data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
  42. data/lib/dnsruby/resource/DLV.rb +27 -0
  43. data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
  44. data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
  45. data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
  46. data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
  47. data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
  48. data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
  49. data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
  50. data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
  51. data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
  52. data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
  53. data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
  54. data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
  55. data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
  56. data/lib/dnsruby/resource/NSEC.rb +275 -0
  57. data/lib/dnsruby/resource/NSEC3.rb +332 -0
  58. data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
  59. data/lib/dnsruby/resource/OPT.rb +272 -0
  60. data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
  61. data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
  62. data/lib/dnsruby/resource/RR.rb +421 -0
  63. data/lib/dnsruby/resource/RRSIG.rb +275 -0
  64. data/lib/dnsruby/resource/RRSet.rb +190 -0
  65. data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
  66. data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
  67. data/lib/dnsruby/resource/SPF.rb +29 -0
  68. data/lib/dnsruby/resource/SRV.rb +112 -0
  69. data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
  70. data/lib/dnsruby/resource/TKEY.rb +163 -0
  71. data/lib/dnsruby/resource/TSIG.rb +593 -0
  72. data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
  73. data/lib/dnsruby/resource/X25.rb +55 -0
  74. data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
  75. data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
  76. data/lib/dnsruby/resource/resource.rb +25 -0
  77. data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
  78. data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
  79. data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
  80. data/lib/dnsruby/the_log.rb +44 -0
  81. data/lib/dnsruby/update.rb +278 -0
  82. data/lib/dnsruby/validator_thread.rb +124 -0
  83. data/lib/dnsruby/version.rb +3 -0
  84. data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
  85. data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
  86. data/test/spec_helper.rb +16 -0
  87. data/test/tc_axfr.rb +31 -34
  88. data/test/tc_cache.rb +32 -32
  89. data/test/tc_dlv.rb +28 -28
  90. data/test/tc_dns.rb +73 -76
  91. data/test/tc_dnskey.rb +31 -32
  92. data/test/tc_dnsruby.rb +50 -44
  93. data/test/tc_ds.rb +36 -36
  94. data/test/tc_escapedchars.rb +252 -255
  95. data/test/tc_hash.rb +17 -21
  96. data/test/tc_header.rb +48 -57
  97. data/test/tc_hip.rb +19 -22
  98. data/test/tc_ipseckey.rb +18 -21
  99. data/test/tc_keith.rb +300 -0
  100. data/test/tc_message.rb +87 -0
  101. data/test/tc_misc.rb +83 -87
  102. data/test/tc_name.rb +81 -84
  103. data/test/tc_naptr.rb +18 -21
  104. data/test/tc_nsec.rb +55 -55
  105. data/test/tc_nsec3.rb +23 -24
  106. data/test/tc_nsec3param.rb +20 -21
  107. data/test/tc_packet.rb +90 -93
  108. data/test/tc_packet_unique_push.rb +48 -51
  109. data/test/tc_question.rb +30 -33
  110. data/test/tc_queue.rb +16 -17
  111. data/test/tc_recur.rb +16 -17
  112. data/test/tc_res_config.rb +38 -41
  113. data/test/tc_res_env.rb +29 -32
  114. data/test/tc_res_file.rb +26 -29
  115. data/test/tc_res_opt.rb +62 -65
  116. data/test/tc_resolver.rb +287 -242
  117. data/test/tc_rr-opt.rb +70 -63
  118. data/test/tc_rr-txt.rb +68 -71
  119. data/test/tc_rr-unknown.rb +45 -48
  120. data/test/tc_rr.rb +76 -70
  121. data/test/tc_rrset.rb +21 -22
  122. data/test/tc_rrsig.rb +19 -20
  123. data/test/tc_single_resolver.rb +294 -297
  124. data/test/tc_soak.rb +199 -202
  125. data/test/tc_soak_base.rb +29 -34
  126. data/test/tc_sshfp.rb +20 -23
  127. data/test/tc_tcp.rb +32 -35
  128. data/test/tc_tkey.rb +41 -44
  129. data/test/tc_tsig.rb +81 -84
  130. data/test/tc_update.rb +108 -111
  131. data/test/tc_validator.rb +29 -29
  132. data/test/tc_verifier.rb +81 -82
  133. data/test/ts_dnsruby.rb +16 -15
  134. data/test/ts_offline.rb +62 -63
  135. data/test/ts_online.rb +115 -115
  136. metadata +155 -90
  137. data/README +0 -59
  138. data/lib/Dnsruby/DNS.rb +0 -305
  139. data/lib/Dnsruby/PacketSender.rb +0 -656
  140. data/lib/Dnsruby/Resolver.rb +0 -1189
  141. data/lib/Dnsruby/TheLog.rb +0 -44
  142. data/lib/Dnsruby/message.rb +0 -1230
  143. data/lib/Dnsruby/resource/A.rb +0 -56
  144. data/lib/Dnsruby/resource/AAAA.rb +0 -54
  145. data/lib/Dnsruby/resource/DLV.rb +0 -27
  146. data/lib/Dnsruby/resource/NSEC.rb +0 -298
  147. data/lib/Dnsruby/resource/NSEC3.rb +0 -340
  148. data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
  149. data/lib/Dnsruby/resource/OPT.rb +0 -213
  150. data/lib/Dnsruby/resource/RRSIG.rb +0 -275
  151. data/lib/Dnsruby/resource/SPF.rb +0 -29
  152. data/lib/Dnsruby/resource/SRV.rb +0 -112
  153. data/lib/Dnsruby/resource/TKEY.rb +0 -163
  154. data/lib/Dnsruby/resource/TSIG.rb +0 -593
  155. data/lib/Dnsruby/resource/X25.rb +0 -55
  156. data/lib/Dnsruby/resource/resource.rb +0 -678
  157. data/lib/Dnsruby/update.rb +0 -278
  158. data/lib/Dnsruby/validator_thread.rb +0 -124
data/test/tc_hash.rb CHANGED
@@ -1,30 +1,26 @@
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
- #
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
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
- begin
17
- require 'rubygems'
18
- rescue LoadError
19
- end
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'
20
18
 
21
- require 'test/unit'
22
19
  require 'set'
23
- require 'dnsruby'
24
20
 
25
21
  module Dnsruby
26
22
 
27
- class TestHash < Test::Unit::TestCase
23
+ class TestHash < Minitest::Test
28
24
 
29
25
  def test_types_hash
30
26
  object1 = Types.new(Types::NSEC3)
data/test/tc_header.rb CHANGED
@@ -1,53 +1,50 @@
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
- begin
17
- require 'rubygems'
18
- rescue LoadError
19
- end
20
- require 'test/unit'
21
- require 'dnsruby'
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
+
22
19
  include Dnsruby
23
- class TestHeader < Test::Unit::TestCase
20
+ class TestHeader < Minitest::Test
24
21
  def test_header
25
22
  header = Header.new();
26
23
  assert(header, "new() returned something")
27
-
24
+
28
25
  header.id=41
29
26
  assert_equal(header.id, 41, "id() works")
30
-
27
+
31
28
  header.qr=true
32
29
  assert_equal(header.qr, true, "qr() works")
33
-
30
+
34
31
  header.opcode="QUERY"
35
- assert_equal(OpCode.Query, header.opcode,
32
+ assert_equal(OpCode.Query, header.opcode,
36
33
  "opcode() works")
37
34
  header.opcode=OpCode::Query
38
- assert_equal(header.opcode.string, "Query",
35
+ assert_equal(header.opcode.string, "Query",
39
36
  "opcode() works")
40
-
41
-
37
+
38
+
42
39
  header.aa=true
43
40
  assert_equal(header.aa, true, "aa() works")
44
-
41
+
45
42
  header.tc=false
46
43
  assert_equal(header.tc, false, "tc() works")
47
-
44
+
48
45
  header.rd=true
49
46
  assert_equal(header.rd, true, "rd() works")
50
-
47
+
51
48
  header.ad=true
52
49
  assert_equal(header.ad, true, "rd() works")
53
50
 
@@ -56,52 +53,46 @@ class TestHeader < Test::Unit::TestCase
56
53
 
57
54
  header.ra=true
58
55
  assert_equal(header.ra, true, "ra() works")
59
-
56
+
60
57
  header.qr=true
61
58
  assert_equal(header.qr, true, "qr() works")
62
-
59
+
63
60
  header.rcode="NOERROR"
64
61
  assert_equal(header.get_header_rcode, RCode::NOERROR, "rcode() works")
65
62
  header.rcode=RCode.NOERROR
66
63
  assert_equal(header.get_header_rcode.string, "NOERROR", "rcode() works")
67
-
64
+
68
65
  header.qdcount=1
69
66
  header.ancount=2
70
67
  header.nscount=3
71
68
  header.arcount=3
72
-
73
-
74
- # Reenable when support for CD is there
75
- #header.cd=0
76
- #assert_equal(header.cd, 0, "cd() works")
69
+
70
+
71
+ # Reenable when support for CD is there
72
+ # header.cd=0
73
+ # assert_equal(header.cd, 0, "cd() works")
77
74
  data = header.data
78
-
75
+
79
76
  header2 = Header.new_from_data(data);
80
-
77
+
81
78
  assert(header==(header2), 'Headers are the same');
82
-
83
- #
84
- # Is header.inspect remotely sane?
85
- #
86
- assert(header.to_s =~ /opcode = Query/, 'inspect() has opcode correct');
87
- assert(header.to_s =~ /ancount = 2/, 'inspect() has ancount correct');
88
-
79
+
89
80
  header = Header.new;
90
-
91
- #
92
- # Check that the aliases work properly.
93
- #
81
+
82
+ #
83
+ # Check that the aliases work properly.
84
+ #
94
85
  header.zocount=(0);
95
86
  header.prcount=(1);
96
87
  header.upcount=(2);
97
88
  header.adcount=(3);
98
-
89
+
99
90
  assert_equal(header.zocount, 0, 'zocount works');
100
91
  assert_equal(header.prcount, 1, 'prcount works');
101
92
  assert_equal(header.upcount, 2, 'upcount works');
102
93
  assert_equal(header.adcount, 3, 'adcount works');
103
-
104
-
105
-
94
+
95
+
96
+
106
97
  end
107
98
  end
data/test/tc_hip.rb CHANGED
@@ -1,27 +1,24 @@
1
1
 
2
- #--
3
- #Copyright 2007 Nominet UK
4
- #
5
- #Licensed under the Apache License, Version 2.0 (the "License");
6
- #you may not use this file except in compliance with the License.
7
- #You may obtain a copy of the License at
8
- #
2
+ # --
3
+ # Copyright 2007 Nominet UK
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
9
  # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- #Unless required by applicable law or agreed to in writing, software
12
- #distributed under the License is distributed on an "AS IS" BASIS,
13
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- #See the License for the specific language governing permissions and
15
- #limitations under the License.
16
- #++
17
- begin
18
- require 'rubygems'
19
- rescue LoadError
20
- end
21
- require 'test/unit'
22
- require 'dnsruby'
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ # ++
17
+
18
+ require_relative 'spec_helper'
19
+
23
20
  include Dnsruby
24
- class TestHIP < Test::Unit::TestCase
21
+ class TestHIP < Minitest::Test
25
22
  def test_hip
26
23
  [{"www.example.com. IN HIP ( 2 200100107B1A74DF365639CC39F1D578
27
24
  AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D )" =>
@@ -70,4 +67,4 @@ class TestHIP < Test::Unit::TestCase
70
67
  end
71
68
 
72
69
  end
73
-
70
+
data/test/tc_ipseckey.rb CHANGED
@@ -1,27 +1,24 @@
1
1
 
2
- #--
3
- #Copyright 2007 Nominet UK
4
- #
5
- #Licensed under the Apache License, Version 2.0 (the "License");
6
- #you may not use this file except in compliance with the License.
7
- #You may obtain a copy of the License at
8
- #
2
+ # --
3
+ # Copyright 2007 Nominet UK
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
9
  # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- #Unless required by applicable law or agreed to in writing, software
12
- #distributed under the License is distributed on an "AS IS" BASIS,
13
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- #See the License for the specific language governing permissions and
15
- #limitations under the License.
16
- #++
17
- begin
18
- require 'rubygems'
19
- rescue LoadError
20
- end
21
- require 'test/unit'
22
- require 'dnsruby'
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ # ++
17
+
18
+ require_relative 'spec_helper'
19
+
23
20
  include Dnsruby
24
- class TestIPSECKEY < Test::Unit::TestCase
21
+ class TestIPSECKEY < Minitest::Test
25
22
  def test_ipseckey
26
23
  [{"38.1.0.192.in-addr.arpa. 7200 IN IPSECKEY ( 10 3 2
27
24
  mygateway.example.com.
data/test/tc_keith.rb ADDED
@@ -0,0 +1,300 @@
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 tmexpress or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+ require_relative 'spec_helper'
17
+
18
+ require 'socket'
19
+
20
+ include Dnsruby
21
+ # @TODO@ We also need a test server so we can control behaviour of server to test
22
+ # different aspects of retry strategy.
23
+ # Of course, with Ruby's limit of 256 open sockets per process, we'd need to run
24
+ # the server in a different Ruby process.
25
+
26
+ class TestResolver < Minitest::Test
27
+
28
+ include Dnsruby
29
+
30
+ Thread::abort_on_exception = true
31
+
32
+ GOOD_DOMAIN_NAME = 'example.com'
33
+ BAD_DOMAIN_NAME = 'dnsruby-test-of-bad-domain-name.blah'
34
+
35
+ PORT = 42138
36
+ @@port = PORT
37
+
38
+ def setup
39
+ Dnsruby::Config.reset
40
+ end
41
+
42
+ def assert_valid_response(response)
43
+ assert(response.kind_of?(Message), "Expected response to be a message but was a #{response.class}")
44
+ end
45
+
46
+ def assert_nil_response(response)
47
+ assert(response.nil?, "Expected no response but got a #{response.class}:\n#{response}")
48
+ end
49
+
50
+ def assert_error_is_exception(error, error_class = Exception)
51
+ assert(error.is_a?(error_class), "Expected error to be an #{error_class}, but was a #{error.class}:\n#{error}")
52
+ end
53
+
54
+ def assert_nil_error(error)
55
+ assert(error.nil?, "Expected no error but got a #{error.class}:\n#{error}")
56
+ end
57
+
58
+ def test_send_message
59
+ response = Resolver.new.send_message(Message.new("example.com", Types.A))
60
+ assert_valid_response(response)
61
+ end
62
+
63
+ def test_send_message_bang_noerror
64
+ response, error = Resolver.new.send_message!(Message.new(GOOD_DOMAIN_NAME, Types.A))
65
+ assert_nil_error(error)
66
+ assert_valid_response(response)
67
+ end
68
+
69
+ def test_send_message_bang_error
70
+ message = Message.new(BAD_DOMAIN_NAME, Types.A)
71
+ response, error = Resolver.new.send_message!(message)
72
+ assert_nil_response(response)
73
+ assert_error_is_exception(error)
74
+ end
75
+
76
+ def test_send_plain_message
77
+ resolver = Resolver.new
78
+ response, error = resolver.send_plain_message(Message.new("cnn.com"))
79
+ assert_nil_error(error)
80
+ assert_valid_response(response)
81
+
82
+ m = Message.new(BAD_DOMAIN_NAME)
83
+ m.header.rd = true
84
+ response, error = resolver.send_plain_message(m)
85
+ assert_valid_response(response)
86
+ assert_error_is_exception(error, NXDomain)
87
+ end
88
+
89
+ def test_query
90
+ response = Resolver.new.query("example.com")
91
+ assert_valid_response(response)
92
+ end
93
+
94
+ def test_query_bang_noerror
95
+ response, error = Resolver.new.query!(GOOD_DOMAIN_NAME)
96
+ assert_nil_error(error)
97
+ assert_valid_response(response)
98
+ end
99
+
100
+ def test_query_bang_error
101
+ response, error = Resolver.new.query!(BAD_DOMAIN_NAME)
102
+ assert_nil_response(response)
103
+ assert_error_is_exception(error)
104
+ end
105
+
106
+ def test_query_async
107
+ q = Queue.new
108
+ Resolver.new.send_async(Message.new("example.com", Types.A),q,q)
109
+ id, response, error = q.pop
110
+ assert_equal(id, q, "Id wrong!")
111
+ assert_valid_response(response)
112
+ assert_nil_error(error)
113
+ end
114
+
115
+ def test_query_one_duff_server_one_good
116
+ res = Resolver.new({:nameserver => ["8.8.8.8", "8.8.8.7"]})
117
+ res.retry_delay=1
118
+ q = Queue.new
119
+ res.send_async(Message.new("example.com", Types.A),q,q)
120
+ id, response, error = q.pop
121
+ assert_equal(id, q, "Id wrong!")
122
+ assert_valid_response(response)
123
+ assert_nil_error(error)
124
+ end
125
+
126
+ # @TODO@ Implement!! But then, why would anyone want to do this?
127
+ # def test_many_threaded_clients
128
+ # assert(false, "IMPLEMENT!")
129
+ # end
130
+
131
+ def test_reverse_lookup
132
+ m = Message.new("8.8.8.8", Types.PTR)
133
+ r = Resolver.new
134
+ q=Queue.new
135
+ r.send_async(m,q,q)
136
+ id,ret, error=q.pop
137
+ assert(ret.kind_of?(Message))
138
+ no_pointer=true
139
+ ret.each_answer do |answer|
140
+ if (answer.type==Types.PTR)
141
+ no_pointer=false
142
+ assert(answer.domainname.to_s=~/google-public-dns/)
143
+ end
144
+ end
145
+ assert(!no_pointer)
146
+ end
147
+
148
+ # def test_bad_host
149
+ # res = Resolver.new({:nameserver => "localhost"})
150
+ # res.retry_times=1
151
+ # res.retry_delay=0
152
+ # res.query_timeout = 1
153
+ # q = Queue.new
154
+ # res.send_async(Message.new("example.com", Types.A), q, q)
155
+ # id, m, err = q.pop
156
+ # assert(id==q)
157
+ # assert(m == nil)
158
+ # assert(err.kind_of?(OtherResolvError) || err.kind_of?(IOError), "OtherResolvError or IOError expected : got #{err.class}")
159
+ # end
160
+ #
161
+ def test_nxdomain
162
+ resolver = Resolver.new
163
+ q = Queue.new
164
+ resolver .send_async(Message.new(BAD_DOMAIN_NAME, Types.A), q, 1)
165
+ id, m, error = q.pop
166
+ assert(id==1, "Id should have been 1 but was #{id}")
167
+ assert(m.rcode == RCode.NXDOMAIN, "Expected NXDOMAIN but got #{m.rcode} instead.")
168
+ assert_error_is_exception(error, NXDomain)
169
+ end
170
+
171
+ def test_timeouts
172
+ # test timeout behaviour for different retry, retrans, total timeout etc.
173
+ # Problem here is that many sockets will be created for queries which time out.
174
+ # Run a query which will not respond, and check that the timeout works
175
+ if (!RUBY_PLATFORM=~/darwin/)
176
+ start=stop=0
177
+ retry_times = 3
178
+ retry_delay=1
179
+ packet_timeout=2
180
+ # Work out what time should be, then time it to check
181
+ expected = ((2**(retry_times-1))*retry_delay) + packet_timeout
182
+ begin
183
+ res = Resolver.new({:nameserver => "10.0.1.128"})
184
+ # res = Resolver.new({:nameserver => "213.248.199.17"})
185
+ res.packet_timeout=packet_timeout
186
+ res.retry_times=retry_times
187
+ res.retry_delay=retry_delay
188
+ start=Time.now
189
+ m = res.send_message(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A))
190
+ fail
191
+ rescue ResolvTimeout
192
+ stop=Time.now
193
+ time = stop-start
194
+ assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
195
+ end
196
+ end
197
+ end
198
+
199
+ def test_packet_timeout
200
+ res = Resolver.new({:nameserver => []})
201
+ # res = Resolver.new({:nameserver => "10.0.1.128"})
202
+ start=stop=0
203
+ retry_times = retry_delay = packet_timeout= 10
204
+ query_timeout=2
205
+ begin
206
+ res.packet_timeout=packet_timeout
207
+ res.retry_times=retry_times
208
+ res.retry_delay=retry_delay
209
+ res.query_timeout=query_timeout
210
+ # Work out what time should be, then time it to check
211
+ expected = query_timeout
212
+ start=Time.now
213
+ m = res.send_message(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A))
214
+ fail
215
+ rescue ResolvTimeout
216
+ stop=Time.now
217
+ time = stop-start
218
+ assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
219
+ end #
220
+ end
221
+
222
+ def test_queue_packet_timeout
223
+ # if (!RUBY_PLATFORM=~/darwin/)
224
+ res = Resolver.new({:nameserver => "10.0.1.128"})
225
+ # bad = SingleResolver.new("localhost")
226
+ res.add_server("localhost")
227
+ expected = 2
228
+ res.query_timeout=expected
229
+ q = Queue.new
230
+ start = Time.now
231
+ m = res.send_async(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A), q, q)
232
+ id,ret,err = q.pop
233
+ stop = Time.now
234
+ assert(id=q)
235
+ assert(ret==nil)
236
+ assert(err.class == ResolvTimeout, "#{err.class}, #{err}")
237
+ time = stop-start
238
+ assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
239
+ # end
240
+ end
241
+
242
+ def test_illegal_src_port
243
+ # Also test all singleresolver ports ok
244
+ # Try to set src_port to an illegal value - make sure error raised, and port OK
245
+ res = Resolver.new
246
+ res.port = 56789
247
+ tests = [53, 387, 1265, 3210, 48619]
248
+ tests.each do |bad_port|
249
+ begin
250
+ res.src_port = bad_port
251
+ fail("bad port #{bad_port}")
252
+ rescue
253
+ end
254
+ end
255
+ assert(res.single_resolvers[0].src_port = 56789)
256
+ end
257
+
258
+ def test_add_src_port
259
+ # Try setting and adding port ranges, and invalid ports, and 0.
260
+ # Also test all singleresolver ports ok
261
+ res = Resolver.new
262
+ res.src_port = [56789,56790, 56793]
263
+ assert(res.src_port == [56789,56790, 56793])
264
+ res.src_port = 56889..56891
265
+ assert(res.src_port == [56889,56890,56891])
266
+ res.add_src_port(60000..60002)
267
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002])
268
+ res.add_src_port([60004,60005])
269
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005])
270
+ res.add_src_port(60006)
271
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
272
+ # Now test invalid src_ports
273
+ tests = [0, 53, [60007, 53], [60008, 0], 55..100]
274
+ tests.each do |x|
275
+ begin
276
+ res.add_src_port(x)
277
+ fail()
278
+ rescue
279
+ end
280
+ end
281
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
282
+ assert(res.single_resolvers[0].src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
283
+ end
284
+
285
+ def test_eventtype_api
286
+ # @TODO@ TEST THE Resolver::EventType interface!
287
+ end
288
+
289
+ def test_rd_not_overwritten
290
+ message = Message.new(GOOD_DOMAIN_NAME)
291
+ message.header.rd = false
292
+ assert(! message.header.rd)
293
+ resolver = Resolver.new
294
+ raise "Header rd flag was overwritten to true in #{__FILE__}:#{__LINE__}" if message.header.rd
295
+ _response = resolver.send_message(message)
296
+ puts "Header rd: #{message.header.rd}"
297
+ raise "Header rd flag was overwritten to true in #{__FILE__}:#{__LINE__}" if message.header.rd
298
+ assert(! message.header.rd, "Header rd flag was overwritten to true")
299
+ end
300
+ end