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_update.rb CHANGED
@@ -1,37 +1,34 @@
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 TestUpdate < Test::Unit::TestCase
20
+ class TestUpdate < Minitest::Test
24
21
  def is_empty(string)
25
22
  return true if string == nil || string.length == 0
26
-
23
+
27
24
  return (string == "; no data" || string == "; rdlength = 0");
28
25
  end
29
-
26
+
30
27
  def test_update
31
- #------------------------------------------------------------------------------
32
- # Canned data.
33
- #------------------------------------------------------------------------------
34
-
28
+ # ------------------------------------------------------------------------------
29
+ # Canned data.
30
+ # ------------------------------------------------------------------------------
31
+
35
32
  zone = "example.com";
36
33
  name = "foo.example.com";
37
34
  klass = Classes.CLASS32;
@@ -40,155 +37,155 @@ class TestUpdate < Test::Unit::TestCase
40
37
  ttl = 43200;
41
38
  rdata = "10.1.2.3";
42
39
  rr = nil;
43
-
44
- #------------------------------------------------------------------------------
45
- # Packet creation.
46
- #------------------------------------------------------------------------------
47
-
40
+
41
+ # ------------------------------------------------------------------------------
42
+ # Packet creation.
43
+ # ------------------------------------------------------------------------------
44
+
48
45
  update = Dnsruby::Update.new(zone, klass);
49
46
  z = (update.zone)[0];
50
-
47
+
51
48
  assert(update, 'new() returned packet'); #2
52
- assert_equal(update.header.opcode, OpCode.UPDATE, 'header opcode correct'); #3
49
+ assert_equal(update.header.opcode, OpCode.UPDATE, 'header opcode correct'); #3
53
50
  assert_equal(z.zname.to_s, zone, 'zname correct'); #4
54
51
  assert_equal(z.zclass.to_s, klass.to_s, 'zclass correct'); #5
55
- assert_equal(z.ztype, Types.SOA, 'ztype correct'); #6
56
-
57
- #------------------------------------------------------------------------------
58
- # RRset exists (value-independent).
59
- #------------------------------------------------------------------------------
60
-
52
+ assert_equal(z.ztype, Types.SOA, 'ztype correct'); #6
53
+
54
+ # ------------------------------------------------------------------------------
55
+ # RRset exists (value-independent).
56
+ # ------------------------------------------------------------------------------
57
+
61
58
  rr = update.present(name, type);
62
-
59
+
63
60
  assert(rr, 'yxrrset() returned RR'); #7
64
61
  assert_equal(name, rr.name.to_s, 'yxrrset - right name'); #8
65
62
  assert_equal(0, rr.ttl, 'yxrrset - right TTL'); #9
66
63
  assert_equal('ANY', rr.klass.string, 'yxrrset - right class'); #10
67
64
  assert_equal(type, rr.type, 'yxrrset - right type'); #11
68
65
  assert(is_empty(rr.rdata), "yxrrset - data empty (#{rr.rdata})"); #12
69
-
66
+
70
67
  rr = nil
71
-
72
- #------------------------------------------------------------------------------
73
- # RRset exists (value-dependent).
74
- #------------------------------------------------------------------------------
75
-
68
+
69
+ # ------------------------------------------------------------------------------
70
+ # RRset exists (value-dependent).
71
+ # ------------------------------------------------------------------------------
72
+
76
73
  rr = update.present(name, type, rdata, klass);
77
-
74
+
78
75
  assert(rr, 'yxrrset() returned RR'); #13
79
76
  assert_equal(name, rr.name.to_s, 'yxrrset - right name'); #14
80
77
  assert_equal(0, rr.ttl, 'yxrrset - right TTL'); #15
81
78
  assert_equal(klass, rr.klass.string, 'yxrrset - right class'); #16
82
79
  assert_equal(type, rr.type, 'yxrrset - right type'); #17
83
80
  assert_equal(rdata, rr.rdata, 'yxrrset - right data'); #18
84
-
81
+
85
82
  rr=nil
