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_naptr.rb CHANGED
@@ -1,26 +1,23 @@
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
20
- require 'test/unit'
21
- require 'dnsruby'
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 TestNAPTR < Test::Unit::TestCase
20
+ class TestNAPTR < Minitest::Test
24
21
  def test_naptr
25
22
  txt = "example.com. IN NAPTR 100 50 \"s\" \"z3950+I2L+I2C\" \"\" _z3950._tcp.gatech.edu."
26
23
  naptr = RR.create(txt)
data/test/tc_nsec.rb CHANGED
@@ -1,24 +1,24 @@
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
- #++
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'
16
18
 
17
- require 'test/unit'
18
- require 'dnsruby'
19
19
  include Dnsruby
20
20
 
21
- class NsecTest < Test::Unit::TestCase
21
+ class NsecTest < Minitest::Test
22
22
  INPUT = "alfa.example.com. 86400 IN NSEC host.example.com. ( " +
23
23
  "A MX RRSIG NSEC TYPE1234 )"
24
24
  include Dnsruby
@@ -26,7 +26,7 @@ class NsecTest < Test::Unit::TestCase
26
26
  nsec = Dnsruby::RR.create(INPUT)
27
27
  assert_equal("host.example.com", nsec.next_domain.to_s)
28
28
  assert_equal([Types.A, Types.MX, Types.RRSIG, Types.NSEC, Types.TYPE1234], nsec.types)
29
-
29
+
30
30
  nsec2 = Dnsruby::RR.create(nsec.to_s)
31
31
  assert(nsec2.to_s == nsec.to_s)
32
32
 
@@ -45,10 +45,10 @@ class NsecTest < Test::Unit::TestCase
45
45
  nsec3 = m2.additional()[0]
46
46
  assert_equal(nsec.to_s, nsec3.to_s)
47
47
  end
48
-
48
+
49
49
  def test_nsec_types
50
- # Test types in last section to 65536.
51
- #Test no zeros
50
+ # Test types in last section to 65536.
51
+ # Test no zeros
52
52
  nsec = Dnsruby::RR.create(INPUT)
53
53
  nsec.add_type(Types.TYPE65534)
54
54
  assert(nsec.types.include?(Types.TYPE65534))
@@ -56,9 +56,9 @@ class NsecTest < Test::Unit::TestCase
56
56
  end
57
57
 
58
58
  def test_examples_from_rfc_4035_name_error
59
- # Grab the example responses from RFC4035 and make sure that they pass.
60
- # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
61
- # and make sure that they fail verification for that reason
59
+ # Grab the example responses from RFC4035 and make sure that they pass.
60
+ # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
61
+ # and make sure that they fail verification for that reason
62
62
  m = Message.new
63
63
  m.header.rcode = 3
64
64
  m.add_question(Question.new("m1.example."))
@@ -93,11 +93,11 @@ class NsecTest < Test::Unit::TestCase
93
93
  rescue VerifyError
94
94
  end
95
95
  end
96
-
96
+
97
97
  def test_examples_from_rfc_4035_no_data
98
- # Grab the example responses from RFC4035 and make sure that they pass.
99
- # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
100
- # and make sure that they fail verification for that reason
98
+ # Grab the example responses from RFC4035 and make sure that they pass.
99
+ # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
100
+ # and make sure that they fail verification for that reason
101
101
  m = Message.new
102
102
  m.header.rcode = 0
103
103
  m.add_question(Question.new("ns1.example.", Types.MX))
@@ -127,11 +127,11 @@ class NsecTest < Test::Unit::TestCase
127
127
  end
128
128
 
129
129
  def test_examples_from_rfc_4035_wildcard_expansion
130
- # Grab the example responses from RFC4035 and make sure that they pass.
131
- # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
132
- # and make sure that they fail verification for that reason
130
+ # Grab the example responses from RFC4035 and make sure that they pass.
131
+ # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
132
+ # and make sure that they fail verification for that reason
133
133
  m = Message.new
