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_rr-opt.rb CHANGED
@@ -1,51 +1,58 @@
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
  require 'socket'
20
+
23
21
  include Dnsruby
24
- class TestRrOpt < Test::Unit::TestCase
22
+ class TestRrOpt < Minitest::Test
25
23
  def test_rropt
26
24
  size=2048;
27
25
  ednsflags=0x9e22;
28
-
26
+
29
27
  optrr = RR::OPT.new(size, ednsflags)
30
-
28
+
31
29
  assert(optrr.dnssec_ok,"DO bit set")
32
30
  optrr.dnssec_ok=false
33
31
  assert_equal(optrr.flags,0x1e22,"Clearing do, leaving the other bits ");
34
32
  assert(!optrr.dnssec_ok,"DO bit cleared")
35
33
  optrr.dnssec_ok=true
36
34
  assert_equal(optrr.flags,0x9e22,"Clearing do, leaving the other bits ");
37
-
38
-
35
+
39
36
  assert_equal(optrr.payloadsize,2048,"Size read")
40
37
  assert_equal(optrr.payloadsize=(1498),1498,"Size set")
41
-
38
+
39
+ optrr.set_client_subnet("0.0.0.0/0")
40
+ assert_equal(optrr.edns_client_subnet,"0.0.0.0/0/0","Wildcard Address")
41
+ optrr.set_client_subnet("216.253.14.2/24")
42
+ assert_equal(optrr.edns_client_subnet,"216.253.14.0/24/0","IPv4 subnet")
43
+ optrr.set_client_subnet("216.253.14.2/1")
44
+ assert_equal(optrr.edns_client_subnet,"216.0.0.0/1/0","IPv4 subnet <8 bits")
45
+ optrr.set_client_subnet("2600:3c00:0:91fd:ab77:157e::/64")
46
+ assert_equal(optrr.edns_client_subnet,"2600:3c00:0:91fd::/64/0","IPv6 subnet")
47
+ optrr.set_client_subnet("2600:3c00:0:91fd:ab77:157e::/7")
48
+ assert_equal(optrr.edns_client_subnet,"2600::/7/0","IPv6 subnet <8 bits")
42
49
  end
43
-
50
+
44
51
  def test_resolver_opt_application
45
52
  return if (/java/ =~ RUBY_PLATFORM) # @TODO@ Check if this is fixed with JRuby yet
46
- # Set up a server running on localhost. Get the resolver to send a
47
- # query to it with the UDP size set to 4096. Make sure that it is received
48
- # correctly.
53
+ # Set up a server running on localhost. Get the resolver to send a
54
+ # query to it with the UDP size set to 4096. Make sure that it is received
55
+ # correctly.
49
56
  Dnsruby::PacketSender.clear_caches
50
57
  socket = UDPSocket.new
51
58
  socket.bind("127.0.0.1", 0)
@@ -58,62 +65,62 @@ class TestRrOpt < Test::Unit::TestCase
58
65
  q.push(Message.decode(received_query))
59
66
  socket.send(received_query,0)
60
67
  }
61
-
62
- # Now send query
68
+
69
+ # Now send query
63
70
  res = Resolver.new("127.0.0.1")
64
71
  res.port = port
65
72
  res.udp_size = 4096
66
73
  assert(res.udp_size == 4096)
67
74
  res.query("example.com")
68
-
69
- # Now get received query from the server
75
+
76
+ # Now get received query from the server
70
77
  p = q.pop
71
- # Now check the query was what we expected
78
+ # Now check the query was what we expected
72
79
  assert(p.header.arcount == 1)
73
80
  assert(p.additional()[0].type = Types.OPT)
74
81
  assert(p.additional()[0].klass.code == 4096)
75
82
  end
76
-
83
+
77
84
  def test_large_packet
78
- # Query TXT for overflow.dnsruby.validation-test-servers.nominet.org.uk
79
- # with a large udp_size
85
+ # Query TXT for overflow.dnsruby.validation-test-servers.nominet.org.uk
86
+ # with a large udp_size
80
87
  res = SingleResolver.new
81
88
  res.udp_size = 4096
82
89
  ret = res.query("overflow.dnsruby.validation-test-servers.nominet.org.uk", Types.TXT)
83
90
  assert(ret.rcode == RCode.NoError)
84
91
  end
85
-
92
+
86
93
  def test_decode_opt
87
- # Create an OPT RR
94
+ # Create an OPT RR
88
95
  size=2048;
89
96
  ednsflags=0x9e22;
90
97
  optrr = RR::OPT.new(size, ednsflags)
91
-
92
- # Add it to a message
98
+
99
+ # Add it to a message
93
100
  m = Message.new
94
101
  m.add_additional(optrr)
95
-
96
- # Encode the message
102
+
103
+ # Encode the message
97
104
  data = m.encode
