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_res_env.rb CHANGED
@@ -1,54 +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'
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 TestResolverEnv < Test::Unit::TestCase
20
+ class TestResolverEnv < Minitest::Test
24
21
  # @todo@ Dnsruby does not provide this functionality
25
22
  def test_res_env
26
23
  ENV['RES_NAMESERVERS'] = '10.0.1.128 10.0.2.128';
27
24
  ENV['RES_SEARCHLIST'] = 'dnsruby.validation-test-servers.nominet.org.uk lib.dnsruby.validation-test-servers.nominet.org.uk';
28
25
  ENV['LOCALDOMAIN'] = 't.dnsruby.validation-test-servers.nominet.org.uk';
29
26
  ENV['RES_OPTIONS'] = 'retrans:3 retry:2 debug';
30
-
31
-
27
+
28
+
32
29
  res = DNS.new;
33
-
30
+
34
31
  assert(res, "new() returned something");
35
32
  assert(res.config.nameserver, "nameservers() works");
36
-
33
+
37
34
  servers = res.config.nameserver;
38
-
35
+
39
36
  assert_equal(servers[0], '10.0.1.128', 'Nameserver set correctly');
40
37
  assert_equal(servers[1], '10.0.2.128', 'Nameserver set correctly');
41
-
42
-
38
+
39
+
43
40
  search = res.searchlist;
44
41
  assert_equal(search[0], 'dnsruby.validation-test-servers.nominet.org.uk', 'Search set correctly' );
45
42
  assert_equal(search[1], 'lib.dnsruby.validation-test-servers.nominet.org.uk', 'Search set correctly' );
46
-
43
+
47
44
  assert_equal(res.domain, 't.dnsruby.validation-test-servers.nominet.org.uk', 'Local domain works' );
48
45
  assert_equal(3, res.retrans, 'Retransmit works' );
49
46
  assert_equal(2, res.retry, 'Retry works' );
50
47
  assert(res.debug, 'Debug works' );
51
-
52
-
48
+
49
+
53
50
  end
54
51
  end
data/test/tc_res_file.rb CHANGED
@@ -1,45 +1,42 @@
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
- class TestAResolverFile < Test::Unit::TestCase
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
+ class TestAResolverFile < Minitest::Test
23
20
  def setup
24
21
  Dnsruby::Config.reset
25
22
  end
26
-
23
+
27
24
  def test_resFile
28
25
  res = Dnsruby::DNS.new("test/resolv.conf")
29
-
26
+
30
27
  assert(res, "new() returned something")
31
28
  assert(res.config.nameserver, "nameservers() works")
32
-
29
+
33
30
  servers = res.config.nameserver
34
-
31
+
35
32
  assert_equal(servers[0], '10.0.1.128', 'Nameserver set correctly')
36
33
  assert_equal(servers[1], '10.0.2.128', 'Nameserver set correctly')
37
-
38
-
34
+
35
+
39
36
  search = res.config.search
40
37
  assert(search.include?('dnsruby.validation-test-servers.nominet.org.uk'), 'Search set correctly' )
41
38
  assert(search.include?('lib.dnsruby.validation-test-servers.nominet.org.uk'), 'Search set correctly' )
42
-
39
+
43
40
  assert(res.config.domain=='t.dnsruby.validation-test-servers.nominet.org.uk', 'Local domain works' )
44
41
  end
45
42
  end
data/test/tc_res_opt.rb CHANGED
@@ -1,54 +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'
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 TestResOpt < Test::Unit::TestCase
20
+ class TestResOpt < Minitest::Test
24
21
  def test_dns_file
25
-
26
- # .txt because this test will run under windows, unlike the other file
27
- # configuration tests.
22
+
23
+ # .txt because this test will run under windows, unlike the other file
24
+ # configuration tests.
28
25
  res = Dnsruby::DNS.new('test/custom.txt')
29
-
26
+
30
27
  assert(res, 'new() returned something')
31
28
  assert_instance_of(DNS, res, 'new() returns an object of the correct class.')
32
29
  assert(res.config.nameserver, 'nameservers() works')
33
-
30
+
34
31
  servers = res.config.nameserver
35
-
32
+
36
33
  assert_equal('10.0.1.42', servers[0], 'Nameserver set correctly')
37
34
  assert_equal('10.0.2.42', servers[1], 'Nameserver set correctly')
