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.rb CHANGED
@@ -1,53 +1,50 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
16
- begin
17
- require 'rubygems'
18
- rescue LoadError
19
- end
20
- require 'test/unit'
21
- require 'dnsruby'
1
+ # --
2
+ # Copyright 2007 Nominet UK
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+
17
+ require_relative 'spec_helper'
18
+
22
19
  include Dnsruby
23
- class TestRR < Test::Unit::TestCase
20
+ class TestRR < Minitest::Test
24
21
  def test_rr
25
- #------------------------------------------------------------------------------
26
- # Canned data.
27
- #------------------------------------------------------------------------------
28
-
22
+ # ------------------------------------------------------------------------------
23
+ # Canned data.
24
+ # ------------------------------------------------------------------------------
25
+
29
26
  name = "foo.example.com";
30
27
  klass = "IN";
31
28
  ttl = 43200;
32
-
29
+
33
30
  rrs = [
34
31
  { #[0]
35
32
  :type => Types.A,
36
- :address => '10.0.0.1',
37
- },
33
+ :address => '10.0.0.1',
34
+ },
38
35
  { #[1]
39
36
  :type => Types::AAAA,
40
37
  :address => '102:304:506:708:90a:b0c:d0e:ff10',
41
- },
38
+ },
42
39
  { #[2]
43
40
  :type => 'AFSDB',
44
41
  :subtype => 1,
45
42
  :hostname => 'afsdb-hostname.example.com',
46
- },
43
+ },
47
44
  { #[3]
48
45
  :type => Types.CNAME,
49
46
  :domainname => 'cname-cname.example.com',
50
- },
47
+ },
51
48
  { #[4]
52
49
  :type => Types.DNAME,
53
50
  :domainname => 'dname.example.com',
@@ -56,29 +53,29 @@ class TestRR < Test::Unit::TestCase
56
53
  :type => Types.HINFO,
57
54
  :cpu => 'test-cpu',
58
55
  :os => 'test-os',
59
- },
56
+ },
60
57
  { #[6]
61
58
  :type => Types.ISDN,
62
59
  :address => '987654321',
63
60
  :subaddress => '001',
64
- },
61
+ },
65
62
  { #[7]
66
63
  :type => Types.MB,
67
64
  :domainname => 'mb-madname.example.com',
68
- },
65
+ },
69
66
  { #[8]
70
67
  :type => Types.MG,
71
68
  :domainname => 'mg-mgmname.example.com',
72
- },
69
+ },
73
70
  { #[9]
74
71
  :type => Types.MINFO,
75
72
  :rmailbx => 'minfo-rmailbx.example.com',
76
73
  :emailbx => 'minfo-emailbx.example.com',
77
- },
74
+ },
78
75
  { #[10]
79
76
  :type => Types.MR,
80
77
  :domainname => 'mr-newname.example.com',
81
- },
78
+ },
82
79
  { #[11]
83
80
  :type => Types.MX,
84
81
  :preference => 10,
@@ -107,14 +104,14 @@ class TestRR < Test::Unit::TestCase
107
104
  :area => '0020',
108
105
  :id => '00800a123456',
109
106
  :sel => '00',
110
- # #:address => '4700580005a001000002000800a12345600'
111
- # :address => '47000580005a0000001000002000800a12345600'
107
+ # #:address => '4700580005a001000002000800a12345600'
108
+ # :address => '47000580005a0000001000002000800a12345600'
112
109
  },
113
110
  { #[15]
114
111
  :type => Types.PTR,
115
112
  :domainname => 'ptr-ptrdname.example.com',
116
113
  },
117
- { #[16]
114
+ { #[16]
118
115
  :type => Types.PX,
119
116
  :preference => 10,
120
117
  :map822 => 'px-map822.example.com',
@@ -182,48 +179,48 @@ class TestRR < Test::Unit::TestCase
182
179
  :exchange => 'kx-exchange.example.com',
183
180
  },
184
181
  ]
185
-
186
-
187
- #------------------------------------------------------------------------------
188
- # Create the packet
189
- #------------------------------------------------------------------------------
190
-
182
+
183
+
184
+ # ------------------------------------------------------------------------------
185
+ # Create the packet
186
+ # ------------------------------------------------------------------------------
187
+
191
188
  message = Message.new
192
189
  assert(message, 'Message created');