86
-
87
- #------------------------------------------------------------------------------
88
- # RRset does not exist.
89
- #------------------------------------------------------------------------------
90
-
83
+
84
+ # ------------------------------------------------------------------------------
85
+ # RRset does not exist.
86
+ # ------------------------------------------------------------------------------
87
+
91
88
  rr = update.absent(name, type);
92
-
89
+
93
90
  assert(rr, 'nxrrset() returned RR'); #19
94
91
  assert_equal(name, rr.name.to_s, 'nxrrset - right name'); #20
95
92
  assert_equal(0, rr.ttl, 'nxrrset - right ttl'); #21
96
93
  assert_equal('NONE', rr.klass.string, 'nxrrset - right class'); #22
97
94
  assert_equal(type, rr.type, 'nxrrset - right type'); #23
98
95
  assert(is_empty(rr.rdata), 'nxrrset - data empty'); #24
99
-
96
+
100
97
  rr = nil
101
-
102
- #------------------------------------------------------------------------------
103
- # Name is in use.
104
- #------------------------------------------------------------------------------
105
-
98
+
99
+ # ------------------------------------------------------------------------------
100
+ # Name is in use.
101
+ # ------------------------------------------------------------------------------
102
+
106
103
  rr = update.present(name);
107
-
104
+
108
105
  assert(rr, 'yxdomain() returned RR'); #25
109
106
  assert_equal(rr.name.to_s, name, 'yxdomain - right name'); #26
110
107
  assert_equal(rr.ttl, 0, 'yxdomain - right ttl'); #27
111
108
  assert_equal(rr.klass.string, 'ANY', 'yxdomain - right class'); #28
112
109
  assert_equal(rr.type.string, 'ANY', 'yxdomain - right type'); #29
113
110
  assert(is_empty(rr.rdata), 'yxdomain - data empty'); #30
114
-
111
+
115
112
  rr = nil
116
-
117
- #------------------------------------------------------------------------------
118
- # Name is not in use. (No Class)
119
- #------------------------------------------------------------------------------
120
-
113
+
114
+ # ------------------------------------------------------------------------------
115
+ # Name is not in use. (No Class)
116
+ # ------------------------------------------------------------------------------
117
+
121
118
  rr = update.absent(name);
122
-
119
+
123
120
  assert(rr, 'nxdomain() returned RR'); #31
124
121
  assert_equal(rr.name.to_s, name, 'nxdomain - right name'); #32
125
122
  assert_equal(rr.ttl, 0, 'nxdomain - right ttl'); #33
126
123
  assert_equal(rr.klass.string, 'NONE', 'nxdomain - right class'); #34
127
124
  assert_equal(rr.type.string, 'ANY', 'nxdomain - right type'); #35
128
125
  assert(is_empty(rr.rdata), 'nxdomain - data empty'); #36
129
-
126
+
130
127
  rr = nil
131
-
132
-
133
-
134
- #------------------------------------------------------------------------------
135
- # Add to an RRset.
136
- #------------------------------------------------------------------------------
137
-
128
+
129
+
130
+
131
+ # ------------------------------------------------------------------------------
132
+ # Add to an RRset.
133
+ # ------------------------------------------------------------------------------
134
+
138
135
  rr = update.add(name, type, ttl, rdata);
139
-
136
+
140
137
  assert(rr, 'rr_add() returned RR'); #37
141
138
  assert_equal(rr.name.to_s, name, 'rr_add - right name'); #38
142
139
  assert_equal(rr.ttl, ttl, 'rr_add - right ttl'); #39
143
140
  assert_equal(rr.klass, klass, 'rr_add - right class'); #40
144
141
  assert_equal(rr.type, type, 'rr_add - right type'); #41
145
142
  assert_equal(rr.rdata, rdata, 'rr_add - right data'); #42
146
-
143
+
147
144
  rr = nil
