dnsruby 1.55 → 1.56.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 (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_dnskey.rb CHANGED
@@ -1,51 +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
- #
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 DnskeyTest < Test::Unit::TestCase
21
- INPUT = "example.com. 86400 IN DNSKEY 256 3 5 ( AQPSKmynfzW4kyBv015MUG2DeIQ3" +
22
- "Cbl+BBZH4b/0PY1kxkmvHjcZc8no" +
19
+ class DnskeyTest < Minitest::Test
20
+ INPUT = "example.com. 86400 IN DNSKEY 256 3 5 ( AQPSKmynfzW4kyBv015MUG2DeIQ3" +
21
+ "Cbl+BBZH4b/0PY1kxkmvHjcZc8no" +
23
22
  "kfzj31GajIQKY+5CptLr3buXA10h" +
24
23
  "WqTkF7H6RfoRqXQeogmMHfpftf6z" +
25
- "Mv1LyBUgia7za6ZEzOJBOztyvhjL" +
24
+ "Mv1LyBUgia7za6ZEzOJBOztyvhjL" +
26
25
  "742iU/TpPSEDhm2SNKLijfUppn1U" +
27
26
  "aNvv4w== )"
28
- BADINPUT = "example.com. 86400 IN DNSKEY 384 3 5 ( AQPSKmynfzW4kyBv015MUG2DeIQ3" +
29
- "Cbl+BBZH4b/0PY1kxkmvHjcZc8no" +
27
+ BADINPUT = "example.com. 86400 IN DNSKEY 384 3 5 ( AQPSKmynfzW4kyBv015MUG2DeIQ3" +
28
+ "Cbl+BBZH4b/0PY1kxkmvHjcZc8no" +
30
29
  "kfzj31GajIQKY+5CptLr3buXA10h" +
31
30
  "WqTkF7H6RfoRqXQeogmMHfpftf6z" +
32
- "Mv1LyBUgia7za6ZEzOJBOztyvhjL" +
31
+ "Mv1LyBUgia7za6ZEzOJBOztyvhjL" +
33
32
  "742iU/TpPSEDhm2SNKLijfUppn1U" +
34
33
  "aNvv4w== )"
35
- # def test_bad_flag
36
- # dnskey = Dnsruby::RR.create(BADINPUT)
37
- # assert_equal(384, dnskey.flags)
38
- # assert(dnskey.bad_flags?)
39
- # end
34
+ # def test_bad_flag
35
+ # dnskey = Dnsruby::RR.create(BADINPUT)
36
+ # assert_equal(384, dnskey.flags)
37
+ # assert(dnskey.bad_flags?)
38
+ # end
40
39
  def test_dnskey_from_string
41
40
  dnskey = Dnsruby::RR.create(INPUT)
42
- # assert(!dnskey.bad_flags?)
41
+ # assert(!dnskey.bad_flags?)
43
42
  assert_equal(3, dnskey.protocol)
44
43
  assert_equal(256, dnskey.flags)
45
44
  assert_equal(Dnsruby::Algorithms::RSASHA1, dnskey.algorithm)
46
45
  assert_equal(Dnsruby::RR::DNSKEY::ZONE_KEY, dnskey.flags & Dnsruby::RR::DNSKEY::ZONE_KEY)
47
46
  assert_equal(0, dnskey.flags & Dnsruby::RR::DNSKEY::SEP_KEY)
48
-
47
+
49
48
  dnskey2 = Dnsruby::RR.create(dnskey.to_s)
50
49
  assert(dnskey2.to_s == dnskey.to_s, "#{dnskey.to_s} not equal to \n#{dnskey2.to_s}")
51
50
  end
@@ -64,7 +63,7 @@ class DnskeyTest < Test::Unit::TestCase
64
63
  dnskey3 = m2.additional()[0]
65
64
  assert_equal(dnskey.to_s, dnskey3.to_s)
66
65
  end
67
-
66
+
68
67
  def test_bad_values
69
68
  dnskey = Dnsruby::RR.create(INPUT)
70
69
  begin
@@ -84,6 +83,6 @@ class DnskeyTest < Test::Unit::TestCase
84
83
  dnskey.flags=1
85
84
  assert_equal(1, dnskey.flags)
86
85
  dnskey.protocol=3
87
-
86
+
88
87
  end
89
88
  end
data/test/tc_dnsruby.rb CHANGED
@@ -1,45 +1,51 @@
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'
22
- include Dnsruby
23
- class TestDnsruby < Test::Unit::TestCase
24
- def test_dnsruby
25
- a = Resolv.getaddress("google-public-dns-a.google.com.")
26
- assert_equal(a.to_s, "8.8.8.8")
27
- a = Resolv.getaddresses("google-public-dns-a.google.com.")
28
- assert(a.length==1)
29
- assert_equal(a[0].to_s, "8.8.8.8")
30
- Resolv.each_address("google-public-dns-a.google.com.") {|address| assert_equal(address, "8.8.8.8")}
31
-
32
- n = Resolv.getname("8.8.8.8")
33
- assert_equal(n, "google-public-dns-a.google.com")
34
- begin
35
- ret = Resolv.getname("google-public-dns-a.google.com.")
36
- assert(false, ret)
37
- rescue Exception => e
38
- assert(e.kind_of?(ResolvError))
39
- end
40
- n = Resolv.getnames("8.8.8.8")
41
- assert(n.length==1)
42
- assert_equal(n[0], "google-public-dns-a.google.com")
43
- Resolv.each_name("8.8.8.8") {|name| assert_equal(name, "google-public-dns-a.google.com")}
44
- end
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
+
19
+ include Dnsruby
20
+ class TestDnsruby < Minitest::Test
21
+ def test_dnsruby
22
+ a = Resolv.getaddress("google-public-dns-a.google.com.")
23
+ assert_equal(a.to_s, "8.8.8.8")
24
+ a = Resolv.getaddresses("google-public-dns-a.google.com.")
25
+ if (a.length == 1)
26
+ assert(a.length==1, a.to_s + " should only have one response. Had " + a.length.to_s)
27
+ assert(a.any? {|s| s.to_s == ("8.8.8.8")})
28
+ Resolv.each_address("google-public-dns-a.google.com.") {|address| assert_equal(address, "8.8.8.8")}
29
+ else
30
+ assert(a.length==2, a.to_s + " should have had two responses. Had " + a.length.to_s)
31
+ assert(a.any? {|s| s.to_s == ("8.8.8.8")})
32
+ assert(a.any? {|s| s.to_s == ("2001:4860:4860::8888")})
33
+ Resolv.each_address("google-public-dns-a.google.com.") {|address|
34
+ assert((address == "8.8.8.8") || (address = "2001:4860:4860::8888")) }
35
+ end
36
+
37
+ n = Resolv.getname("8.8.8.8")
38
+ assert_equal(n, "google-public-dns-a.google.com")
39
+ begin
40
+ ret = Resolv.getname("google-public-dns-a.google.com.")
41
+ assert(false, ret)
42
+ rescue Exception => e
43
+ # assert(e.kind_of?(ResolvError))
44
+ assert(e.kind_of?(Resolv::ResolvError), "Error was a #{e.class}: #{e}")
45
+ end
46
+ n = Resolv.getnames("8.8.8.8")
47
+ assert(n.length==1)
48
+ assert_equal(n[0], "google-public-dns-a.google.com")
49
+ Resolv.each_name("8.8.8.8") {|name| assert_equal(name, "google-public-dns-a.google.com")}
50
+ end
45
51
  end
data/test/tc_ds.rb CHANGED
@@ -1,31 +1,31 @@
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
19
  require 'openssl'
19
20
  require 'digest/sha2'
20
- require 'dnsruby'
21
21
 
22
- class DsTest < Test::Unit::TestCase
23
- DLVINPUT = "dskey.example.com. 86400 IN DLV 60485 5 1 ( 2BB183AF5F22588179A53B0A" +
22
+ class DsTest < Minitest::Test
23
+ DLVINPUT = "dskey.example.com. 86400 IN DLV 60485 5 1 ( 2BB183AF5F22588179A53B0A" +
24
24
  "98631FAD1A292118 )"
25
- INPUT = "dskey.example.com. 86400 IN DS 60485 5 1 ( 2BB183AF5F22588179A53B0A" +
25
+ INPUT = "dskey.example.com. 86400 IN DS 60485 5 1 ( 2BB183AF5F22588179A53B0A" +
26
26
  "98631FAD1A292118 )"
27
27
  DNSKEY = "dskey.example.com. 86400 IN DNSKEY 256 3 5 ( AQOeiiR0GOMYkDshWoSKz9Xz" +
28
- "fwJr1AYtsmx3TGkJaNXVbfi/" +
28
+ "fwJr1AYtsmx3TGkJaNXVbfi/" +
29
29
  "2pHm822aJ5iI9BMzNXxeYCmZ"+
30
30
  "DRD99WYwYqUSdjMmmAphXdvx"+
31
31
  "egXd/M5+X7OrzKBaMbCVdFLU"+
@@ -44,7 +44,7 @@ class DsTest < Test::Unit::TestCase
44
44
  assert_equal(Algorithms.RSASHA1, ds.algorithm)
45
45
  assert_equal(1, ds.digest_type)
46
46
  assert_equal("2BB183AF5F22588179A53B0A98631FAD1A292118", ds.digest)
47
-
47
+
48
48
  ds2 = Dnsruby::RR.create(ds.to_s)
49
49
  assert(ds2.to_s == ds.to_s)
50
50
  end
@@ -58,47 +58,47 @@ class DsTest < Test::Unit::TestCase
58
58
  ds3 = m2.additional()[0]
59
59
  assert_equal(ds.to_s, ds3.to_s)
60
60
  end
61
-
61
+
62
62
  def test_ds_values
63
63
  ds = Dnsruby::RR.create(INPUT)
64
64
  ds.digest_type = 2
65
- # Be liberal in what you accept...
65
+ # Be liberal in what you accept...
66
66
  # begin
67
67
  # ds.digest_type = 3
68
68
  # fail
69
- #
69
+ #
70
70
  # rescue DecodeError
71
71
  # end
72
72
  end
73
-
73
+
74
74
  def test_ds_digest
75
75
  key = Dnsruby::RR.create(DNSKEY)
76
-
77
- # and check it is the same as DS
76
+
77
+ # and check it is the same as DS
78
78
  right_ds = Dnsruby::RR.create(DS1)
79
79
  ds = Dnsruby::RR::DS.from_key(key, 1);
80
- assert_equal(ds.to_s, right_ds.to_s)
80
+ assert_equal(ds.to_s, right_ds.to_s)
81
81
  end
82
-
82
+
83
83
  def test_sha2
84
- # Create a new DS from the DNSKEY,
84
+ # Create a new DS from the DNSKEY,
85
85
  key = Dnsruby::RR.create(DNSKEY)
86
-
87
- # and check it is the same as DS
86
+
87
+ # and check it is the same as DS
88
88
  right_ds = Dnsruby::RR.create(DS2)
89
89
  ds = Dnsruby::RR::DS.from_key(key, 2);
90
90
  assert_equal(ds.to_s, right_ds.to_s)
91
91
  end
92
-
92
+
93
93
  def test_dlv_from_string
94
94
  dlv = Dnsruby::RR.create(DLVINPUT)
95
95
  assert_equal(60485, dlv.key_tag)
96
96
  assert_equal(Algorithms.RSASHA1, dlv.algorithm)
97
97
  assert_equal(1, dlv.digest_type)
98
98
  assert_equal("2BB183AF5F22588179A53B0A98631FAD1A292118", dlv.digest)
99
-
99
+
100
100
  dlv2 = Dnsruby::RR.create(dlv.to_s)
101
- assert(dlv2.to_s == dlv.to_s)
101
+ assert(dlv2.to_s == dlv.to_s)
102
102
  end
103
-
103
+
104
104
  end
@@ -1,163 +1,160 @@
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 TestEscapedChars < Test::Unit::TestCase
20
+ class TestEscapedChars < Minitest::Test
24
21
  def test_one
25
22
  Name::Label.set_max_length(150)
26
- #
27
- # We test al sorts of escaped non-ascii characters.
28
- # This is all to be protocol conform... so to speak.
29
-
30
- #
31
- # The collection of tests is somewhat of a hodgepodge that tried to
32
- # assess sensitivity to combinations of characters that the regular
33
- # expressions and perl itself are sensitive to. (like \\\\\.\..)
34
- # Development versions of the code tried to split a domain name in
35
- # invidual labels by a regular expression. It made no sense to remove
36
- # the more ackward tests as they have to pass anyway ...
37
-
38
-
39
- # Note that in perl the \\ in a presentation format can only be achieved
40
- # through \\\\ .
41
-
42
- # The hex codes are the names in wireformat:
43
- # length octet. content octets, length octet, content , NULL octet
44
-
45
-
46
- # Below are test combos, 1st and 2nd array elements are
47
- # representations of the name. The output of the perl functions should
48
- # yield the 2nd presentation (eg \037 gets presented as % )
49
-
50
- # The 3rd element is a label count.
51
- # The 4th element represents the number of octets per label
52
- # The 5th element is a hexdump of the domain name in wireformat
53
-
23
+ #
24
+ # We test al sorts of escaped non-ascii characters.
25
+ # This is all to be protocol conform... so to speak.
26
+
27
+ #
28
+ # The collection of tests is somewhat of a hodgepodge that tried to
29
+ # assess sensitivity to combinations of characters that the regular
30
+ # expressions and perl itself are sensitive to. (like \\\\\.\..)
31
+ # Development versions of the code tried to split a domain name in
32
+ # invidual labels by a regular expression. It made no sense to remove
33
+ # the more ackward tests as they have to pass anyway ...
34
+
35
+
36
+ # Note that in perl the \\ in a presentation format can only be achieved
37
+ # through \\\\ .
38
+
39
+ # The hex codes are the names in wireformat:
40
+ # length octet. content octets, length octet, content , NULL octet
41
+
42
+
43
+ # Below are test combos, 1st and 2nd array elements are
44
+ # representations of the name. The output of the perl functions should
45
+ # yield the 2nd presentation (eg \037 gets presented as % )
46
+
47
+ # The 3rd element is a label count.
48
+ # The 4th element represents the number of octets per label
49
+ # The 5th element is a hexdump of the domain name in wireformat
50
+
54
51
  testcombos=[
55
52
  ['bla.fo\.o.org',
56
53
  'bla.fo\.o.org',
57
54
  3,
58
55
  [3,4,3],
59
- #Wire: 3 b l a 4 f o . o 3 o r g 0
56
+ # Wire: 3 b l a 4 f o . o 3 o r g 0
60
57
  "03626c6104666f2e6f036f726700"
61
58
  ],
62
-
59
+
63
60
  [
64
- 'bla\255.foo.org',
61
+ 'bla\255.foo.org',
65
62
  'bla\255.foo.org',
66
63
  3,
67
64
  [4,3,3],
68
- #Wire: 4 b l a 0xff 3 f o o 3 o r g 0
69
- "04626c61ff03666f6f036f726700"
65
+ # Wire: 4 b l a 0xff 3 f o o 3 o r g 0
66
+ "04626c61ff03666f6f036f726700"
70
67
  ],
71
-
68
+
72
69
  [
73
- 'bla.f\xa9oo.org',
70
+ 'bla.f\xa9oo.org',
74
71
  'bla.f\169oo.org',
75
72
  3,
76
73
  [3,4,3] ,
77
- #Wire: 3 b l a 4 f 0xa9 o o 3 o r g 0
78
- "03626c610466a96f6f036f726700"
74
+ # Wire: 3 b l a 4 f 0xa9 o o 3 o r g 0
75
+ "03626c610466a96f6f036f726700"
79
76
  ], # Note hex to decimal
80
77
  ['bla.fo\.o.org',
81
78
  'bla.fo\.o.org',
82
79
  3,
83
80
  [3,4,3],
84
- #Wire: 3 b l a 4 f o . o 3 o r g 0
81
+ # Wire: 3 b l a 4 f o . o 3 o r g 0
85
82
  "03626c6104666f2e6f036f726700"
86
83
  ],
87
-
84
+
88
85
  ['bla\0000.foo.org',
89
86
  'bla\0000.foo.org',
90
87
  3,
91
88
  [5,3,3],
92
- #Wire: 5 b l a 0x00 0 3 f o o 3 o r g 0
89
+ # Wire: 5 b l a 0x00 0 3 f o o 3 o r g 0
93
90
  "05626c61003003666f6f036f726700" ,
94
91
  ],
95
-
92
+
96
93
  ["bla.fo\o.org",
97
94
  "bla.foo.org",
98
95
  3,
99
96
  [3,3,3],
100
- #Wire: 3 b l a 3 f o o 3 o r g 0 ignoring backslash on input
97
+ # Wire: 3 b l a 3 f o o 3 o r g 0 ignoring backslash on input
101
98
  "03626c6103666f6f036f726700",
102
99
  ],
103
- #drops the \
100
+ # drops the \
104
101
  ['bla(*.foo.org',
105
102
  'bla\(*.foo.org',
106
103
  3,
107
104
  [5,3,3],
108
-
109
- #Wire: 5 b l a ( * 3 f o o 3 o r g 0
110
- "05626c61282a03666f6f036f726700"
105
+
106
+ # Wire: 5 b l a ( * 3 f o o 3 o r g 0
107
+ "05626c61282a03666f6f036f726700"
111
108
  ],
112
-
109
+
113
110
  [' .bla.foo.org',
114
111
  '\032.bla.foo.org',
115
112
  4,
116
113
  [1,3,3,3],
117
114
  "012003626c6103666f6f036f726700",
118
115
  ],
119
-
116
+
120
117
  ["\\\\a.foo",
121
118
  "\\\\a.foo",
122
119
  2,
123
120
  [2,3],
124
- #Wire: 2 \ a 3 f o o 0
121
+ # Wire: 2 \ a 3 f o o 0
125
122
  "025c6103666f6f00"
126
123
  ],
127
-
128
-
124
+
125
+
129
126
  ['\\\\.foo',
130
127
  '\\\\.foo',
131
128
  2,
132
129
  [1,3],
133
- #Wire: 1 \ 3 f o o 0
130
+ # Wire: 1 \ 3 f o o 0
134
131
  "015c03666f6f00",
135
132
  ],
136
-
133
+
137
134
  ['a\\..foo',
138
135
  'a\\..foo',
139
- 2,
136
+ 2,
140
137
  [2,3],
141
- #Wire: 2 a . 3 f o o 0
138
+ # Wire: 2 a . 3 f o o 0
142
139
  "02612e03666f6f00"
143
140
  ],
144
-
141
+
145
142
  ['a\\.foo.org',
146
143
  'a\\.foo.org',
147
144
  2, [5,3],
148
- #Wire: 5 a . f o o 3 o r g 0
145
+ # Wire: 5 a . f o o 3 o r g 0
149
146
  "05612e666f6f036f726700" ,
150
147
  ],
151
-
148
+
152
149
  ['\..foo.org',
153
150
  '\..foo.org',
154
151
  3,
155
- [1,3,3],
156
-
157
- #Wire: 1 . 3 f o o 3 o r g 0
152
+ [1,3,3],
153
+
154
+ # Wire: 1 . 3 f o o 3 o r g 0
158
155
  "012e03666f6f036f726700" ,
159
156
  ],
160
-
157
+
161
158
  [
162
159
  '\046.\046',
163
160
  '\..\.',
@@ -165,192 +162,192 @@ class TestEscapedChars < Test::Unit::TestCase
165
162
  [1,1],
166
163
  '012e012e00',
167
164
  ],
168
-
169
- [ # all non \w characters :-)
165
+
166
+ [ # all non \w characters :-)
170
167
  '\000\001\002\003\004\005\006\007\008\009\010\011\012\013\014\015\016\017\018\019\020\021\022\023\024\025\026\027\028\029\030\031\032.\033\034\035\036\037\038\039\040\041\042\043\044\045\046\047\048.\058\059\060\061\062\063\064\065.\091\092\093\094\095\096.\123\124\125\126\127\128\129',
171
168
  '\000\001\002\003\004\005\006\007\008\009\010\011\012\013\014\015\016\017\018\019\020\021\022\023\024\025\026\027\028\029\030\031\032.!\"#\$%&\'\(\)*+,-\./0.:\;<=>?\@a.[\\\\]^_`.{|}~\127\128\129',
172
169
  5,
173
170
  [33,16,8,6,7],
174
171
  "21000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20102122232425262728292a2b2c2d2e2f30083a3b3c3d3e3f4061065b5c5d5e5f60077b7c7d7e7f808100",
175
172
  ],
176
-
173
+
177
174
  ]
178
-
179
-
180
- #foreach my $testinput (@testcombos){
175
+
176
+
177
+ # foreach my $testinput (@testcombos){
181
178
  testcombos.each do |testinput|
182
- # test back and forth
183
-
184
- name = Name.create(testinput[0])
179
+ # test back and forth
180
+
181
+ name = Name.create(testinput[0])
185
182
  labels = Name.name2encodedlabels(testinput[0])
186
-
187
- # assert_equal(testinput[1], Net::labels2name(labels), "consistent name2labels labels2name for " + testinput[0])
183
+
184
+ # assert_equal(testinput[1], Net::labels2name(labels), "consistent name2labels labels2name for " + testinput[0])
188
185
  # name_from_labels = Name.encodedlabels2name(labels)
189
186
  name_from_labels = Name.new(labels)
190
- assert_equal(name.to_s, name_from_labels.to_s, "Name->Labels->Name for " + testinput[0])
191
-
192
- # test number of labels
187
+ assert_equal(name.to_s, name_from_labels.to_s, "Name->Labels->Name for " + testinput[0])
188
+
189
+ # test number of labels
193
190
  assert_equal(testinput[2],labels.length(),"consistent labelcount (#{testinput[2]})")
194
- # test number of elements within label.
191
+ # test number of elements within label.
195
192
  i=0
196
- # Test length of each individual label
193
+ # Test length of each individual label
197
194
  while i<testinput[2]
198
- assert_equal(testinput[3][i], labels[i].length,
195
+ assert_equal(testinput[3][i], labels[i].length,
199
196
  "labellength for label #{labels[i]} equals " + testinput[3][i].to_s)
200
197
  i = i + 1
201
198
  end
202
-
203
- # wire=Name._name2wire(testinput[0])
199
+
200
+ # wire=Name._name2wire(testinput[0])
204
201
  wire=MessageEncoder.new {|msg|
205
202
  msg.put_name(name, true)}.to_s
206
-
203
+
207
204
  wireinhex=wire.unpack("H*")[0]
208
205
  assert_equal( testinput[4].to_s, wireinhex.to_s,"Wireinhex for " + testinput[0] )
209
- # And now call DN_EXPAND
210
- # name,offset=Name.dn_expand(wire,0)
211
-
212
-
206
+ # And now call DN_EXPAND
207
+ # name,offset=Name.dn_expand(wire,0)
208
+
209
+
213
210
  MessageDecoder.new(wire) {|msg|
214
211
  name = msg.get_name}
215
-
212
+
216
213
  assert_equal(name.to_s,testinput[1],"DN_EXPAND (pp) consistent")
217
214
  end
218
-
219
- # QUESTION SECTION
220
- #\\.eg.secret-wg.org. IN TXT
221
- #
222
- # ANSWER SECTION:
223
- #\\.eg.secret-wg.org. 10 IN TXT "WildCard Match"
224
- #
225
- # AUTHORITY SECTION:
226
- #eg.secret-wg.org. 600 IN NS ns.eg.secret-wg.org.
227
- #
228
- # ADDITIONAL SECTION:
229
- #ns.eg.secret-wg.org. 600 IN A 10.0.53.208
230
- #
231
-
215
+
216
+ # QUESTION SECTION
217
+ # \\.eg.secret-wg.org. IN TXT
218
+ #
219
+ # ANSWER SECTION:
220
+ # \\.eg.secret-wg.org. 10 IN TXT "WildCard Match"
221
+ #
222
+ # AUTHORITY SECTION:
223
+ # eg.secret-wg.org. 600 IN NS ns.eg.secret-wg.org.
224
+ #
225
+ # ADDITIONAL SECTION:
226
+ # ns.eg.secret-wg.org. 600 IN A 10.0.53.208
227
+ #
228
+
232
229
  uuencodedPacket=%w{
233
- c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 5c 02
234
- 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
235
- 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
236
- 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
237
- c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
238
- 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
239
- d0
230
+ c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 5c 02
231
+ 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
232
+ 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
233
+ 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
234
+ c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
235
+ 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
236
+ d0
240
237
  }
241
-
242
- # uuEncodedPacket =~ s/\s*//g
243
- # uuEncodedPacket =uuEncodedPacket.gsub("\s*", "")
244
- # packetdata = [uuEncodedPacket].pack('H*')
245
-
238
+
239
+ # uuEncodedPacket =~ s/\s*//g
240
+ # uuEncodedPacket =uuEncodedPacket.gsub("\s*", "")
241
+ # packetdata = [uuEncodedPacket].pack('H*')
242
+
246
243
  uuencodedPacket.map!{|e| e.hex}
247
244
  packetdata = uuencodedPacket.pack('c*')
248
245
  packetdata = packetdata.gsub("\s*", "")
249
-
246
+
250
247
  packet = Message.decode(packetdata)
251
248
  assert(packet, "nil packet returned from binary data")
252
249
  assert_equal( (packet.answer)[0].name.to_s,'\\\\\\\\.eg.secret-wg.org',"Correctly dealt escaped backslash from wireformat \\\\.eg.secret-wg.org")
253
250
  end
254
-
251
+
255
252
  def test_esoteric_stuff
256
- # Now testing for the real esotheric stuff.
257
- # domain names can contain NULL and space characters (on the wire)
258
- # these should be properly expanded
259
-
260
- # This only works if the dn_expand_XS() is NOT used.
261
-
262
- # The UUencoded packet contains a captured packet with this content:
263
-
264
- # QUESTION SECTION:
265
- #\000.n\032ll.eg.secret-wg.org. IN TXT
266
-
267
- # ANSWER SECTION:
268
- #\000.n ll.eg.secret-wg.org. 0 IN TXT "NULL byte ownername"
269
- # ^ SPACE !!!
270
- # AUTHORITY SECTION:
271
- #eg.secret-wg.org. 600 IN NS ns.eg.secret-wg.org.
272
-
273
- # ADDITIONAL SECTION:
274
- #ns.eg.secret-wg.org. 600 IN A 10.0.53.208
275
-
253
+ # Now testing for the real esotheric stuff.
254
+ # domain names can contain NULL and space characters (on the wire)
255
+ # these should be properly expanded
256
+
257
+ # This only works if the dn_expand_XS() is NOT used.
258
+
259
+ # The UUencoded packet contains a captured packet with this content:
260
+
261
+ # QUESTION SECTION:
262
+ # \000.n\032ll.eg.secret-wg.org. IN TXT
263
+
264
+ # ANSWER SECTION:
265
+ # \000.n ll.eg.secret-wg.org. 0 IN TXT "NULL byte ownername"
266
+ # ^ SPACE !!!
267
+ # AUTHORITY SECTION:
268
+ # eg.secret-wg.org. 600 IN NS ns.eg.secret-wg.org.
269
+
270
+ # ADDITIONAL SECTION:
271
+ # ns.eg.secret-wg.org. 600 IN A 10.0.53.208
272
+
276
273
  uuencodedPacket =%w{
277
- a6 58 85 00 00 01 00 01 00 01 00 01 01 00 04 6e
278
- 20 6c 6c 02 65 67 09 73 65 63 72 65 74 2d 77 67
279
- 03 6f 72 67 00 00 10 00 01 c0 0c 00 10 00 01 00
280
- 00 00 00 00 14 13 4e 55 4c 4c 20 62 79 74 65 20
281
- 6f 77 6e 65 72 6e 61 6d 65 c0 13 00 02 00 01 00
282
- 00 02 58 00 05 02 6e 73 c0 13 c0 55 00 01 00 01
283
- 00 00 02 58 00 04 0a 00 35 d0
274
+ a6 58 85 00 00 01 00 01 00 01 00 01 01 00 04 6e
275
+ 20 6c 6c 02 65 67 09 73 65 63 72 65 74 2d 77 67
276
+ 03 6f 72 67 00 00 10 00 01 c0 0c 00 10 00 01 00
277
+ 00 00 00 00 14 13 4e 55 4c 4c 20 62 79 74 65 20
278
+ 6f 77 6e 65 72 6e 61 6d 65 c0 13 00 02 00 01 00
279
+ 00 02 58 00 05 02 6e 73 c0 13 c0 55 00 01 00 01
280
+ 00 00 02 58 00 04 0a 00 35 d0
284
281
  }
285
-
282
+
286
283
  uuencodedPacket.map!{|e| e.hex}
287
284
  packetdata = uuencodedPacket.pack('c*')
288
285
  packetdata = packetdata.gsub("\s*", "")
289
286
  packet = Message.decode(packetdata)
290
287
  assert_equal( '\000.n\\032ll.eg.secret-wg.org',(packet.answer)[0].name.to_s,"Correctly dealt with NULL bytes in domain names")
291
-
292
-
293
- #slightly modified \\ .eg.secret-wg.org instead of \\\\.eg.secret-wg.org
294
- # That is escaped backslash space
288
+
289
+
290
+ # slightly modified \\ .eg.secret-wg.org instead of \\\\.eg.secret-wg.org
291
+ # That is escaped backslash space
295
292
  uuencodedPacket=%w{
296
- c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 20 02
297
- 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
298
- 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
299
- 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
300
- c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
301
- 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
302
- d0
293
+ c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 20 02
294
+ 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
295
+ 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
296
+ 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
297
+ c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
298
+ 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
299
+ d0
303
300
  }
304
-
301
+
305
302
  uuencodedPacket.map!{|e| e.hex}
306
303
  packetdata = uuencodedPacket.pack('c*')
307
304
  packetdata.gsub!("\s*", "")
308
305
  packet = Message.decode(packetdata)
309
-
310
-
306
+
307
+
311
308
  assert_equal( '\\\\\\032.eg.secret-wg.org',(packet.answer)[0].name.to_s,"Correctly dealt escaped backslash from wireformat \\e.eg.secret-wg.org")
312
-
313
- #slightly modified \\e.eg.secret-wg.org instead of \\\\.eg.secret-wg.org
309
+
310
+ # slightly modified \\e.eg.secret-wg.org instead of \\\\.eg.secret-wg.org
314
311
  uuencodedPacket=%w{
315
- c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 65 02
316
- 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
317
- 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
318
- 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
319
- c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
320
- 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
321
- d0
312
+ c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 65 02
313
+ 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
314
+ 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
315
+ 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
316
+ c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
317
+ 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
318
+ d0
322
319
  }
323
-
324
- # uuEncodedPacket =~ s/\s*//g
325
- # packetdata = uuEncodedPacket.pack('H*')
326
- # packetdata = packetdata.gsub("\s*", "")
320
+
321
+ # uuEncodedPacket =~ s/\s*//g
322
+ # packetdata = uuEncodedPacket.pack('H*')
323
+ # packetdata = packetdata.gsub("\s*", "")
327
324
  uuencodedPacket.map!{|e| e.hex}
328
325
  packetdata = uuencodedPacket.pack('c*')
329
326
  packet = Message.decode(packetdata)
330
-
331
-
327
+
328
+
332
329
  assert_equal( '\\\\e.eg.secret-wg.org',(packet.answer)[0].name.to_s,"Correctly dealt escaped backslash from wireformat \\e.eg.secret-wg.org")
333
-
334
-
335
- #slightly modified \\\..eg.secret-wg.org instead of \\e.eg.secret-wg.org
330
+
331
+
332
+ # slightly modified \\\..eg.secret-wg.org instead of \\e.eg.secret-wg.org
336
333
  uuencodedPacket=%w{
337
- c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 65 02
338
- 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
339
- 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
340
- 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
341
- c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
342
- 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
343
- d0
334
+ c8 d5 85 00 00 01 00 01 00 01 00 01 02 5c 65 02
335
+ 65 67 09 73 65 63 72 65 74 2d 77 67 03 6f 72 67
336
+ 00 00 10 00 01 c0 0c 00 10 00 01 00 00 00 0a 00
337
+ 0f 0e 57 69 6c 64 43 61 72 64 20 4d 61 74 63 68
338
+ c0 0f 00 02 00 01 00 00 02 58 00 05 02 6e 73 c0
339
+ 0f c0 4c 00 01 00 01 00 00 02 58 00 04 0a 00 35
340
+ d0
344
341
  }
345
-
346
- ## uuEncodedPacket =~ s/\s*//g
347
- # packetdata = uuEncodedPacket.pack('H*')
348
- # packetdata = packetdata.gsub("\s*", "")
342
+
343
+ # # uuEncodedPacket =~ s/\s*//g
344
+ # packetdata = uuEncodedPacket.pack('H*')
345
+ # packetdata = packetdata.gsub("\s*", "")
349
346
  uuencodedPacket.map!{|e| e.hex}
350
347
  packetdata = uuencodedPacket.pack('c*')
351
348
  packet = Message.decode(packetdata)
352
349
  assert_equal( '\\\\e.eg.secret-wg.org',(packet.answer)[0].name.to_s,"Correctly dealt escaped backslash from wireformat \\\..eg.secret-wg.org")
353
-
350
+
354
351
  testrr=RR.create(
355
352
  :name => '\\e.eg.secret-wg.org',
356
353
  :type => 'TXT',
@@ -358,27 +355,27 @@ d0
358
355
  :ttl => 10,
359
356
  :class => "IN"
360
357
  )
361
-
362
-
363
-
364
- klass = "IN"
365
- ttl = 43200
366
- name = 'def0au&lt.example.com'
367
-
368
-
369
-
358
+
359
+
360
+
361
+ klass = "IN"
362
+ ttl = 43200
363
+ name = 'def0au&lt.example.com'
364
+
365
+
366
+
370
367
  rrs = [
371
- { #[0]
372
- :name => '\..bla\..example.com',
373
- :type => Types.A,
374
- :address => '10.0.0.1',
368
+ { #[0]
369
+ :name => '\..bla\..example.com',
370
+ :type => Types.A,
371
+ :address => '10.0.0.1',
375
372
  },
376
373
  { #[2]
377
374
  :name => name,
378
- :type => 'AFSDB',
379
- :subtype => 1,
380
- :hostname =>'afsdb-hostname.example.com',
381
- },
375
+ :type => 'AFSDB',
376
+ :subtype => 1,
377
+ :hostname =>'afsdb-hostname.example.com',
378
+ },
382
379
  { #[3]
383
380
  :name => '\\.funny.example.com',
384
381
  :type => Types::CNAME,
@@ -394,14 +391,14 @@ d0
394
391
  :type => Types.MINFO,
395
392
  :rmailbx => 'minfo\.rmailbx.example.com',
396
393
  :emailbx => 'minfo\007emailbx.example.com',
397
- },
398
-
394
+ },
395
+
399
396
  { #[13]
400
397
  :name => name,
401
398
  :type => Types.NS,
402
399
  :domainname => '\001ns-nsdname.example.com',
403
400
  },
404
-
401
+
405
402
  { #[19]
406
403
  :name => name,
407
404
  :type => Types.SOA,
@@ -413,40 +410,40 @@ d0
413
410
  :expire => 2592000,
414
411
  :minimum => 86400,
415
412
  },
416
-
413
+
417
414
  ]
418
-
419
- #------------------------------------------------------------------------------
420
- # Create the packet.
421
- #------------------------------------------------------------------------------
415
+
416
+ # ------------------------------------------------------------------------------
417
+ # Create the packet.
418
+ # ------------------------------------------------------------------------------
422
419
  packet = nil
423
420
  packet = Message.new(name)
424
421
  assert(packet, 'Packet created')
425
-
422
+
426
423
  rrs.each do |data|
427
424
  data.update({:ttl => ttl,})
428
-
425
+
429
426
  rec = RR.create(data)
430
427
  packet.add_answer(rec)
431
428
  end
432
-
433
-
434
- #------------------------------------------------------------------------------
435
- # Re-create the packet from data.
436
- #------------------------------------------------------------------------------
429
+
430
+
431
+ # ------------------------------------------------------------------------------
432
+ # Re-create the packet from data.
433
+ # ------------------------------------------------------------------------------
437
434
  data = packet.encode
438
-
435
+
439
436
  assert(data, 'Packet has data after pushes')
440
-
437
+
441
438
  packet = nil
442
-
439
+
443
440
  packet = Message.decode(data)
444
-
441
+
445
442
  assert(packet, 'Packet reconstructed from data')
446
-
443
+
447
444
  answer = packet.answer
448
-
449
- # assert(answer && answer == rrs, 'Packet returned correct answer section')
445
+
446
+ # assert(answer && answer == rrs, 'Packet returned correct answer section')
450
447
  rrs.each do |rr|
451
448
  record = nil
452
449
  answer.each do |ansrec|
@@ -459,30 +456,30 @@ d0
459
456
  rr.keys.each do |key|
460
457
  if (key == :type)
461
458
  assert_equal(Types.new(rr[key]).string, record.send(key).to_s, "value not right for key #{key} for rr #{rr}")
462
- else
459
+ else
463
460
  assert_equal(rr[key].to_s, record.send(key).to_s, "value not right for key #{key} for rr #{rr}")
464
461
  end
465
462
  end
466
463
  end
467
-
468
-
464
+
465
+
469
466
  while (answer.size>0 and rrs.size>0)
470
467
  data = rrs.shift
471
468
  rr = answer.shift
472
469
  type = data[:type]
473
- # foreach my $meth (keys %{$data}) {
470
+ # foreach my $meth (keys %{$data}) {
474
471
  (data.keys.each do |meth|
475
- if (meth == :type)
472
+ if (meth == :type)
476
473
  assert_equal(Types.new(data[meth]).to_s, rr.send(meth).to_s, "#{type} - #meth() correct")
477
474
  else
478
475
  assert_equal(data[meth].to_s, rr.send(meth).to_s, "#{type} - #meth() correct")
479
476
  end
480
477
  end)
481
-
478
+
482
479
  rr2 = RR.new_from_string(rr.to_s)
483
480
  assert_equal(rr.to_s, rr2.to_s, "#{type} - Parsing from string works")
484
481
  end
485
-
482
+
486
483
  Name::Label.set_max_length(Name::Label::MaxLabelLength)
487
484
  end
488
485
  end