38
-
39
-
35
+
36
+
40
37
  search = res.config.search
41
38
  assert(search.include?('alt.dnsruby.validation-test-servers.nominet.org.uk'), 'Search set correctly' )
42
39
  assert(search.include?('ext.dnsruby.validation-test-servers.nominet.org.uk'), 'Search set correctly' )
43
-
40
+
44
41
  assert(res.config.domain == 't2.dnsruby.validation-test-servers.nominet.org.uk', 'Local domain works' )
45
42
  end
46
-
43
+
47
44
  def test_resolver_file
48
45
  res = Dnsruby::Resolver.new({:config_info => 'test/custom.txt'})
49
46
  assert(res.config.nameserver==['10.0.1.42', '10.0.2.42'], res.config.nameserver.to_s)
50
47
  end
51
-
48
+
52
49
  def test_no_file
53
50
  Dnsruby.log.level=Logger::FATAL
54
51
  res=nil
@@ -64,10 +61,10 @@ class TestResOpt < Test::Unit::TestCase
64
61
  end
65
62
  # Dnsruby.log.level=Logger::ERROR
66
63
  end
67
-
64
+
68
65
  def test_config_hash_singleresolver
69
- # Resolver interface gives us : port, TCP, IgnoreTruncation, TSIGkey, timeout
70
- # SR : server, local_address, udp_size
66
+ # Resolver interface gives us : port, TCP, IgnoreTruncation, TSIGkey, timeout
67
+ # SR : server, local_address, udp_size
71
68
  test_config = {
72
69
  :server => '10.0.0.1',
73
70
  :port => 54, # SingleResolver and Multi-Resolver
@@ -80,17 +77,17 @@ class TestResOpt < Test::Unit::TestCase
80
77
  :packet_timeout => 60, # SingleResolver and Multi-Resolver # Only have one timeout for both UDP and TCP
81
78
  :dnssec => true,
82
79
  }
83
-
80
+
84
81
  res = SingleResolver.new(test_config)
85
82
  test_config.keys.each do |item|
86
83
  assert_equal(test_config[item], res.send(item), "#{item} is correct")
87
- end
84
+ end
88
85
  end
89
-
86
+
90
87
  def test_config_hash_multiresolver
91
- # Resolver interface gives us : port, TCP, IgnoreTruncation, TSIGkey, timeout
92
- # ER : retries, load_balance. Also loads servers from Config and configures SRs to point to them
93
- # Also implements Resolver interface - but iterates this through *all* SRs
88
+ # Resolver interface gives us : port, TCP, IgnoreTruncation, TSIGkey, timeout
89
+ # ER : retries, load_balance. Also loads servers from Config and configures SRs to point to them
90
+ # Also implements Resolver interface - but iterates this through *all* SRs
94
91
  test_config = {
95
92
  :nameserver => ['10.0.0.1', '10.0.0.2'], # for Multi-Resolver & DNS
96
93
  :port => 54, # SingleResolver and Multi-Resolver
@@ -101,12 +98,12 @@ class TestResOpt < Test::Unit::TestCase
101
98
  :retry_times => 5, # DNSand Multi-Resolver
102
99
  :use_tcp => true, # SingleResolver and Multi-Resolver
103
100
  :ignore_truncation => true, # SingleResolver and Multi-Resolver
104
- :recurse => false,
101
+ :recurse => false,
105
102
  :packet_timeout => 60, # SingleResolver and Multi-Resolver # Only have one timeout for both UDP and TCP
106
103
  :query_timeout => 60, # Multi-Resolver only
107
104
  :dnssec => true,
108
105
  }
109
-
106
+
110
107
  res = Resolver.new(test_config)
111
108
  test_config.keys.each do |item|
112
109
  if (item==:nameserver)
@@ -114,36 +111,36 @@ class TestResOpt < Test::Unit::TestCase
114
111
  else
115
112
  assert_equal(res.send(item), test_config[item], "#{item} is correct")
116
113
  end
117
- end
114
+ end
118
115
  end
119
-
116
+
120
117
  def test_config_hash_lookup
121
- # Lookup : can specify resolver, searchpath
122
- #
123
- # Check that we can set things in new()
124
- #
118
+ # Lookup : can specify resolver, searchpath
119
+ #
120
+ # Check that we can set things in new()
121
+ #
125
122
  res=nil