148
-
149
- #------------------------------------------------------------------------------
150
- # Delete an RRset.
151
- #------------------------------------------------------------------------------
152
-
145
+
146
+ # ------------------------------------------------------------------------------
147
+ # Delete an RRset.
148
+ # ------------------------------------------------------------------------------
149
+
153
150
  rr = update.delete(name, type);
154
-
151
+
155
152
  assert(rr, 'rr_del() returned RR'); #43
156
153
  assert_equal(name, rr.name.to_s, 'rr_del - right name'); #44
157
154
  assert_equal(0, rr.ttl, 'rr_del - right ttl'); #45
158
155
  assert_equal('ANY', rr.klass.string, 'rr_del - right class'); #46
159
156
  assert_equal(type, rr.type, 'rr_del - right type'); #47
160
157
  assert(is_empty(rr.rdata), 'rr_del - data empty'); #48
161
-
158
+
162
159
  rr = nil
163
-
164
- #------------------------------------------------------------------------------
165
- # Delete All RRsets From A Name.
166
- #------------------------------------------------------------------------------
167
-
160
+
161
+ # ------------------------------------------------------------------------------
162
+ # Delete All RRsets From A Name.
163
+ # ------------------------------------------------------------------------------
164
+
168
165
  rr = update.delete(name);
169
-
166
+
170
167
  assert(rr, 'rr_del() returned RR'); #49
171
168
  assert_equal(name, rr.name.to_s, 'rr_del - right name'); #50
172
169
  assert_equal(0, rr.ttl, 'rr_del - right ttl'); #51
173
170
  assert_equal(Classes.ANY, rr.klass, 'rr_del - right class'); #52
174
171
  assert_equal(Classes.ANY, rr.type, 'rr_del - right type'); #53
175
172
  assert(is_empty(rr.rdata), 'rr_del - data empty'); #54
176
-
173
+
177
174
  rr = nil
178
-
179
- #------------------------------------------------------------------------------
180
- # Delete An RR From An RRset.
181
- #------------------------------------------------------------------------------
182
-
175
+
176
+ # ------------------------------------------------------------------------------
177
+ # Delete An RR From An RRset.
178
+ # ------------------------------------------------------------------------------
179
+
183
180
  rr = update.delete(name, type, rdata);
184
-
181
+
185
182
  assert(rr, 'rr_del() returned RR'); #55
186
183
  assert_equal(name, rr.name.to_s, 'rr_del - right name'); #56
187
184
  assert_equal(0, rr.ttl, 'rr_del - right ttl'); #57
188
185
  assert_equal('NONE', rr.klass.string, 'rr_del - right class'); #58
189
186
  assert_equal(type, rr.type, 'rr_del - right type'); #59
190
187
  assert_equal(rdata, rr.rdata, 'rr_del - right data'); #60
191
-
188
+
192
189
  rr = nil
193
190
 
194
191
  data = update.encode
@@ -196,18 +193,18 @@ class TestUpdate < Test::Unit::TestCase
196
193
  assert(header.opcode == OpCode.Update)
197
194
  new_update = Message.decode(data)
198
195
  assert(new_update.header.opcode == OpCode.Update)
199
-
200
- #------------------------------------------------------------------------------
201
- # Make sure RRs in an update packet have the same class as the zone, unless
202
- # the class is NONE or ANY.
203
- #------------------------------------------------------------------------------
204
-
196
+
197
+ # ------------------------------------------------------------------------------
198
+ # Make sure RRs in an update packet have the same class as the zone, unless
199
+ # the class is NONE or ANY.
200
+ # ------------------------------------------------------------------------------
201
+
205
202
  update = Dnsruby::Update.new(zone, klass);
206
203
  assert(update, 'packet created'); #61
207
-
208
-
204
+
205
+
209
206
  update.present(name, type, rdata);
210
-
207
+
211
208
  update.present(name, type, rdata);
212
209
 
213
210
  update.present(name, type);
@@ -215,7 +212,7 @@ class TestUpdate < Test::Unit::TestCase
215
212
  update.absent(name, type);
216
213
 
217
214
  pre = update.pre;