193
-
194
-
190
+
191
+
195
192
  rrs.each do |data|
196
193
  data.update({ :name => name,
197
194
  :ttl => ttl,
198
195
  })
199
196
  rr=RR.create(data)
200
-
197
+
201
198
  message.add_answer(rr);
202
199
  end
203
-
204
- #------------------------------------------------------------------------------
205
- # Re-create the packet from data.
206
- #------------------------------------------------------------------------------
200
+
201
+ # ------------------------------------------------------------------------------
202
+ # Re-create the packet from data.
203
+ # ------------------------------------------------------------------------------
207
204
  data = message.encode;
208
205
  assert(data, 'Packet has data after pushes');
209
-
206
+
210
207
  message=nil;
211
208
  message= Message.decode(data);
212
-
209
+
213
210
  assert(message, 'Packet reconstructed from data');
214
-
211
+
215
212
  answer = message.answer;
216
-
213
+
217
214
  i = 0
218
215
  rrs.each do |rec|
219
216
  ret_rr = answer[i]
220
217
  i += 1
221
218
  rec.each do |key, value|
222
- # method = key+'=?'
219
+ # method = key+'=?'
223
220
  x = ret_rr.send(key)
224
221
  if (ret_rr.kind_of?RR::CERT and (key == :alg or key == :certtype))
225
222
  assert_equal(value.to_s, x.code.to_s.downcase, "Packet returned wrong answer section for #{ret_rr.to_s}, #{key}")
226
- elsif (ret_rr.kind_of?RR::TXT and (key == :strings))
223
+ elsif (ret_rr.kind_of?RR::TXT and (key == :strings))
227
224
  assert_equal(value.to_s.downcase, x[0].to_s.downcase, "TXT strings wrong")
228
225
  else
229
226
  if (key == :type)
@@ -234,25 +231,25 @@ class TestRR < Test::Unit::TestCase
234
231
  end
235
232
  end
236
233
  end
237
-
238
-
239
-
234
+
235
+
236
+
240
237
  while (!answer.empty? and !rrs.empty?)
241
238
  data = rrs.shift;
242
239
  rr = answer.shift;
243
240
  type = data[:type];
244
-
245
- assert(rr, "#{type} - RR defined");
246
- assert_equal(name, rr.name.to_s, "#{type} - name() correct");
241
+
242
+ assert(rr, "#{type} - RR defined");
243
+ assert_equal(name, rr.name.to_s, "#{type} - name() correct");
247
244
  assert_equal(klass, rr.klass.to_s, "#{type} - class() correct");
248
- assert_equal(ttl, rr.ttl, "#{type} - ttl() correct");
249
-
250
- # foreach my $meth (keys %{data}) {
245
+ assert_equal(ttl, rr.ttl, "#{type} - ttl() correct");
246
+
247
+ # foreach my $meth (keys %{data}) {
251
248
  data.keys.each do |meth|
252
249
  ret = rr.send(meth)
253
250
  if (rr.kind_of?RR::CERT and (meth == :alg or meth == :certtype))
254
251
  assert_equal(data[meth].to_s, ret.code.to_s.downcase, "#{type} - #{meth}() correct")
255
- elsif (rr.kind_of?RR::TXT and (meth == :strings))
252
+ elsif (rr.kind_of?RR::TXT and (meth == :strings))
256
253
  assert_equal(data[meth].to_s, ret[0].to_s.downcase, "TXT strings wrong")
257
254
  else
258
255
  if (meth == :type)
@@ -313,4 +310,13 @@ class TestRR < Test::Unit::TestCase
313
310
  assert rr.to_s.index('"Shuttle-ST61G4 Intel PIV3000"')
314
311
  assert rr.to_s.index('"FreeBSD 7.0-STABLE"')
315
312
  end
313
+
314
+ def test_private_method_really_private
315
+ begin
316
+ RR._get_subclass(nil, nil, nil, nil, nil)
317
+ raise "This should not have gotten here; the method should have been private"
318
+ rescue NoMethodError
319
+ # We should be here because the method should not have been found.
320
+ end
321
+ end
316
322
  end
data/test/tc_rrset.rb CHANGED
@@ -1,27 +1,26 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
1
+ # --
2
+ # Copyright 2007 Nominet UK
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
8
  # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
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 RrsetTest < Test::Unit::TestCase
19
+ class RrsetTest < Minitest::Test
21
20
  def test_rrset