98
-
99
- # Decode it
105
+
106
+ # Decode it
100
107
  m2 = Message.decode(data)
101
-
102
- # Make sure there is an OPT RR there
108
+
109
+ # Make sure there is an OPT RR there
103
110
  assert(m2.rcode == RCode.NOERROR )
104
111
  end
105
112
 
106
113
  def test_formerr_response
107
- # If we get a FORMERR back from the remote resolver, we should retry with no OPT record
108
- # So, we need a server which sends back FORMERR for OPT records, and is OK without them.
109
- # Then, we need to get a client to send a request to it (by default adorned with EDNS0),
110
- # and make sure that the response is returned to the client OK.
111
- # We should then check that the server only received one message with EDNS0, and one message
112
- # without.
114
+ # If we get a FORMERR back from the remote resolver, we should retry with no OPT record
115
+ # So, we need a server which sends back FORMERR for OPT records, and is OK without them.
116
+ # Then, we need to get a client to send a request to it (by default adorned with EDNS0),
117
+ # and make sure that the response is returned to the client OK.
118
+ # We should then check that the server only received one message with EDNS0, and one message
119
+ # without.
113
120
  return if (/java/ =~ RUBY_PLATFORM) # @TODO@ Check if this is fixed with JRuby yet
114
- # Set up a server running on localhost. Get the resolver to send a
115
- # query to it with the UDP size set to 4096. Make sure that it is received
116
- # correctly.
121
+ # Set up a server running on localhost. Get the resolver to send a
122
+ # query to it with the UDP size set to 4096. Make sure that it is received
123
+ # correctly.
117
124
  Dnsruby::PacketSender.clear_caches
118
125
  socket = UDPSocket.new
119
126
  socket.bind("127.0.0.1", 0)
@@ -126,7 +133,7 @@ class TestRrOpt < Test::Unit::TestCase
126
133
  m = Message.decode(received_query)
127
134
  q.push(m)
128
135
  if (m.header.arcount > 0)
129
- # send back FORMERR
136
+ # send back FORMERR
130
137
  m.header.rcode = RCode.FORMERR
131
138
  socket.send(m.encode,0,s[1][2], s[1][1])
132
139
  else
@@ -135,7 +142,7 @@ class TestRrOpt < Test::Unit::TestCase
135
142
  }
136
143
 
137
144
  }
138
- # Now send query
145
+ # Now send query
139
146
  res = Resolver.new("127.0.0.1")
140
147
  res.port = port
141
148
  res.udp_size = 4096
@@ -144,14 +151,14 @@ class TestRrOpt < Test::Unit::TestCase
144
151
  assert(ret.header.get_header_rcode == RCode.NOERROR)
145
152
  assert(ret.header.arcount == 0)
146
153
 
147
- # Now get received query from the server
154
+ # Now get received query from the server
148
155
  p = q.pop
149
- # Now check the query was what we expected
156
+ # Now check the query was what we expected
150
157
  assert(p.header.arcount == 1)
151
158
  assert(p.additional()[0].type = Types.OPT)
152
159
  assert(p.additional()[0].klass.code == 4096)
153
160
 
154
- # Now check the second message
161
+ # Now check the second message
155
162
  assert (!(q.empty?))
156
163
  p2 = q.pop
157
164
  assert (p2)
data/test/tc_rr-txt.rb CHANGED
@@ -1,28 +1,25 @@
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 TestRrTest < Test::Unit::TestCase
24
- #Stimulus, expected response, and test name:
25
-
20
+ class TestRrTest < Minitest::Test
21
+ # Stimulus, expected response, and test name:
22
+
26
23
  TESTLIST = [
27
24
  { # 2-5
28
25
  :stim => %<"">,
@@ -60,82 +57,82 @@ class TestRrTest < Test::Unit::TestCase
60
57
  :char_str_list_r => [ %q|two|, %q|tokens|, ],
61
58
  :descr => 'Two unquoted strings',
62
59
  },
63
- # @TODO@ Why don't escaped quotes work?
64
- # { # 22-25
65
- # :stim => %<"escaped \" quote">,
66
- # :rdatastr => %<"escaped \" quote">,
67
- # :char_str_list_r => [ %<escaped " quote>, ],
68
- # :descr => 'Quoted, escaped double-quote',
69
- # },
70
- # { # 30-33
71
- # :stim => %<"missing quote>,
72
- # :rdatastr => %<>,
73
- # :char_str_list_r => [],
74
- # :descr => 'Unbalanced quotes work',
75
- # }
60
+ # @TODO@ Why don't escaped quotes work?
61
+ # { # 22-25
62
+ # :stim => %<"escaped \" quote">,
63
+ # :rdatastr => %<"escaped \" quote">,
64
+ # :char_str_list_r => [ %<escaped " quote>, ],
65
+ # :descr => 'Quoted, escaped double-quote',
66
+ # },
67
+ # { # 30-33
68
+ # :stim => %<"missing quote>,
69
+ # :rdatastr => %<>,
70
+ # :char_str_list_r => [],
71
+ # :descr => 'Unbalanced quotes work',
72
+ # }
76
73
  ]