218
-
215
+
219
216
  assert_equal(3, pre.size, 'pushed inserted correctly'); #62
220
217
  assert_equal(klass, pre[0].klass.string, 'first class right'); #63
221
218
  assert_equal(Classes.ANY, pre[1].klass, 'third class right'); #65
data/test/tc_validator.rb CHANGED
@@ -1,24 +1,24 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
1
+ # --
2
+ # Copyright 2007 Nominet UK
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
8
  # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+
17
+ require_relative 'spec_helper'
16
18
 
17
- require 'test/unit'
18
- require 'dnsruby'
19
19
  include Dnsruby
20
20
 
21
- class TestValidator < Test::Unit::TestCase
21
+ class TestValidator < Minitest::Test
22
22
  def test_validation
23
23
  # Dnsruby::TheLog.level = Logger::DEBUG
24
24
  Dnsruby::Dnssec.clear_trusted_keys
@@ -41,11 +41,11 @@ class TestValidator < Test::Unit::TestCase
41
41
  ret = Dnsruby::Dnssec.validate(r)
42
42
  assert(ret, "Dnssec validation failed")
43
43
 
44
- # @TODO@ Test other validation policies!!
44
+ # @TODO@ Test other validation policies!!
45
45
  end
46
46
 
47
47
  def test_resolver_cd_validation_fails
48
- # Should be able to check Nominet test-zone here - no keys point to it
48
+ # Should be able to check Nominet test-zone here - no keys point to it
49
49
  res = Resolver.new
50
50
  res.dnssec=true
51
51
  r = res.query("uk-dnssec.nic.uk", Dnsruby::Types.A)
@@ -53,20 +53,20 @@ class TestValidator < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  def test_eventtype_api
56
- # @TODO@ TEST THE Resolver::EventType interface!
56
+ # @TODO@ TEST THE Resolver::EventType interface!
57
57
  print "Test EventType API!\n"
58
58
  end
59
59
 
60
60
  def test_config_api
61
- # @TODO@ Test the different configuration options for the validator,
62
- # and their defaults
63
- #
64
- # Should be able to set :
65
- # o Whether or not validation happens
66
- # o The async API queue tuples etc.
67
- # o Whether to use authoritative nameservers for validation
68
- # o Whether to use authoritative nameservers generally
69
- #
61
+ # @TODO@ Test the different configuration options for the validator,
62
+ # and their defaults
63
+ #
64
+ # Should be able to set :
65
+ # o Whether or not validation happens
66
+ # o The async API queue tuples etc.
67
+ # o Whether to use authoritative nameservers for validation
68
+ # o Whether to use authoritative nameservers generally
69
+ #
70
70
  print "Test validation configuration options!\n"
71
71
  end
72
72
 
data/test/tc_verifier.rb CHANGED
@@ -1,26 +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
- #
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 VerifierTest < Test::Unit::TestCase
19
+ class VerifierTest < Minitest::Test
21
20
 
22
21
  def test_sha2
23
- # Check if OpenSSL supports SHA2
22
+ # Check if OpenSSL supports SHA2
24
23
  have_sha2 = false
25
24
  begin
26
25
  OpenSSL::Digest::SHA256.new
@@ -28,7 +27,7 @@ class VerifierTest < Test::Unit::TestCase
28
27
  rescue Exception
29
28
  end
30
29
  if (have_sha2)
31
- # print "OpenSSL supports SHA2\n"
30
+ # print "OpenSSL supports SHA2\n"
32
31
  do_test_sha256
33
32
  do_test_sha512
34
33
  do_test_nsec
@@ -72,13 +71,13 @@ class VerifierTest < Test::Unit::TestCase
72
71
  end
73
72
 
74
73
  def test_se_query
75
- # Run some queries on the .se zone
74
+ # Run some queries on the .se zone
76
75
  Dnsruby::Dnssec.clear_trusted_keys
77
76
  Dnsruby::Dnssec.clear_trust_anchors