126
-
123
+
127
124
  test_config = {
128
125
  :nameserver => ['10.0.0.1', '10.0.0.2'], # for Multi-Resolver & DNS
129
126
  :domain => 'dnsruby.validation-test-servers.nominet.org.uk', # one for DNS only?
130
127
  :search => ['dnsruby.validation-test-servers.nominet.org.uk', 't.dnsruby.validation-test-servers.nominet.org.uk'], # one for DNS
131
128
  :ndots => 2, # DNS only
132
- :apply_search_list => false, # DNS only
133
- :apply_domain => false, # DNS only
129
+ :apply_search_list => false, # DNS only
130
+ :apply_domain => false, # DNS only
134
131
  }
135
-
132
+
136
133
  res = DNS.new(test_config)
137
134
  test_config.keys.each do |item|
138
135
  assert_equal(res.config.send(item), test_config[item], "#{item} is correct")
139
- end
136
+ end
140
137
  end
141
-
142
-
138
+
139
+
143
140
  def test_bad_config
144
141
  res=nil
145
142
  Dnsruby.log.level=Logger::FATAL
146
-
143
+
147
144
  bad_input = {
148
145
  :tsig_rr => 'set',
149
146
  :errorstring => 'set',
@@ -157,11 +154,11 @@ class TestResOpt < Test::Unit::TestCase
157
154
  :cdflag => 'set',
158
155
  }
159
156
  res=nil
160
- begin
157
+ begin
161
158
  res = Resolver.new(bad_input)
162
- rescue Exception
159
+ rescue Exception
163
160
  end
164
- if (res)
161
+ if (res)
165
162
  bad_input.keys.each do |key|
166
163
  begin
167
164
  assert_not_equal(res.send(key), 'set', "#{key} is not set")
@@ -169,13 +166,13 @@ class TestResOpt < Test::Unit::TestCase
169
166
  end
170
167
  end
171
168
  end
172
-
169
+
173
170
  res=nil
174
- begin
171
+ begin
175
172
  res = DNS.new(bad_input)
176
- rescue Exception
173
+ rescue Exception
177
174
  end
178
- if (res)
175
+ if (res)
179
176
  bad_input.keys.each do |key|
180
177
  begin
181
178
  assert_not_equal(res.send(key), 'set', "#{key} is not set")