77
-
74
+
78
75
  def test_RrTest
79
- #------------------------------------------------------------------------------
80
- # Canned data.
81
- #------------------------------------------------------------------------------
82
-
76
+ # ------------------------------------------------------------------------------
77
+ # Canned data.
78
+ # ------------------------------------------------------------------------------
79
+
83
80
  name = 'foo.example.com';
84
81
  klass = 'IN';
85
82
  type = 'TXT';
86
83
  ttl = 43201;
87
-
84
+
88
85
  rr_base = [name, ttl, klass, type, " " ].join(' ')
89
-
90
-
91
- #------------------------------------------------------------------------------
92
- # Run the tests
93
- #------------------------------------------------------------------------------
94
-
86
+
87
+
88
+ # ------------------------------------------------------------------------------
89
+ # Run the tests
90
+ # ------------------------------------------------------------------------------
91
+
95
92
  TESTLIST.each do |test_hr|
96
- assert( uut = RR.create(rr_base + test_hr[:stim]),
97
- test_hr[:descr] + " -- Stimulus " )
98
-
99
- assert_equal(test_hr[:rdatastr], uut.rdata_to_string(),
100
- test_hr[:descr] + " -- Response ( rdatastr ) " )
101
-
102
- list = uut.strings
103
-
93
+ assert( uut = RR.create(rr_base + test_hr[:stim]),
94
+ test_hr[:descr] + " -- Stimulus " )
95
+
96
+ assert_equal(test_hr[:rdatastr], uut.rdata_to_string(),
97
+ test_hr[:descr] + " -- Response ( rdatastr ) " )
98
+
99
+ list = uut.strings
100
+
104
101
  assert_equal(test_hr[:char_str_list_r], list,
105
- test_hr[:descr] + " -- char_str_list equality" )
102
+ test_hr[:descr] + " -- char_str_list equality" )
106
103
  end
107
-
104
+
108
105
  string1 = %<no>
109
106
  string2 = %<quotes>
110
-
107
+
111
108
  rdata = [string1.length].pack("C") + string1
112
109
  rdata += [string2.length].pack("C") + string2
113
-
110
+
114
111
  work_hash = {
115
112
  :name => name,
116
113
  :ttl => ttl,
117
114
  :class => klass,
118
115
  :type => type,
119
116
  }
120
-
121
-
122
- # Don't break RR.new_from_hash (e.i. "See the manual pages for each RR
123
- # type to see what fields the type requires.").
124
-
117
+
118
+
119
+ # Don't break RR.new_from_hash (e.i. "See the manual pages for each RR
120
+ # type to see what fields the type requires.").
121
+
125
122
  work_hash[:strings] = %<no quotes>
126
-
127
- uut = RR.create(work_hash)
123
+
124
+ uut = RR.create(work_hash)
128
125
  assert( uut , # 30
129
126
  "RR.new_from_hash with txtdata -- Stimulus")
130
127
  assert_equal( uut.rdata_to_string() , %<"no" "quotes">, # 31
131
128
  "RR.new_from_hash with txtdata -- Response (rdatastr())")
132
-
129
+
133
130
  rr_rdata = MessageEncoder.new {|msg|
134
131
  uut.encode_rdata(msg)
135
132
  }.to_s
136
133
  assert( rr_rdata == rdata , "TXT.rr_rdata" ) # 32
137
-
138
-
134
+
135
+
139
136
  end
140
137
 
141
138
  def test_nasty_txt
@@ -1,98 +1,95 @@
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 TestRrUnknown < Test::Unit::TestCase
20
+ class TestRrUnknown < Minitest::Test
24
21
  def test_RrUnknown
25
22
  assert_equal(10226, Types::typesbyname('TYPE10226'), 'typesbyname(TYPE10226) returns 10226')
26
23
  assert_equal('TYPE10226', Types::typesbyval(10226), 'typesbyval(10226) returns TYPE10226')
27
24
  assert_equal(Types::typesbyval(1), "A", ' typesbyval(1) returns A')
28
-
25
+
29
26
  assert_equal(Types::typesbyval(Types.typesbyname('TYPE001')), 'A', 'typesbyval(typebyname(TYPE001)) returns A')
30
-
31
-
27
+
28
+
32
29
  begin
33
30
  Types.typesbyval(0xffff+1)
34
31
  flunk("Should fail on large TYPE code")
35
32
  rescue Exception
36
33
  end
37
-
34
+
38
35
  assert_equal(Classes::classesbyname('CLASS124'), 124, 'classesbyname(CLASS124) returns 124')