78
77
  res = Dnsruby::Resolver.new(Dnsruby::Resolv.getaddress("a.ns.se"))
79
78
  res.dnssec = true
80
79
  r = res.query("se", Dnsruby::Types.ANY)
81
- # See comment below
80
+ # See comment below
82
81
  Dnsruby::Dnssec.anchor_verifier.add_trusted_key(r.answer.rrset("se", 'DNSKEY'))
83
82
  nss = r.answer.rrset("se", 'NS')
84
83
  ret = Dnsruby::Dnssec.verify_rrset(nss)
@@ -91,10 +90,10 @@ class VerifierTest < Test::Unit::TestCase
91
90
  res = Dnsruby::Resolver.new(Dnsruby::Resolv.getaddress("a.ns.se"))
92
91
  res.udp_size = 5000
93
92
  r = res.query("se", Dnsruby::Types.DNSKEY)
94
- # This shouldn't be in the code - but the key is rotated by the .se registry
95
- # so we can't keep up with it in the test code.
96
- # Oh, for a signed root...
97
- # print "Adding keys : #{r.answer.rrset("se", 'DNSKEY')}\n"
93
+ # This shouldn't be in the code - but the key is rotated by the .se registry
94
+ # so we can't keep up with it in the test code.
95
+ # Oh, for a signed root...
96
+ # print "Adding keys : #{r.answer.rrset("se", 'DNSKEY')}\n"
98
97
  Dnsruby::Dnssec.anchor_verifier.add_trusted_key(r.answer.rrset("se", 'DNSKEY'))
99
98
  ret = Dnsruby::Dnssec.verify(r)
100
99
  assert(ret, "Dnssec message verification failed : #{ret}")
@@ -105,13 +104,13 @@ class VerifierTest < Test::Unit::TestCase
105
104
  Dnsruby::Dnssec.clear_trust_anchors
106
105
  res = Dnsruby::Resolver.new("a.ns.se")
107
106
  r = res.query("se", Dnsruby::Types.ANY)
108
- # Haven't configured key for this, so should fail
107
+ # Haven't configured key for this, so should fail
109
108
  begin
110
109
  ret = Dnsruby::Dnssec.verify(r)
111
110
  fail("Message shouldn't have verified")
112
111
  rescue (Dnsruby::VerifyError)
113
112
  end
114
- # assert(!ret, "Dnssec message verification failed")
113
+ # assert(!ret, "Dnssec message verification failed")
115
114
  end
116
115
 
117
116
  def test_trusted_key
@@ -129,7 +128,7 @@ class VerifierTest < Test::Unit::TestCase
129
128
  ret = Dnsruby::Dnssec.verify(r)
130
129
  fail("Dnssec trusted key message verification should have failed with bad key")
131
130
  rescue (Dnsruby::VerifyError)
132
- # assert(!ret, "Dnssec trusted key message verification should have failed with bad key")
131
+ # assert(!ret, "Dnssec trusted key message verification should have failed with bad key")
133
132
  end