data/test/tc_resolver.rb CHANGED
@@ -1,243 +1,288 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either tmexpress or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
16
- require 'dnsruby'
17
- require 'socket'
18
- require 'test/unit'
19
- include Dnsruby
20
- #@TODO@ We also need a test server so we can control behaviour of server to test
21
- #different aspects of retry strategy.
22
- #Of course, with Ruby's limit of 256 open sockets per process, we'd need to run
23
- #the server in a different Ruby process.
24
-
25
- class TestResolver < Test::Unit::TestCase
26
- include Dnsruby
27
- Thread::abort_on_exception = true
28
- PORT = 42138
29
- @@port = PORT
30
- def setup
31
- Dnsruby::Config.reset
32
- end
33
-
34
- def test_send_message
35
- res = Resolver.new
36
- ret = res.send_message(Message.new("example.com", Types.A))
37
- assert(ret.kind_of?(Message))
38
- end
39
-
40
- def test_send_plain_message
41
- res = Resolver.new
42
- response, error = res.send_plain_message(Message.new("example.com"))
43
- assert(response.kind_of?(Message))
44
- m = Message.new("fgjkhsklfjedfiuaufewriuf.com")
45
- m.header.rd = true
46
- response, error = res.send_plain_message(m)
47
- # print "Response : #{response}\n"
48
- # print "Error : #{error}\n"
49
- assert(response.kind_of?(Message))
50
- assert(error)
51
- assert(error.kind_of?(NXDomain))
52
- end
53
-
54
- def test_query
55
- res = Resolver.new
56
- ret = res.query("example.com")
57
- assert(ret.kind_of?(Message))
58
- end
59
-
60
- def test_query_async
61
- res = Resolver.new
62
- q = Queue.new
63
- res.send_async(Message.new("example.com", Types.A),q,q)
64
- id, ret, error = q.pop
65
- assert_equal(id, q, "Id wrong!")
66
- assert(ret.kind_of?(Message), "Ret wrong!")
67
- assert(error==nil)
68
- end
69
-
70
- def test_query_one_duff_server_one_good
71
- res = Resolver.new({:nameserver => ["localhost", "128.8.10.90"]})
72
- res.retry_delay=1
73
- q = Queue.new
74
- res.send_async(Message.new("example.com", Types.A),q,q)
75
- id, ret, error = q.pop
76
- assert_equal(id, q, "Id wrong!")
77
- assert(ret.kind_of?(Message), "Ret wrong! (#{ret.class}")
78
- assert(error==nil)
79
- end
80
-
81
- # @TODO@ Implement!! But then, why would anyone want to do this?
82
- # def test_many_threaded_clients
83
- # assert(false, "IMPLEMENT!")
84
- # end
85
-
86
- def test_reverse_lookup
87
- m = Message.new("210.251.121.214", Types.PTR)
88
- r = Resolver.new
89
- q=Queue.new
90
- r.send_async(m,q,q)
91
- id,ret, error=q.pop
92
- assert(ret.kind_of?(Message))
93
- no_pointer=true
94
- ret.each_answer do |answer|
95
- if (answer.type==Types.PTR)
96
- no_pointer=false
97
- assert(answer.domainname.to_s=~/ruby-lang/)
98
- end
99
- end
100
- assert(!no_pointer)
101
- end
102
-
103
- # def test_bad_host
104
- # res = Resolver.new({:nameserver => "localhost"})
105
- # res.retry_times=1
106
- # res.retry_delay=0
107
- # res.query_timeout = 1
108
- # q = Queue.new
109
- # res.send_async(Message.new("example.com", Types.A), q, q)
110
- # id, m, err = q.pop
111
- # assert(id==q)
112
- # assert(m == nil)
113
- # assert(err.kind_of?(OtherResolvError) || err.kind_of?(IOError), "OtherResolvError or IOError expected : got #{err.class}")
114
- # end
115
- #
116
- def test_nxdomain
117
- res=Resolver.new
118
- q = Queue.new
119
- res.send_async(Message.new("dklfjhdFHFHDVVUIEWRFDSAJKVCNASDLFJHN.com", Types.A), q, 1)
120
- id, m, err = q.pop
121
- assert(id==1)
122
- assert(m.rcode == RCode.NXDOMAIN)
123
- assert(NXDomain === err)
124
- end
125
-
126
- def test_timeouts
127
- #test timeout behaviour for different retry, retrans, total timeout etc.
128
- #Problem here is that many sockets will be created for queries which time out.
129
- # Run a query which will not respond, and check that the timeout works
130
- if (!RUBY_PLATFORM=~/darwin/)
131
- start=stop=0
132
- retry_times = 3
133
- retry_delay=1
134
- packet_timeout=2
135
- # Work out what time should be, then time it to check
136
- expected = ((2**(retry_times-1))*retry_delay) + packet_timeout
137
- begin
138
- res = Resolver.new({:nameserver => "10.0.1.128"})
139
- # res = Resolver.new({:nameserver => "213.248.199.17"})
140
- res.packet_timeout=packet_timeout
141
- res.retry_times=retry_times
142
- res.retry_delay=retry_delay
143
- start=Time.now
144
- m = res.send_message(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A))
145
- fail
146
- rescue ResolvTimeout
147
- stop=Time.now
148
- time = stop-start
149
- assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
150
- end
151
- end
152
- end
153
-
154
- def test_packet_timeout
155
- res = Resolver.new({:nameserver => []})
156
- # res = Resolver.new({:nameserver => "10.0.1.128"})
157
- start=stop=0
158
- retry_times = retry_delay = packet_timeout= 10
159
- query_timeout=2
160
- begin
161
- res.packet_timeout=packet_timeout
162
- res.retry_times=retry_times
163
- res.retry_delay=retry_delay
164
- res.query_timeout=query_timeout
165
- # Work out what time should be, then time it to check
166
- expected = query_timeout
167
- start=Time.now
168
- m = res.send_message(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A))
169
- fail
170
- rescue ResolvTimeout
171
- stop=Time.now
172
- time = stop-start
173
- assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
174
- end #
175
- end
176
-
177
- def test_queue_packet_timeout
178
- # if (!RUBY_PLATFORM=~/darwin/)
179
- res = Resolver.new({:nameserver => "10.0.1.128"})
180
- # bad = SingleResolver.new("localhost")
181
- res.add_server("localhost")
182
- expected = 2
183
- res.query_timeout=expected
184
- q = Queue.new
185
- start = Time.now
186
- m = res.send_async(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A), q, q)
187
- id,ret,err = q.pop
188
- stop = Time.now
189
- assert(id=q)
190
- assert(ret==nil)
191
- assert(err.class == ResolvTimeout, "#{err.class}, #{err}")
192
- time = stop-start
193
- assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
194
- # end
195
- end
196
-
197
- def test_illegal_src_port
198
- # Also test all singleresolver ports ok
199
- # Try to set src_port to an illegal value - make sure error raised, and port OK
200
- res = Resolver.new
201
- res.port = 56789
202
- tests = [53, 387, 1265, 3210, 48619]
203
- tests.each do |bad_port|
204
- begin
205
- res.src_port = bad_port
206
- fail("bad port #{bad_port}")
207
- rescue
208
- end
209
- end
210
- assert(res.single_resolvers[0].src_port = 56789)
211
- end
212
-
213
- def test_add_src_port
214
- # Try setting and adding port ranges, and invalid ports, and 0.
215
- # Also test all singleresolver ports ok
216
- res = Resolver.new
217
- res.src_port = [56789,56790, 56793]
218
- assert(res.src_port == [56789,56790, 56793])
219
- res.src_port = 56889..56891
220
- assert(res.src_port == [56889,56890,56891])
221
- res.add_src_port(60000..60002)
222
- assert(res.src_port == [56889,56890,56891,60000,60001,60002])
223
- res.add_src_port([60004,60005])
224
- assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005])
225
- res.add_src_port(60006)
226
- assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
227
- # Now test invalid src_ports
228
- tests = [0, 53, [60007, 53], [60008, 0], 55..100]
229
- tests.each do |x|
230
- begin
231
- res.add_src_port(x)
232
- fail()
233
- rescue
234
- end
235
- end
236
- assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
237
- assert(res.single_resolvers[0].src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
238
- end
239
-
240
- def test_eventtype_api
241
- # @TODO@ TEST THE Resolver::EventType interface!
242
- 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 tmexpress or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+ require_relative 'spec_helper'
17
+
18
+ require 'socket'
19
+
20
+ include Dnsruby
21
+ # @TODO@ We also need a test server so we can control behaviour of server to test
22
+ # different aspects of retry strategy.
23
+ # Of course, with Ruby's limit of 256 open sockets per process, we'd need to run
24
+ # the server in a different Ruby process.
25
+
26
+ class TestResolver < Minitest::Test
27
+
28
+ include Dnsruby
29
+
30
+ Thread::abort_on_exception = true
31
+
32
+ GOOD_DOMAIN_NAME = 'example.com'
33
+ BAD_DOMAIN_NAME = 'dnsruby-test-of-bad-domain-name.blah'
34
+
35
+ PORT = 42138
36
+ @@port = PORT
37
+
38
+ def setup
39
+ Dnsruby::Config.reset
40
+ end
41
+
42
+ def assert_valid_response(response)
43
+ assert(response.kind_of?(Message), "Expected response to be a message but was a #{response.class}")
44
+ end
45
+
46
+ def assert_nil_response(response)
47
+ assert(response.nil?, "Expected no response but got a #{response.class}:\n#{response}")
48
+ end
49
+
50
+ def assert_error_is_exception(error, error_class = Exception)
51
+ assert(error.is_a?(error_class), "Expected error to be an #{error_class}, but was a #{error.class}:\n#{error}")
52
+ end
53
+
54
+ def assert_nil_error(error)
55
+ assert(error.nil?, "Expected no error but got a #{error.class}:\n#{error}")
56
+ end
57
+
58
+ def test_send_message
59
+ response = Resolver.new.send_message(Message.new("example.com", Types.A))
60
+ assert_valid_response(response)
61
+ end
62
+
63
+ def test_send_message_bang_noerror
64
+ response, error = Resolver.new.send_message!(Message.new(GOOD_DOMAIN_NAME, Types.A))
65
+ assert_nil_error(error)
66
+ assert_valid_response(response)
67
+ end
68
+
69
+ def test_send_message_bang_error
70
+ message = Message.new(BAD_DOMAIN_NAME, Types.A)
71
+ response, error = Resolver.new.send_message!(message)
72
+ assert_nil_response(response)
73
+ assert_error_is_exception(error)
74
+ end
75
+
76
+ def test_send_plain_message
77
+ resolver = Resolver.new
78
+ response, error = resolver.send_plain_message(Message.new("cnn.com"))
79
+ assert_nil_error(error)
80
+ assert_valid_response(response)
81
+
82
+ m = Message.new(BAD_DOMAIN_NAME)
83
+ m.header.rd = true
84
+ response, error = resolver.send_plain_message(m)
85
+ assert_valid_response(response)
86
+ assert_error_is_exception(error, NXDomain)
87
+ end
88
+
89
+ def test_query
90
+ response = Resolver.new.query("example.com")
91
+ assert_valid_response(response)
92
+ end
93
+
94
+ def test_query_bang_noerror
95
+ response, error = Resolver.new.query!(GOOD_DOMAIN_NAME)
96
+ assert_nil_error(error)
97
+ assert_valid_response(response)
98
+ end
99
+
100
+ def test_query_bang_error
101
+ response, error = Resolver.new.query!(BAD_DOMAIN_NAME)
102
+ assert_nil_response(response)
103
+ assert_error_is_exception(error)
104
+ end
105
+
106
+ def test_query_async
107
+ q = Queue.new
108
+ Resolver.new.send_async(Message.new("example.com", Types.A),q,q)
109
+ id, response, error = q.pop
110
+ assert_equal(id, q, "Id wrong!")
111
+ assert_valid_response(response)
112
+ assert_nil_error(error)
113
+ end
114
+
115
+ def test_query_one_duff_server_one_good
116
+ res = Resolver.new({:nameserver => ["8.8.8.8", "8.8.8.7"]})
117
+ res.retry_delay=1
118
+ q = Queue.new
119
+ res.send_async(Message.new("example.com", Types.A),q,q)
120
+ id, response, error = q.pop
121
+ assert_equal(id, q, "Id wrong!")
122
+ assert_valid_response(response)
123
+ assert_nil_error(error)
124
+ end
125
+
126
+ # @TODO@ Implement!! But then, why would anyone want to do this?
127
+ # def test_many_threaded_clients
128
+ # assert(false, "IMPLEMENT!")
129
+ # end
130
+
131
+ def test_reverse_lookup
132
+ m = Message.new("8.8.8.8", Types.PTR)
133
+ r = Resolver.new
134
+ q=Queue.new
135
+ r.send_async(m,q,q)
136
+ id,ret, error=q.pop
137
+ assert(ret.kind_of?(Message))
138
+ no_pointer=true
139
+ ret.each_answer do |answer|
140
+ if (answer.type==Types.PTR)
141
+ no_pointer=false
142
+ assert(answer.domainname.to_s=~/google-public-dns/)
143
+ end
144
+ end
145
+ assert(!no_pointer)
146
+ end
147
+
148
+ # def test_bad_host
149
+ # res = Resolver.new({:nameserver => "localhost"})
150
+ # res.retry_times=1
151
+ # res.retry_delay=0
152
+ # res.query_timeout = 1
153
+ # q = Queue.new
154
+ # res.send_async(Message.new("example.com", Types.A), q, q)
155
+ # id, m, err = q.pop
156
+ # assert(id==q)
157
+ # assert(m == nil)
158
+ # assert(err.kind_of?(OtherResolvError) || err.kind_of?(IOError), "OtherResolvError or IOError expected : got #{err.class}")
159
+ # end
160
+ #
161
+ def test_nxdomain
162
+ resolver = Resolver.new
163
+ q = Queue.new
164
+ resolver .send_async(Message.new(BAD_DOMAIN_NAME, Types.A), q, 1)
165
+ id, m, error = q.pop
166
+ assert(id==1, "Id should have been 1 but was #{id}")
167
+ assert(m.rcode == RCode.NXDOMAIN, "Expected NXDOMAIN but got #{m.rcode} instead.")
168
+ assert_error_is_exception(error, NXDomain)
169
+ end
170
+
171
+ def test_timeouts
172
+ # test timeout behaviour for different retry, retrans, total timeout etc.
173
+ # Problem here is that many sockets will be created for queries which time out.
174
+ # Run a query which will not respond, and check that the timeout works
175
+ if (!RUBY_PLATFORM=~/darwin/)
176
+ start=stop=0
177
+ retry_times = 3
178
+ retry_delay=1
179
+ packet_timeout=2
180
+ # Work out what time should be, then time it to check
181
+ expected = ((2**(retry_times-1))*retry_delay) + packet_timeout
182
+ begin
183
+ res = Resolver.new({:nameserver => "10.0.1.128"})
184
+ # res = Resolver.new({:nameserver => "213.248.199.17"})
185
+ res.packet_timeout=packet_timeout
186
+ res.retry_times=retry_times
187
+ res.retry_delay=retry_delay
188
+ start=Time.now
189
+ m = res.send_message(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A))
190
+ fail
191
+ rescue ResolvTimeout
192
+ stop=Time.now
193
+ time = stop-start
194
+ assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
195
+ end
196
+ end
197
+ end
198
+
199
+ def test_packet_timeout
200
+ res = Resolver.new({:nameserver => []})
201
+ # res = Resolver.new({:nameserver => "10.0.1.128"})
202
+ start=stop=0
203
+ retry_times = retry_delay = packet_timeout= 10
204
+ query_timeout=2
205
+ begin
206
+ res.packet_timeout=packet_timeout
207
+ res.retry_times=retry_times
208
+ res.retry_delay=retry_delay
209
+ res.query_timeout=query_timeout
210
+ # Work out what time should be, then time it to check
211
+ expected = query_timeout
212
+ start=Time.now
213
+ m = res.send_message(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A))
214
+ fail
215
+ rescue ResolvTimeout
216
+ stop=Time.now
217
+ time = stop-start
218
+ assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
219
+ end #
220
+ end
221
+
222
+ def test_queue_packet_timeout
223
+ # if (!RUBY_PLATFORM=~/darwin/)
224
+ res = Resolver.new({:nameserver => "10.0.1.128"})
225
+ # bad = SingleResolver.new("localhost")
226
+ res.add_server("localhost")
227
+ expected = 2
228
+ res.query_timeout=expected
229
+ q = Queue.new
230
+ start = Time.now
231
+ m = res.send_async(Message.new("a.t.dnsruby.validation-test-servers.nominet.org.uk", Types.A), q, q)
232
+ id,ret,err = q.pop
233
+ stop = Time.now
234
+ assert(id=q)
235
+ assert(ret==nil)
236
+ assert(err.class == ResolvTimeout, "#{err.class}, #{err}")
237
+ time = stop-start
238
+ assert(time <= expected *1.3 && time >= expected *0.9, "Wrong time take, expected #{expected}, took #{time}")
239
+ # end
240
+ end
241
+
242
+ def test_illegal_src_port
243
+ # Also test all singleresolver ports ok
244
+ # Try to set src_port to an illegal value - make sure error raised, and port OK
245
+ res = Resolver.new
246
+ res.port = 56789
247
+ tests = [53, 387, 1265, 3210, 48619]
248
+ tests.each do |bad_port|
249
+ begin
250
+ res.src_port = bad_port
251
+ fail("bad port #{bad_port}")
252
+ rescue
253
+ end
254
+ end
255
+ assert(res.single_resolvers[0].src_port = 56789)
256
+ end
257
+
258
+ def test_add_src_port
259
+ # Try setting and adding port ranges, and invalid ports, and 0.
260
+ # Also test all singleresolver ports ok
261
+ res = Resolver.new
262
+ res.src_port = [56789,56790, 56793]
263
+ assert(res.src_port == [56789,56790, 56793])
264
+ res.src_port = 56889..56891
265
+ assert(res.src_port == [56889,56890,56891])
266
+ res.add_src_port(60000..60002)
267
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002])
268
+ res.add_src_port([60004,60005])
269
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005])
270
+ res.add_src_port(60006)
271
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
272
+ # Now test invalid src_ports
273
+ tests = [0, 53, [60007, 53], [60008, 0], 55..100]
274
+ tests.each do |x|
275
+ begin
276
+ res.add_src_port(x)
277
+ fail()
278
+ rescue
279
+ end
280
+ end
281
+ assert(res.src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
282
+ assert(res.single_resolvers[0].src_port == [56889,56890,56891,60000,60001,60002,60004,60005,60006])
283
+ end
284
+
285
+ def test_eventtype_api
286
+ # @TODO@ TEST THE Resolver::EventType interface!
287
+ end
243
288
  end