22
21
  rrset = Dnsruby::RRSet.new
23
22
 
24
-
23
+
25
24
  rr=Dnsruby::RR.create({ :name => "example.com",
26
25
  :ttl => 3600,
27
26
  :type => 'MX',
@@ -34,18 +33,18 @@ class RrsetTest < Test::Unit::TestCase
34
33
  rrset.add(rr)
35
34
  rr.preference = 1
36
35
  rrset.add(rr)
37
-
36
+
38
37
  canon = rrset.sort_canonical
39
-
38
+
40
39
  assert(1 == canon[0].preference)
41
40
  assert(10 == canon[1].preference)
42
41
  assert(12 == canon[2].preference)
43
-
42
+
44
43
  assert(rrset.sigs.length == 0)
45
44
  assert(rrset.num_sigs == 0)
46
45
  assert(rrset.rrs.length == 3)
47
46
 
48
- # Check RRSIG records (only of the right type) can be added to the RRSet
47
+ # Check RRSIG records (only of the right type) can be added to the RRSet
49
48
  sig = Dnsruby::RR.create({:name=>"example.com", :ttl => 3600,
50
49
  :type => 'RRSIG',
51
50
  :type_covered => 'A',
data/test/tc_rrsig.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 RrsigTest < Test::Unit::TestCase
21
- INPUT = "host.example.com. 86400 IN RRSIG A 5 3 86400 20030322173103 ( " +
19
+ class RrsigTest < Minitest::Test
20
+ INPUT = "host.example.com. 86400 IN RRSIG A 5 3 86400 20030322173103 ( " +
22
21
  "20030220173103 2642 example.com. " +
23
22
  "oJB1W6WNGv+ldvQ3WDG0MQkg5IEhjRip8WTr" +
24
23
  "PYGv07h108dUKGMeDPKijVCHX3DDKdfb+v6o" +
@@ -27,7 +26,7 @@ class RrsigTest < Test::Unit::TestCase
27
26
  "J5D6fwFm8nN+6pBzeDQfsS3Ap3o= )"
28
27
  def test_rrsig_from_string
29
28
  rrsig = Dnsruby::RR.create(INPUT)
30
-
29
+
31
30
  assert_equal(Dnsruby::Types.A, rrsig.type_covered)
32
31
  assert_equal(Dnsruby::Algorithms::RSASHA1, rrsig.algorithm)
33
32
  assert_equal(3, rrsig.labels)
@@ -41,7 +40,7 @@ class RrsigTest < Test::Unit::TestCase
41
40
  "B9wfuh3DTJXUAfI/M0zmO/zz8bW0Rznl8O3t" +
42
41
  "GNazPwQKkRN20XPXV6nwwfoXmJQbsLNrLfkG" +
43
42
  "J5D6fwFm8nN+6pBzeDQfsS3Ap3o=", ([rrsig.signature].pack("m*")).gsub(/\n/,"").chomp)
44
-
43
+
45
44
  rrsig2 = Dnsruby::RR.create(rrsig.to_s)
46
45
  assert(rrsig2.to_s == rrsig.to_s)
47
46
  end
@@ -1,298 +1,295 @@
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 TestSingleResolver < Test::Unit::TestCase
24
- Thread::abort_on_exception = true
25
- # Dnsruby.log.level=Logger::DEBUG
26
-
27
- def setup
28
- Dnsruby::Config.reset
29
- end
30
-
31
- Rrs = [
32
- {
33
- :type => Types.A,
34
- :name => 'a.t.dnsruby.validation-test-servers.nominet.org.uk',
35
- :address => '10.0.1.128'
36
- },
37
- {
38
- :type => Types::MX,
39
- :name => 'mx.t.dnsruby.validation-test-servers.nominet.org.uk',
40
- :exchange => 'a.t.dnsruby.validation-test-servers.nominet.org.uk',
41
- :preference => 10
42
- },
43
- {
44
- :type => 'CNAME',
45
- :name => 'cname.t.dnsruby.validation-test-servers.nominet.org.uk',
46
- :domainname => 'a.t.dnsruby.validation-test-servers.nominet.org.uk'
47
- },
48
- {
49
- :type => Types.TXT,
50
- :name => 'txt.t.dnsruby.validation-test-servers.nominet.org.uk',
51
- :strings => ['Net-DNS']
52
- }
53
- ]
54
-
55
- def test_simple
56
- res = SingleResolver.new()
57
- m = res.query("a.t.dnsruby.validation-test-servers.nominet.org.uk")
58
- end
59
-
60
- def test_timeout
61
- # if ((RUBY_PLATFORM=~/darwin/) == nil)
62
- # Run a query which will not respond, and check that the timeout works
63
- start_time = 0
64
- begin
65
- udps = UDPSocket.new
66
- udps.bind("127.0.0.1", 0)
67
- port = *udps.addr.values_at(3,1)
68
-
69
- begin
70
- Dnsruby::PacketSender.clear_caches
71
- res = SingleResolver.new("127.0.0.1")
72
- res.port = port
73
- res.packet_timeout=1
74
- start_time = Time.now.to_i
75
- m = res.query("a.t.dnsruby.validation-test-servers.nominet.org.uk")
76
- fail "Got response when should have got none"
77
- rescue ResolvTimeout
78
- stop_time = Time.now.to_i
79
- assert((stop_time - start_time) <= (res.packet_timeout * 2),
80
- "UDP timeout too long : #{stop_time - start_time}" +
81
- ", should be #{res.packet_timeout}")
82
- end
83
- begin
84
- Dnsruby::PacketSender.clear_caches
85
- res = SingleResolver.new("127.0.0.1")
86
- res.port = port
87
- res.use_tcp = true
88
- res.packet_timeout=1
89
- start_time = Time.now.to_i
90
- # TheLog.level = Logger::DEBUG
91
- m = res.query("a.t.dnsruby.validation-test-servers.nominet.org.uk")
92
- fail "TCP timeouts"
93
- rescue ResolvTimeout
94
- # print "Got Timeout for TCP\n"
95
- stop_time = Time.now.to_i
96
- assert((stop_time - start_time) <= (res.packet_timeout * 2),
97
- "TCP timeout too long : #{stop_time - start_time}, should be #{res.packet_timeout}")
98
- rescue Exception => e
99
- fail(e)
100
- end
101
- TheLog.level = Logger::ERROR
102
- rescue
103
- udps.close
104
- end
105
- end
106
-
107
- def test_queue_timeout
108
- port = 46129
109
- # if (!RUBY_PLATFORM=~/darwin/)
110
- begin
111
- udps = UDPSocket.new
112
- udps.bind("127.0.0.1", 0)
113
- port = *udps.addr.values_at(3,1)
114
- res = SingleResolver.new("127.0.0.1")
115
- res.port = port
116
- res.packet_timeout=1
117
- q = Queue.new
118
- msg = Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk")
119
- res.send_async(msg, q, msg)
120
- id,ret, error = q.pop
121
- assert(id==msg)
122
- assert(ret==nil)
123
- assert(error.class == ResolvTimeout)
124
- rescue
125
- udps.close
126
- end
127
- # end
128
- end
129
-
130
- def test_queries
131
- res = SingleResolver.new
132
-
133
- Rrs.each do |data|
134
- packet=nil
135
- 2.times do
136
- begin
137
- packet = res.query(data[:name], data[:type])
138
- rescue ResolvTimeout
139
- end
140
- break if packet
141
- end
142
- assert(packet)
143
- assert_equal(packet.question[0].qclass, 'IN', 'Class correct' )
144
-
145
- assert(packet, "Got an answer for #{data[:name]} IN #{data[:type]}")
146
- assert_equal(1, packet.header.qdcount, 'Only one question')
147
- assert_equal(1, packet.header.ancount, 'Got single answer')
148
-
149
- question = (packet.question)[0]
150
- answer = (packet.answer)[0]
151
-
152
- assert(question, 'Got question' )
153
- assert_equal(data[:name], question.qname.to_s, 'Question has right name' )
154
- assert_equal(Types.new(data[:type]), question.qtype, 'Question has right type' )
155
- assert_equal('IN', question.qclass.string, 'Question has right class')
156
-
157
- assert(answer)
158
- assert_equal(answer.klass, 'IN', 'Class correct' )
159
-
160
-
161
- data.keys.each do |meth|
162
- if (meth == :type)
163
- assert_equal(Types.new(data[meth]).to_s, answer.send(meth).to_s, "#{meth} correct (#{data[:name]})")
164
- else
165
- assert_equal(data[meth].to_s, answer.send(meth).to_s, "#{meth} correct (#{data[:name]})")
166
- end
167
- end
168
- end # do
169
- end # test_queries
170
-
171
- # @TODO@ Although the test_thread_stopped test runs in isolation, it won't run as part
172
- # of the whole test suite (ts_dnsruby.rb). Commented out until I can figure out how to
173
- # get Test::Unit to run this one sequentially...
174
- # def test_thread_stopped
175
- # res=SingleResolver.new
176
- # # Send a query, and check select_thread running.
177
- # m = res.query("example.com")
178
- # assert(Dnsruby::SelectThread.instance.select_thread_alive?)
179
- # # Wait a second, and check select_thread stopped.
180
- # sleep(2)
181
- # assert(!Dnsruby::SelectThread.instance.select_thread_alive?)
182
- # # Send another query, and check select_thread running.
183
- # m = res.query("example.com")
184
- # assert(Dnsruby::SelectThread.instance.select_thread_alive?)
185
- # end
186
-
187
- def test_res_config
188
- res = Dnsruby::SingleResolver.new
189
-
190
- res.server=('a.t.dnsruby.validation-test-servers.nominet.org.uk')
191
- ip = res.server
192
- assert_equal('10.0.1.128', ip.to_s, 'nameserver() looks up IP.')
193
-
194
- res.server=('cname.t.dnsruby.validation-test-servers.nominet.org.uk')
195
- ip = res.server
196
- assert_equal('10.0.1.128', ip.to_s, 'nameserver() looks up cname.')
197
- end
198
-
199
- def test_truncated_response
200
- res = SingleResolver.new
201
- # print "Dnssec = #{res.dnssec}\n"
202
- res.server=('ns0.validation-test-servers.nominet.org.uk')
203
- res.packet_timeout = 15
204
- m = res.query("overflow.dnsruby.validation-test-servers.nominet.org.uk", 'txt')
205
- assert(m.header.ancount == 61, "61 answer records expected, got #{m.header.ancount}")
206
- assert(!m.header.tc, "Message was truncated!")
207
- end
208
-
209
- def test_illegal_src_port
210
- # Try to set src_port to an illegal value - make sure error raised, and port OK
211
- res = SingleResolver.new
212
- tests = [53, 387, 1265, 3210, 48619]
213
- tests.each do |bad_port|
214
- begin
215
- res.src_port = bad_port
216
- fail("bad port #{bad_port}")
217
- rescue
218
- end
219
- end
220
- end
221
-
222
- def test_add_src_port
223
- # Try setting and adding port ranges, and invalid ports, and 0.
224
- res = SingleResolver.new
225
- res.src_port = [56789,56790, 56793]
226
- assert(res.src_port == [56789,56790, 56793])
227
- res.src_port = 56889..56891
228
- assert(res.src_port == [56889,56890,56891])
229
- res.add_src_port(60000..60002)
230
- assert(res.src_port == [56889,56890,56891,60000,60001,60002])
231
- res.add_src_port([60004,60005])
232
- assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005])
233
- res.add_src_port(60006)
234
- assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
235
- # Now test invalid src_ports
236
- tests = [0, 53, [60007, 53], [60008, 0], 55..100]
237
- tests.each do |x|
238
- begin
239
- res.add_src_port(x)
240
- fail()
241
- rescue
242
- end
243
- end
244
- assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
245
- end
246
-
247
- def test_options_preserved_on_tcp_resend
248
- # Send a very small EDNS message to trigger tcp resend.
249
- # Can we do that without using send_raw and avoiding the case we want to test?
250
- # Sure - just knock up a little server here, which simply returns the response with the
251
- # TC bit set, and records both packets sent to it
252
- # Need to listen once on UDP and once on TCP
253
- udpPacket = nil
254
- tcpPacket = nil
255
- port = 59821
256
- thread = Thread.new {
257
- u = UDPSocket.new()
258
- u.bind("127.0.0.1", port)
259
-
260
- s = u.recvfrom(15000)
261
- received_query = s[0]
262
- udpPacket = Message.decode(received_query)
263
- u.connect(s[1][2], s[1][1])
264
- udpPacket.header.tc = true
265
- u.send(udpPacket.encode(),0)
266
- u.close
267
-
268
- ts = TCPServer.new(port)
269
- t = ts.accept
270
- packet = t.recvfrom(2)[0]
271
-
272
- len = (packet[0]<<8)+packet[1]
273
- if (RUBY_VERSION >= "1.9")
274
- len = (packet[0].getbyte(0)<<8)+packet[1].getbyte(0)# Ruby 1.9
275
- end
276
- packet = t.recvfrom(len)[0]
277
- tcpPacket = Message.decode(packet)
278
- tcpPacket.header.tc = true
279
- lenmsg = [tcpPacket.encode.length].pack('n')
280
- t.send(lenmsg, 0)
281
- t.write(tcpPacket.encode)
282
- t.close
283
- ts.close
284
- }
285
- ret = nil
286
- thread2 = Thread.new {
287
- r = SingleResolver.new("127.0.0.1")
288
- r.port = port
289
- ret = r.query("example.com")
290
- }
291
- thread.join
292
- thread2.join
293
- assert(tcpPacket && udpPacket)
294
- assert(tcpPacket.header == udpPacket.header)
295
- assert(tcpPacket.additional.rrsets('OPT', true)[0].rrs()[0].ttl == udpPacket.additional.rrsets('OPT', true)[0].rrs()[0].ttl, "UDP : #{udpPacket.additional.rrsets('OPT', true)[0].rrs()[0]}, TCP #{tcpPacket.additional.rrsets('OPT', true)[0].rrs()[0]}")
296
-
297
- 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 TestSingleResolver < Minitest::Test
21
+ Thread::abort_on_exception = true
22
+ # Dnsruby.log.level=Logger::DEBUG
23
+
24
+ def setup
25
+ Dnsruby::Config.reset
26
+ end
27
+
28
+ Rrs = [
29
+ {
30
+ :type => Types.A,
31
+ :name => 'a.t.dnsruby.validation-test-servers.nominet.org.uk',
32
+ :address => '10.0.1.128'
33
+ },
34
+ {
35
+ :type => Types::MX,
36
+ :name => 'mx.t.dnsruby.validation-test-servers.nominet.org.uk',
37
+ :exchange => 'a.t.dnsruby.validation-test-servers.nominet.org.uk',
38
+ :preference => 10
39
+ },
40
+ {
41
+ :type => 'CNAME',
42
+ :name => 'cname.t.dnsruby.validation-test-servers.nominet.org.uk',
43
+ :domainname => 'a.t.dnsruby.validation-test-servers.nominet.org.uk'
44
+ },
45
+ {
46
+ :type => Types.TXT,
47
+ :name => 'txt.t.dnsruby.validation-test-servers.nominet.org.uk',
48
+ :strings => ['Net-DNS']
49
+ }
50
+ ]
51
+
52
+ def test_simple
53
+ res = SingleResolver.new()
54
+ m = res.query("a.t.dnsruby.validation-test-servers.nominet.org.uk")
55
+ end
56
+
57
+ def test_timeout
58
+ # if ((RUBY_PLATFORM=~/darwin/) == nil)
59
+ # Run a query which will not respond, and check that the timeout works
60
+ start_time = 0
61
+ begin
62
+ udps = UDPSocket.new
63
+ udps.bind("127.0.0.1", 0)
64
+ port = *udps.addr.values_at(3,1)
65
+
66
+ begin
67
+ Dnsruby::PacketSender.clear_caches
68
+ res = SingleResolver.new("127.0.0.1")
69
+ res.port = port
70
+ res.packet_timeout=1
71
+ start_time = Time.now.to_i
72
+ m = res.query("a.t.dnsruby.validation-test-servers.nominet.org.uk")
73
+ fail "Got response when should have got none"
74
+ rescue ResolvTimeout
75
+ stop_time = Time.now.to_i
76
+ assert((stop_time - start_time) <= (res.packet_timeout * 2),
77
+ "UDP timeout too long : #{stop_time - start_time}" +
78
+ ", should be #{res.packet_timeout}")
79
+ end
80
+ begin
81
+ Dnsruby::PacketSender.clear_caches
82
+ res = SingleResolver.new("127.0.0.1")
83
+ res.port = port
84
+ res.use_tcp = true
85
+ res.packet_timeout=1
86
+ start_time = Time.now.to_i
87
+ # TheLog.level = Logger::DEBUG
88
+ m = res.query("a.t.dnsruby.validation-test-servers.nominet.org.uk")
89
+ fail "TCP timeouts"
90
+ rescue ResolvTimeout
91
+ # print "Got Timeout for TCP\n"
92
+ stop_time = Time.now.to_i
93
+ assert((stop_time - start_time) <= (res.packet_timeout * 2),
94
+ "TCP timeout too long : #{stop_time - start_time}, should be #{res.packet_timeout}")
95
+ rescue Exception => e
96
+ fail(e)
97
+ end
98
+ TheLog.level = Logger::ERROR
99
+ rescue
100
+ udps.close
101
+ end
102
+ end
103
+
104
+ def test_queue_timeout
105
+ port = 46129
106
+ # if (!RUBY_PLATFORM=~/darwin/)
107
+ begin
108
+ udps = UDPSocket.new
109
+ udps.bind("127.0.0.1", 0)
110
+ port = *udps.addr.values_at(3,1)
111
+ res = SingleResolver.new("127.0.0.1")
112
+ res.port = port
113
+ res.packet_timeout=1
114
+ q = Queue.new
115
+ msg = Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk")
116
+ res.send_async(msg, q, msg)
117
+ id,ret, error = q.pop
118
+ assert(id==msg)
119
+ assert(ret==nil)
120
+ assert(error.class == ResolvTimeout)
121
+ rescue
122
+ udps.close
123
+ end
124
+ # end
125
+ end
126
+
127
+ def test_queries
128
+ res = SingleResolver.new
129
+
130
+ Rrs.each do |data|
131
+ packet=nil
132
+ 2.times do
133
+ begin
134
+ packet = res.query(data[:name], data[:type])
135
+ rescue ResolvTimeout
136
+ end
137
+ break if packet
138
+ end
139
+ assert(packet)
140
+ assert_equal(packet.question[0].qclass, 'IN', 'Class correct' )
141
+
142
+ assert(packet, "Got an answer for #{data[:name]} IN #{data[:type]}")
143
+ assert_equal(1, packet.header.qdcount, 'Only one question')
144
+ assert_equal(1, packet.header.ancount, 'Got single answer')
145
+
146
+ question = (packet.question)[0]
147
+ answer = (packet.answer)[0]
148
+
149
+ assert(question, 'Got question' )
150
+ assert_equal(data[:name], question.qname.to_s, 'Question has right name' )
151
+ assert_equal(Types.new(data[:type]), question.qtype, 'Question has right type' )
152
+ assert_equal('IN', question.qclass.string, 'Question has right class')
153
+
154
+ assert(answer)
155
+ assert_equal(answer.klass, 'IN', 'Class correct' )
156
+
157
+
158
+ data.keys.each do |meth|
159
+ if (meth == :type)
160
+ assert_equal(Types.new(data[meth]).to_s, answer.send(meth).to_s, "#{meth} correct (#{data[:name]})")
161
+ else
162
+ assert_equal(data[meth].to_s, answer.send(meth).to_s, "#{meth} correct (#{data[:name]})")
163
+ end
164
+ end
165
+ end # do
166
+ end # test_queries
167
+
168
+ # @TODO@ Although the test_thread_stopped test runs in isolation, it won't run as part
169
+ # of the whole test suite (ts_dnsruby.rb). Commented out until I can figure out how to
170
+ # get Test::Unit to run this one sequentially...
171
+ # def test_thread_stopped
172
+ # res=SingleResolver.new
173
+ # # Send a query, and check select_thread running.
174
+ # m = res.query("example.com")
175
+ # assert(Dnsruby::SelectThread.instance.select_thread_alive?)
176
+ # # Wait a second, and check select_thread stopped.
177
+ # sleep(2)
178
+ # assert(!Dnsruby::SelectThread.instance.select_thread_alive?)
179
+ # # Send another query, and check select_thread running.
180
+ # m = res.query("example.com")
181
+ # assert(Dnsruby::SelectThread.instance.select_thread_alive?)
182
+ # end
183
+
184
+ def test_res_config
185
+ res = Dnsruby::SingleResolver.new
186
+
187
+ res.server=('a.t.dnsruby.validation-test-servers.nominet.org.uk')
188
+ ip = res.server
189
+ assert_equal('10.0.1.128', ip.to_s, 'nameserver() looks up IP.')
190
+
191
+ res.server=('cname.t.dnsruby.validation-test-servers.nominet.org.uk')
192
+ ip = res.server
193
+ assert_equal('10.0.1.128', ip.to_s, 'nameserver() looks up cname.')
194
+ end
195
+
196
+ def test_truncated_response
197
+ res = SingleResolver.new
198
+ # print "Dnssec = #{res.dnssec}\n"
199
+ res.server=('ns0.validation-test-servers.nominet.org.uk')
200
+ res.packet_timeout = 15
201
+ m = res.query("overflow.dnsruby.validation-test-servers.nominet.org.uk", 'txt')
202
+ assert(m.header.ancount == 61, "61 answer records expected, got #{m.header.ancount}")
203
+ assert(!m.header.tc, "Message was truncated!")
204
+ end
205
+
206
+ def test_illegal_src_port
207
+ # Try to set src_port to an illegal value - make sure error raised, and port OK
208
+ res = SingleResolver.new
209
+ tests = [53, 387, 1265, 3210, 48619]
210
+ tests.each do |bad_port|
211
+ begin
212
+ res.src_port = bad_port
213
+ fail("bad port #{bad_port}")
214
+ rescue
215
+ end
216
+ end
217
+ end
218
+
219
+ def test_add_src_port
220
+ # Try setting and adding port ranges, and invalid ports, and 0.
221
+ res = SingleResolver.new
222
+ res.src_port = [56789,56790, 56793]
223
+ assert(res.src_port == [56789,56790, 56793])
224
+ res.src_port = 56889..56891
225
+ assert(res.src_port == [56889,56890,56891])
226
+ res.add_src_port(60000..60002)
227
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002])
228
+ res.add_src_port([60004,60005])
229
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005])
230
+ res.add_src_port(60006)
231
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
232
+ # Now test invalid src_ports
233
+ tests = [0, 53, [60007, 53], [60008, 0], 55..100]
234
+ tests.each do |x|
235
+ begin
236
+ res.add_src_port(x)
237
+ fail()
238
+ rescue
239
+ end
240
+ end
241
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
242
+ end
243
+
244
+ def test_options_preserved_on_tcp_resend
245
+ # Send a very small EDNS message to trigger tcp resend.
246
+ # Can we do that without using send_raw and avoiding the case we want to test?
247
+ # Sure - just knock up a little server here, which simply returns the response with the
248
+ # TC bit set, and records both packets sent to it
249
+ # Need to listen once on UDP and once on TCP
250
+ udpPacket = nil
251
+ tcpPacket = nil
252
+ port = 59821
253
+ thread = Thread.new {
254
+ u = UDPSocket.new()
255
+ u.bind("127.0.0.1", port)
256
+
257
+ s = u.recvfrom(15000)
258
+ received_query = s[0]
259
+ udpPacket = Message.decode(received_query)
260
+ u.connect(s[1][2], s[1][1])
261
+ udpPacket.header.tc = true
262
+ u.send(udpPacket.encode(),0)
263
+ u.close
264
+
265
+ ts = TCPServer.new(port)
266
+ t = ts.accept
267
+ packet = t.recvfrom(2)[0]
268
+
269
+ len = (packet[0]<<8)+packet[1]
270
+ if (RUBY_VERSION >= "1.9")
271
+ len = (packet[0].getbyte(0)<<8)+packet[1].getbyte(0)# Ruby 1.9
272
+ end
273
+ packet = t.recvfrom(len)[0]
274
+ tcpPacket = Message.decode(packet)
275
+ tcpPacket.header.tc = true
276
+ lenmsg = [tcpPacket.encode.length].pack('n')
277
+ t.send(lenmsg, 0)
278
+ t.write(tcpPacket.encode)
279
+ t.close
280
+ ts.close
281
+ }
282
+ ret = nil
283
+ thread2 = Thread.new {
284
+ r = SingleResolver.new("127.0.0.1")
285
+ r.port = port
286
+ ret = r.query("example.com")
287
+ }
288
+ thread.join
289
+ thread2.join
290
+ assert(tcpPacket && udpPacket)
291
+ assert(tcpPacket.header == udpPacket.header)
292
+ assert(tcpPacket.additional.rrsets('OPT', true)[0].rrs()[0].ttl == udpPacket.additional.rrsets('OPT', true)[0].rrs()[0].ttl, "UDP : #{udpPacket.additional.rrsets('OPT', true)[0].rrs()[0]}, TCP #{tcpPacket.additional.rrsets('OPT', true)[0].rrs()[0]}")
293
+
294
+ end
298
295
  end