134
133
  trusted_key = Dnsruby::RR.create({:name => "uk-dnssec.nic.uk.",
135
134
  :type => Dnsruby::Types.DNSKEY,
@@ -142,14 +141,14 @@ class VerifierTest < Test::Unit::TestCase
142
141
  ret = Dnsruby::Dnssec.verify(r)
143
142
  assert(ret, "Dnssec trusted key message verification failed")
144
143
 
145
- # # Check that keys have been added to trusted key cache
146
- # ret = Dnsruby::Dnssec.verify(r)
147
- # assert(ret, "Dnssec trusted key cache failed")
144
+ # # Check that keys have been added to trusted key cache
145
+ # ret = Dnsruby::Dnssec.verify(r)
146
+ # assert(ret, "Dnssec trusted key cache failed")
148
147
  end
149
148
 
150
149
  def test_expired_keys
151
- # Add some keys with an expiration of 1 second.
152
- # Then wait a second or two, and check they are not available any more.
150
+ # Add some keys with an expiration of 1 second.
151
+ # Then wait a second or two, and check they are not available any more.
153
152
  Dnsruby::Dnssec.clear_trusted_keys
154
153
  Dnsruby::Dnssec.clear_trust_anchors
155
154
  assert(Dnsruby::Dnssec.anchor_verifier.trusted_keys.length==0)
@@ -164,30 +163,30 @@ class VerifierTest < Test::Unit::TestCase
164
163
  end
165
164
 
166
165
  def test_tcp
167
- #These queries work:
168
- # dig @194.0.1.13 isoc.lu dnskey
169
- # dig @194.0.1.13 isoc.lu dnskey +dnssec
170
- # dig @194.0.1.13 isoc.lu dnskey +tcp
166
+ # These queries work:
167
+ # dig @194.0.1.13 isoc.lu dnskey
168
+ # dig @194.0.1.13 isoc.lu dnskey +dnssec
169
+ # dig @194.0.1.13 isoc.lu dnskey +tcp
171
170
 
172
- #This one does not
173
- #
174
- # dig @194.0.1.13 isoc.lu dnskey +dnssec +tcp
171
+ # This one does not
172
+ #
173
+ # dig @194.0.1.13 isoc.lu dnskey +dnssec +tcp
175
174
  r = Dnsruby::SingleResolver.new()# "194.0.1.13")
176
175
  r.dnssec = true
177
176
  r.use_tcp = true
178
177
  ret = r.query("isoc.lu", Dnsruby::Types.DNSKEY)
179
- # print ret.to_s+"\n"
178
+ # print ret.to_s+"\n"
180
179
 
181
180
  r = Dnsruby::SingleResolver.new("194.0.1.13")
182
181
  r.dnssec = true
183
- #r.use_tcp = true
182
+ # r.use_tcp = true
184
183
  ret = r.query("isoc.lu", Dnsruby::Types.DNSKEY)
185
- # print ret.to_s+"\n"
184
+ # print ret.to_s+"\n"
186
185
 
187
186
  r.use_tcp = true
188
187
  r.dnssec = false
189
188
  ret = r.query("isoc.lu", Dnsruby::Types.DNSKEY)
190
- # print ret.to_s+"\n"
189
+ # print ret.to_s+"\n"
191
190
 
192
191
  r.dnssec = true
193
192
  begin
@@ -214,7 +213,7 @@ class VerifierTest < Test::Unit::TestCase
214
213
  end
215
214
 
216
215
  def test_dsa
217
- # Let's check sources.org for DSA keys
216
+ # Let's check sources.org for DSA keys
218
217
  Dnsruby::Dnssec.clear_trusted_keys
219
218
  Dnsruby::Dnssec.clear_trust_anchors
220
219
  res = Dnsruby::Recursor.new()
@@ -228,11 +227,11 @@ class VerifierTest < Test::Unit::TestCase
228
227
  end
229
228
  }
230
229
  assert(dsa)
231
- # Now do something with it
230
+ # Now do something with it
232
231
 
233
232
  response = res.query("sources.org", Dnsruby::Types.ANY)
234
233
  verified = 0
235
- # response.each_section {|sec|
234
+ # response.each_section {|sec|
236
235
  response.answer.rrsets.each {|rs|
237
236
  if (rs.sigs()[0].algorithm == Dnsruby::Algorithms.DSA &&
238
237
  rs.sigs()[0].key_tag == dsa.key_tag)
@@ -241,7 +240,7 @@ class VerifierTest < Test::Unit::TestCase
241
240
  verified+=1
242
241
  end
243
242
  }
244
- # }
243
+ # }
245
244
  assert(verified > 0)
246
245
  end
247
246
 
@@ -325,42 +324,42 @@ class VerifierTest < Test::Unit::TestCase
325
324
  # zone2 = reader.process_file("cacert.signed.txt")
326
325
  # assert(zone[1].to_s.index("DAQAB\""))
327
326
  # assert(zone2[1].to_s.index("DAQAB\""))
328
- #
327
+ #
329
328
  # assert(zone[1].to_s == zone2[1].to_s)
330
329
  # end
331
- #
332
- # def test_txt_from_zone
333
- # reader = Dnsruby::ZoneReader.new("all.rr.org.")
334
- # zone = reader.process_file("zone.txt")
335
- # rrset = Dnsruby::RRSet.new
336
- # key_rrset = Dnsruby::RRSet.new
337
- # zone.each {|rr|
338
- # if ( (rr.type == Dnsruby::Types.TXT) || ((rr.type == Dnsruby::Types.RRSIG) && (rr.type_covered == Dnsruby::Types.TXT)))
339
- # rrset.add(rr)
340
- # end
341
- # if (rr.type == Dnsruby::Types.DNSKEY)
342
- # key_rrset.add(rr)
343
- # end
344
- # }
345
- # verifier = Dnsruby::SingleVerifier.new(Dnsruby::SingleVerifier::VerifierType::ANCHOR)
346
- # verifier.verify_rrset(rrset, key_rrset)
347
- # end
330
+ #
331
+ # def test_txt_from_zone
332
+ # reader = Dnsruby::ZoneReader.new("all.rr.org.")
333
+ # zone = reader.process_file("zone.txt")
334
+ # rrset = Dnsruby::RRSet.new
335
+ # key_rrset = Dnsruby::RRSet.new
336
+ # zone.each {|rr|
337
+ # if ( (rr.type == Dnsruby::Types.TXT) || ((rr.type == Dnsruby::Types.RRSIG) && (rr.type_covered == Dnsruby::Types.TXT)))
338
+ # rrset.add(rr)
339
+ # end
340
+ # if (rr.type == Dnsruby::Types.DNSKEY)
341
+ # key_rrset.add(rr)
342
+ # end
343
+ # }
344
+ # verifier = Dnsruby::SingleVerifier.new(Dnsruby::SingleVerifier::VerifierType::ANCHOR)
345
+ # verifier.verify_rrset(rrset, key_rrset)
346
+ # end
348
347
 
349
- # def test_naptr_from_zone
350
- # reader = Dnsruby::ZoneReader.new("all.rr.org.")
351
- # zone = reader.process_file("zone.txt")
352
- # rrset = Dnsruby::RRSet.new
353
- # key_rrset = Dnsruby::RRSet.new
354
- # zone.each {|rr|
355
- # if ((rr.type == Dnsruby::Types.NAPTR) || ((rr.type == Dnsruby::Types.RRSIG) && (rr.type_covered == Dnsruby::Types.NAPTR)))
356
- # rrset.add(rr)
357
- # end
358
- # if (rr.type == Dnsruby::Types.DNSKEY)
359
- # key_rrset.add(rr)
360
- # end
361
- # }
362
- # verifier = Dnsruby::SingleVerifier.new(Dnsruby::SingleVerifier::VerifierType::ANCHOR)
363
- # verifier.verify_rrset(rrset, key_rrset)
364
- # end
348
+ # def test_naptr_from_zone
349
+ # reader = Dnsruby::ZoneReader.new("all.rr.org.")
350
+ # zone = reader.process_file("zone.txt")
351
+ # rrset = Dnsruby::RRSet.new
352
+ # key_rrset = Dnsruby::RRSet.new
353
+ # zone.each {|rr|
354
+ # if ((rr.type == Dnsruby::Types.NAPTR) || ((rr.type == Dnsruby::Types.RRSIG) && (rr.type_covered == Dnsruby::Types.NAPTR)))
355
+ # rrset.add(rr)
356
+ # end
357
+ # if (rr.type == Dnsruby::Types.DNSKEY)
358
+ # key_rrset.add(rr)
359
+ # end
360
+ # }
361
+ # verifier = Dnsruby::SingleVerifier.new(Dnsruby::SingleVerifier::VerifierType::ANCHOR)
362
+ # verifier.verify_rrset(rrset, key_rrset)
363
+ # end
365
364
  end
366
365