39
36
  assert_equal(Classes::classesbyval(125), 'CLASS125','classesbyval(125) returns CLASS125')
40
37
  assert_equal(Classes::classesbyval(1), 'IN', 'classesbyval(1) returns IN')
41
-
38
+
42
39
  assert_equal('HS', Classes::classesbyval(Classes::classesbyname('CLASS04')), 'classesbyval(typebyname(CLASS04)) returns HS')
43
-
40
+
44
41
  begin
45
42
  Classes::classesbyval(0xffff+1)
46
43
  flunk("Should fail on large CLASS code")
47
44
  rescue Exception
48
45
  end
49
46
  end
50
-
47
+
51
48
  def test_rr_new
52
49
  rr = RR.new_from_string('e.example CLASS01 TYPE01 10.0.0.2')
53
50
  assert_equal(RR::IN::A, rr.class, 'TYPE01 parsed OK')
54
51
  assert_equal('A', rr.type.string, 'TYPE01 parsed OK')
55
52
  assert_equal('IN', rr.klass.string,'CLASS01 parsed OK')
56
53
  assert_equal(1, rr.klass.code,'CLASS01 parsed OK')
57
-
54
+
58
55
  rr = RR.new_from_string('e.example IN A \# 4 0A0000 01 ')
59
56
  assert_equal('10.0.0.1', rr.address.to_s,'Unknown RR representation for A parsed OK')
60
-
57
+
61
58
  begin
62
59
  res=RR.new_from_string('e.example IN A \# 4 0A0000 01 11 ')
63
60
  flunk "Should fail on inconsistent length and hex presentation"
64
61
  rescue Exception
65
- #like($@, '/\\\# 4 0A0000 01 11 assert_equal inconsistent\ length does not match content/', 'Fails on inconsassert_equaltent length and hex presentation')
62
+ # like($@, '/\\\# 4 0A0000 01 11 assert_equal inconsistent\ length does not match content/', 'Fails on inconsassert_equaltent length and hex presentation')
66
63
  end
67
-
68
-
64
+
65
+
69
66
  rr = RR.new_from_string('e.example IN TYPE4555 \# 4 0A0000 01 ')
70
67
  assert_equal('e.example 0 IN TYPE4555 \# 4 0a000001', rr.to_s, 'Fully unknown RR parsed correctly')
71
-
68
+
72
69
  rr4 = RR.new_from_string('e.example. CLASS122 TYPE4555 \# 4 0A0000 01 ')
73
70
  assert_equal('e.example. 0 CLASS122 TYPE4555 \# 4 0a000001', rr4.to_s, 'Fully unknown RR in unknown CLASS parsed correctly')
74
71
  end
75
-
72
+
76
73
  def test_real_data
77
74
  uuencodedPacket=%w{
78
- 02 79 85 00 00 01
79
- 00 01 00 01 00 01 04 54 45 53 54 07 65 78 61 6d
80
- 70 6c 65 03 63 6f 6d 00 00 ff 00 01 c0 0c 30 39
81
- 00 01 00 00 00 7b 00 0a 11 22 33 44 55 aa bb cc
82
- dd ee c0 11 00 02 00 01 00 00 03 84 00 05 02 6e
83
- 73 c0 11 c0 44 00 01 00 01 00 00 03 84 00 04 7f
75
+ 02 79 85 00 00 01
76
+ 00 01 00 01 00 01 04 54 45 53 54 07 65 78 61 6d
77
+ 70 6c 65 03 63 6f 6d 00 00 ff 00 01 c0 0c 30 39
78
+ 00 01 00 00 00 7b 00 0a 11 22 33 44 55 aa bb cc
79
+ dd ee c0 11 00 02 00 01 00 00 03 84 00 05 02 6e
80
+ 73 c0 11 c0 44 00 01 00 01 00 00 03 84 00 04 7f
84
81
  00 00 01}
85
-
86
- # packetdata = uuencodedPacket.pack('H*')
87
- # packetdata = packetdata.gsub("\s*", "")
88
-
82
+
83
+ # packetdata = uuencodedPacket.pack('H*')
84
+ # packetdata = packetdata.gsub("\s*", "")
85
+
89
86
  uuencodedPacket.map!{|e| e.hex}
90
87
  packetdata = uuencodedPacket.pack('c*')
91
88
  # packet = Net::Packet.new_from_binary(packetdata)
92
89
  packet = Message.decode(packetdata)
93
-
90
+
94
91
  string_representation = (packet.answer)[0].to_s
95
- #string_representation =~ s/\s+/ /g,
92
+ # string_representation =~ s/\s+/ /g,
96
93
  string_representation = string_representation.gsub(/\s+/, " ")
97
94
  assert_equal(
98
95
  'TEST.example.com. 123 IN TYPE12345 \# 10 1122334455aabbccddee',