134
- m.header.rcode =
134
+ m.header.rcode =
135
135
  m.add_question(Question.new("a.z.w.example.", Types.MX))
136
136
  m.add_answer(RR.create("a.z.w.example. 3600 IN MX 1 ai.example."))
137
137
  m.add_answer(RR.create("a.z.w.example. 3600 RRSIG MX 5 4 3600 20040509183619 (
@@ -172,9 +172,9 @@ class NsecTest < Test::Unit::TestCase
172
172
  end
173
173
 
174
174
  def test_examples_from_rfc_4035_wildcard_no_data
175
- # Grab the example responses from RFC4035 and make sure that they pass.
176
- # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
177
- # and make sure that they fail verification for that reason
175
+ # Grab the example responses from RFC4035 and make sure that they pass.
176
+ # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
177
+ # and make sure that they fail verification for that reason
178
178
  m = Message.new
179
179
  m.header.rcode = 0
180
180
  m.add_question(Question.new("a.z.w.example.", Types.AAAA))
@@ -194,7 +194,7 @@ class NsecTest < Test::Unit::TestCase
194
194
  end
195
195
  m.authority.delete(RR.create("*.w.example. 3600 NSEC x.y.example. MX RRSIG NSEC"))
196
196
  m.add_authority(RR.create("*.w.example. 3600 NSEC x.w.example. MX RRSIG NSEC"))
197
- # Test bad versions of wildcard no data
197
+ # Test bad versions of wildcard no data
198
198
  Dnssec.anchor_verifier.verify_nsecs(m)
199
199
  m.authority.delete(RR.create("x.y.w.example. 3600 NSEC xx.example. MX RRSIG NSEC"))
200
200
  begin
@@ -204,23 +204,23 @@ class NsecTest < Test::Unit::TestCase
204
204
  end
205
205
  end
206
206
 
207
- # @TODO@ Test referrals
208
- # def test_examples_from_rfc_4035_referral_signed
209
- # # Grab the example responses from RFC4035 and make sure that they pass.
210
- # # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
211
- # # and make sure that they fail verification for that reason
212
- # m = Message.new
213
- # m.header.rcode = 3
214
- # fail
215
- # end
216
- #
217
- # def test_examples_from_rfc_4035_referral_unsigned
218
- # # Grab the example responses from RFC4035 and make sure that they pass.
219
- # # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
220
- # # and make sure that they fail verification for that reason
221
- # m = Message.new
222
- # m.header.rcode = 3
223
- # fail
224
- # end
225
- #
207
+ # @TODO@ Test referrals
208
+ # def test_examples_from_rfc_4035_referral_signed
209
+ # # Grab the example responses from RFC4035 and make sure that they pass.
210
+ # # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
211
+ # # and make sure that they fail verification for that reason
212
+ # m = Message.new
213
+ # m.header.rcode = 3
214
+ # fail
215
+ # end
216
+ #
217
+ # def test_examples_from_rfc_4035_referral_unsigned
218
+ # # Grab the example responses from RFC4035 and make sure that they pass.
219
+ # # Then, try changing some of the NSEC values (ignoring the RRSIGs for now)
220
+ # # and make sure that they fail verification for that reason
221
+ # m = Message.new
222
+ # m.header.rcode = 3
223
+ # fail
224
+ # end
225
+ #
226
226
  end
data/test/tc_nsec3.rb CHANGED
@@ -1,24 +1,23 @@
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
- #++
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
16
 
17
- require 'test/unit'
18
- require 'dnsruby'
17
+ require_relative 'spec_helper'
19
18
 
20
- class Nsec3Test < Test::Unit::TestCase
21
- INPUT = "2t7b4g4vsa5smi47k61mv5bv1a22bojr.example. 3600 IN NSEC3 1 1 12 aabbccdd ( " +
19
+ class Nsec3Test < Minitest::Test
20
+ INPUT = "2t7b4g4vsa5smi47k61mv5bv1a22bojr.example. 3600 IN NSEC3 1 1 12 aabbccdd ( " +
22
21
  "2vptu5timamqttgl4luu9kg21e0aor3s A RRSIG )"
23
22
  INPUT2 = "2t7b4g4vsa5smi47k61mv5bv1a22bojr.example. 3600 IN NSEC3 1 1 12 aabbccdd " +
24
23
  "2vptu5timamqttgl4luu9kg21e0aor3s"
@@ -31,7 +30,7 @@ class Nsec3Test < Test::Unit::TestCase
31
30
  assert_equal(12, nsec.iterations)
32
31
  assert_equal("aabbccdd", nsec.salt)
33
32
  assert_equal(Dnsruby::Nsec3HashAlgorithms.SHA_1, nsec.hash_alg)
34
-
33
+
35
34
  nsec2 = Dnsruby::RR.create(nsec.to_s)
36
35
  assert(nsec2.to_s == nsec.to_s)
37
36
 
@@ -90,7 +89,7 @@ class Nsec3Test < Test::Unit::TestCase
90
89
  c = Dnsruby::RR::NSEC3.calculate_hash(name, 12, Dnsruby::RR::NSEC3.decode_salt("aabbccdd"), 1)
91
90
  assert_equal(c, hash, "Expected #{hash} but got #{c} for #{name}")
92
91
  }
93
- #
92
+ #
94
93
  end
95
94
 
96
95
  def test_nsec_other_stuff
@@ -105,7 +104,7 @@ class Nsec3Test < Test::Unit::TestCase
105
104
  # fail
106
105
  # rescue DecodeError
107
106
  # end
108
- # Be liberal in what you accept...
107
+ # Be liberal in what you accept...
109
108
  # begin
110
109
  # nsec.hash_alg = 8
111
110
  # fail
@@ -117,10 +116,10 @@ class Nsec3Test < Test::Unit::TestCase
117
116
  rescue DecodeError
118
117
  end
119
118
  end
120
-
119
+
121
120
  def test_nsec_types
122
- # Test types in last section to 65536.
123
- #Test no zeros
121
+ # Test types in last section to 65536.
122
+ # Test no zeros
124
123
  nsec = Dnsruby::RR.create(INPUT)
125
124
  nsec.add_type(Types.TYPE65534)
126
125
  assert(nsec.types.include?(Types.TYPE65534))
@@ -1,23 +1,22 @@
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
-
17
- require 'test/unit'
18
- require 'dnsruby'
19
-
20
- class Nsec3ParamTest < Test::Unit::TestCase
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
+
19
+ class Nsec3ParamTest < Minitest::Test
21
20
  INPUT = "example. 3600 IN NSEC3PARAM 1 0 12 aabbccdd"
22
21
 
23
22
  include Dnsruby
@@ -28,7 +27,7 @@ class Nsec3ParamTest < Test::Unit::TestCase
28
27
  assert_equal(0, nsec.flags)
29
28
  assert_equal(12, nsec.iterations)
30
29
  assert_equal("aabbccdd", nsec.salt)
31
-
30
+
32
31
  nsec2 = Dnsruby::RR.create(nsec.to_s)
33
32
  assert(nsec2.to_s == nsec.to_s)
34
33
  end
@@ -50,5 +49,5 @@ class Nsec3ParamTest < Test::Unit::TestCase
50
49
  assert_equal("beef", r.salt)
51
50
  assert_equal(Dnsruby::Nsec3HashAlgorithms.SHA_1, r.hash_alg)
52
51
  end
53
-
52
+
54
53
  end
data/test/tc_packet.rb CHANGED
@@ -1,201 +1,198 @@
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 TestPacket < Test::Unit::TestCase
20
+ class TestPacket < Minitest::Test
24
21
  def test_packet
25
22
  domain = "example.com."
26
23
  type = "MX"
27
24
  klass = "IN"
28
-
25
+
29
26
  packet = Message.new(domain, type, klass)
30
-
27
+
31
28
  assert(packet, 'new() returned something'); #2
32
29
  assert(packet.header, 'header() method works'); #3
33
30
  assert_instance_of(Header,packet.header,'header() returns right thing'); #4
34
-
35
-
31
+
32
+
36
33
  question = packet.question;
37
34
  assert(question && question.length == 1, 'question() returned right number of items'); #5
38
- # assert_instance_of(Net::DNS::Question,question[0], 'question() returned the right thing'); #6
39
-
35
+ # assert_instance_of(Net::DNS::Question,question[0], 'question() returned the right thing'); #6
36
+
40
37
  answer = packet.answer;
41
38
  assert(answer.length == 0, 'answer() works when empty'); #7
42
-
43
-
39
+
40
+
44
41
  authority = packet.authority;
45
42
  assert(authority.length == 0, 'authority() works when empty'); #8
46
-
43
+
47
44
  additional = packet.additional;
48
45
  assert(additional.length == 0, 'additional() works when empty'); #9
49
-
50
- packet.add_answer(RR.create( {
46
+
47
+ packet.add_answer(RR.create( {
51
48
  :name => "a1.example.com.",
52
- :type => Types.A,
49
+ :type => Types.A,
53
50
  :address => "10.0.0.1"}));
54
51
  assert_equal(1, packet.header.ancount, 'First push into answer section worked'); #10
55
-
56
-
52
+
53
+
57
54
  ret = packet.answer.rrset("example.com.", 'NSEC')
58
55
  assert_equal(ret.rrs.length, 0, "#{ret.rrs.length}")
59
56
  ret = packet.answer.rrset("a1.example.com", 'A')
60
57
  assert_equal(ret.rrs.length, 1, "#{ret.rrs.length}")
61
58
  ret = packet.answer.rrsets()
62
59
  assert_equal(ret.length, 1, "#{ret.length}")
63
-
60
+
64
61
  packet.add_answer(RR.create({:name => "a2.example.com.",
65
62
  :type => "A", :address => "10.0.0.2"}));
66
63
  assert_equal(packet.header.ancount, 2, 'Second push into answer section worked'); #11
67
-
64
+
68
65
  packet.add_authority(RR.create({:name => "a3.example.com.",
69
66
  :type => "A",
70
67
  :address => "10.0.0.3"}));
71
68
  assert_equal(1, packet.header.nscount, 'First push into authority section worked'); #12
72
-
73
-
69
+
70
+
74
71
  packet.add_authority(RR.create( {
75
72
  :name => "a4.example.com.",
76
73
  :type => "A",
77
74
  :address => "10.0.0.4"}));
78
75
  assert_equal(2, packet.header.nscount, 'Second push into authority section worked'); #13
79
-
76
+
80
77
  packet.add_additional(RR.create({
81
78
  :name => "a5.example.com.",
82
79
  :type => "A",
83
80
  :address => "10.0.0.5"}));
84
81
  assert_equal(1, packet.header.adcount, 'First push into additional section worked'); #14
85
-
82
+
86
83
  packet.add_additional(RR.create( {
87
84
  :name => "a6.example.com.",
88
85
  :type => Types.A,
89
86
  :address => "10.0.0.6"}));
90
87
  assert_equal(2, packet.header.adcount, 'Second push into additional section worked'); #15
91
-
88
+
92
89
  data = packet.encode;
93
-
90
+
94
91
  packet2 = Message.decode(data);
95
-
92
+
96
93
  assert(packet2, 'new() from data buffer works'); #16
97
94
 
98
95
  assert_equal(packet.to_s, packet2.to_s, 'inspect() works correctly'); #17
99
-
100
-
96
+
97
+
101
98
  string = packet2.to_s
102
99
  6.times do |count|
103
100
  ip = "10.0.0.#{count+1}";
104
101
  assert(string =~ /#{ip}/, "Found #{ip} in packet"); # 18 though 23
105
102
  end
106
-
103
+
107
104
  assert_equal(1, packet2.header.qdcount, 'header question count correct'); #24
108
105
  assert_equal(2, packet2.header.ancount, 'header answer count correct'); #25
109
- assert_equal(2, packet2.header.nscount, 'header authority count correct'); #26
106
+ assert_equal(2, packet2.header.nscount, 'header authority count correct'); #26
110
107
  assert_equal(2, packet2.header.adcount, 'header additional count correct'); #27
111
-
112
-
113
-
114
- # Test using a predefined answer. This is an answer that was generated by a bind server.
115
- #
116
-
117
- # data=["22cc85000001000000010001056461636874036e657400001e0001c00c0006000100000e100025026e730472697065c012046f6c6166c02a7754e1ae0000a8c0000038400005460000001c2000002910000000800000050000000030"].pack("H*");
108
+
109
+
110
+
111
+ # Test using a predefined answer. This is an answer that was generated by a bind server.
112
+ #
113
+
114
+ # data=["22cc85000001000000010001056461636874036e657400001e0001c00c0006000100000e100025026e730472697065c012046f6c6166c02a7754e1ae0000a8c0000038400005460000001c2000002910000000800000050000000030"].pack("H*");
118
115
  uuencodedPacket =%w{
119
- 22 cc 85 00 00 01 00 00 00 01 00 01 05 64 61 63
120
- 68 74 03 6e 65 74 00 00 1e 00 01 c0 0c 00 06 00
121
- 01 00 00 0e 10 00 25 02 6e 73 04 72 69 70 65 c0
122
- 12 04 6f 6c 61 66 c0 2a 77 54 e1 ae 00 00 a8 c0
123
- 00 00 38 40 00 05 46 00 00 00 1c 20 00 00 29 10
116
+ 22 cc 85 00 00 01 00 00 00 01 00 01 05 64 61 63
117
+ 68 74 03 6e 65 74 00 00 1e 00 01 c0 0c 00 06 00
118
+ 01 00 00 0e 10 00 25 02 6e 73 04 72 69 70 65 c0
119
+ 12 04 6f 6c 61 66 c0 2a 77 54 e1 ae 00 00 a8 c0
120
+ 00 00 38 40 00 05 46 00 00 00 1c 20 00 00 29 10
124
121
  00 00 00 80 00 00 05 00 00 00 00 30
125
122
  }
126
-
123
+
127
124
  uuencodedPacket = %w{
128
- ba 91 81 80 00 01
129
- 00 04 00 00 00 01 07 65 78 61 6d 70 6c 65 03 63
130
- 6f 6d 00 00 ff 00 01 c0 0c 00 02 00 01 00 02 9f
131
- f4 00 14 01 61 0c 69 61 6e 61 2d 73 65 72 76 65
132
- 72 73 03 6e 65 74 00 c0 0c 00 02 00 01 00 02 9f
133
- f4 00 04 01 62 c0 2b c0 0c 00 01 00 01 00 02 9f
134
- 7e 00 04 d0 4d bc a6 c0 0c 00 06 00 01 00 02 9f
135
- f4 00 31 04 64 6e 73 31 05 69 63 61 6e 6e 03 6f
136
- 72 67 00 0a 68 6f 73 74 6d 61 73 74 65 72 c0 6e
125
+ ba 91 81 80 00 01
126
+ 00 04 00 00 00 01 07 65 78 61 6d 70 6c 65 03 63
127
+ 6f 6d 00 00 ff 00 01 c0 0c 00 02 00 01 00 02 9f
128
+ f4 00 14 01 61 0c 69 61 6e 61 2d 73 65 72 76 65
129
+ 72 73 03 6e 65 74 00 c0 0c 00 02 00 01 00 02 9f
130
+ f4 00 04 01 62 c0 2b c0 0c 00 01 00 01 00 02 9f
131
+ 7e 00 04 d0 4d bc a6 c0 0c 00 06 00 01 00 02 9f
132
+ f4 00 31 04 64 6e 73 31 05 69 63 61 6e 6e 03 6f
133
+ 72 67 00 0a 68 6f 73 74 6d 61 73 74 65 72 c0 6e
137
134
  77 a1 2d b7 00 00 1c 20 00 00 0e 10 00 12 75 00
138
- 00 01 51 80 00 00 29 05 00 00 00 00 00 00 00
135
+ 00 01 51 80 00 00 29 05 00 00 00 00 00 00 00
139
136
  }
140
137
  uuencodedPacket.map!{|e| e.hex}
141
138
  packetdata = uuencodedPacket.pack('c*')
142
139
 
143
140
  packet3 = Message.decode(packetdata)
144
141
  assert(packet3, 'new data returned something'); #28
145
-
142
+
146
143
  assert_equal(packet3.header.qdcount, 1, 'header question count in syntetic packet correct'); #29
147
144
  assert_equal(packet3.header.ancount, 4, 'header answer count in syntetic packet correct'); #30
148
- assert_equal(packet3.header.nscount, 0, 'header authority count in syntetic packet correct'); #31
145
+ assert_equal(packet3.header.nscount, 0, 'header authority count in syntetic packet correct'); #31
149
146
  assert_equal(packet3.header.adcount, 1, 'header additional in sytnetic packet correct'); #32
150
-
147
+
151
148
  rr=packet3.additional;
152
-
149
+
153
150
  assert_equal(Types.OPT, rr[0].type, "Additional section packet is EDNS0 type"); #33
154
151
  assert_equal(1280, rr[0].klass.code, "EDNS0 packet size correct"); #34
155
-
156
- # In theory its valid to have multiple questions in the question section.
157
- # Not many servers digest it though.
158
-
152
+
153
+ # In theory its valid to have multiple questions in the question section.
154
+ # Not many servers digest it though.
155
+
159
156
  packet.add_question("bla.foo", Types::TXT, Classes.CH)
160
157
  question = packet.question
161
- assert_equal(2, question.length, 'question() returned right number of items poptest:2'); #36
162
- end
163
-
158
+ assert_equal(2, question.length, 'question() returned right number of items poptest:2'); #36
159
+ end
160
+
164
161
  def get_test_packet
165
162
  packet=Message.new("254.9.11.10.in-addr.arpa.","PTR","IN")
166
-
163
+
167
164
  packet.add_answer(RR.create(%q[254.9.11.10.in-addr.arpa. 86400 IN PTR host-84-11-9-254.customer.example.com.]));
168
-
165
+
169
166
  packet.add_authority(RR.create("9.11.10.in-addr.arpa. 86400 IN NS autons1.example.com."));
170
167
  packet.add_authority(RR.create("9.11.10.in-addr.arpa. 86400 IN NS autons2.example.com."));
171
168
  packet.add_authority(RR.create("9.11.10.in-addr.arpa. 86400 IN NS autons3.example.com."));
172
169
  return packet
173
170
  end
174
-
175
-
171
+
172
+
176
173
  def test_push
177
174
  packet = get_test_packet
178
175
  data=packet.encode
179
-
176
+
180
177
  packet2=Message.decode(data)
181
-
178
+
182
179
  assert_equal(packet.to_s,packet2.to_s,"Packet decode and encode"); #39
183
180
  end
184
-
181
+
185
182
  def test_rrset
186
183
  packet = get_test_packet
187
184
  packet.each_section do |section|
188
- # print "#{section.rrsets}\n"
185
+ # print "#{section.rrsets}\n"
189
186
  end
190
187
  packet.section_rrsets.each do |section, rrsets|
191
- # print "section = #{section}, rrsets = #{rrsets.length}\n"
188
+ # print "section = #{section}, rrsets = #{rrsets.length}\n"
192
189
  end
193
190
  assert(packet.authority.rrsets.length == 1)
194
191
  assert(packet.question().length == 1)
195
192
  assert(packet.answer.rrsets.length == 1)
196
193
  assert(packet.additional.rrsets.length == 0)
197
194
  assert(packet.authority.rrsets[0].length == 3)
198
- # assert(packet.additional.rrsets[0].length == 0)
195
+ # assert(packet.additional.rrsets[0].length == 0)
199
196
  assert(packet.answer.rrsets[0].length == 1)
200
197
  end
201
198