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
@@ -0,0 +1,87 @@
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 TestMessage < Minitest::Test
20
+
21
+ include Dnsruby
22
+
23
+ # Creates and returns sample message:
24
+ #
25
+ # ;; QUESTION SECTION (1 record)
26
+ # ;; cnn.com. IN A
27
+ # ;; Security Level : UNCHECKED
28
+ # ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7195
29
+ # ;; flags: ; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
30
+ def sample_message
31
+ Message.new('cnn.com', 'A')
32
+ end
33
+
34
+ def test_question_section_formatted_ok
35
+ multiline_regex = /QUESTION SECTION.+record.+cnn.com.\s+IN\s+A/m
36
+ assert multiline_regex.match(sample_message.to_s)
37
+ end
38
+
39
+ def test_has_security_level_line
40
+ line_regex = /^;; Security Level : .+/
41
+ assert line_regex.match(sample_message.to_s)
42
+ end
43
+
44
+ def test_has_flags_and_section_count
45
+ line_regex = /^;; flags:.+QUERY: \d+, ANSWER: \d+, AUTHORITY: \d+, ADDITIONAL: \d+/
46
+ assert line_regex.match(sample_message.to_s)
47
+ end
48
+
49
+ def test_rd_flag_displayed_when_true
50
+ message = sample_message
51
+ message.header.instance_variable_set(:@rd, true)
52
+ assert /;; flags(.+)rd/.match(message.to_s), message
53
+ end
54
+
55
+ def test_header_line_contains_opcode_and_status_and_id
56
+ message = sample_message
57
+ header_line = message.to_s.split("\n").grep(/->>HEADER<<-/).first
58
+ line_regex = /->>HEADER<<- opcode: .+, status: .+, id: \d+/
59
+ assert line_regex.match(header_line)
60
+ end
61
+
62
+ def test_getopt
63
+ message = sample_message
64
+ assert message.get_opt.nil?
65
+
66
+ # Add an OPT record
67
+ opt = RR::OPT.new(4096, 32768)
68
+ message.additional << opt
69
+
70
+ opt = message.get_opt
71
+ assert opt.is_a?(Dnsruby::RR::OPT),
72
+ "Expected get_opt to return a Dnsruby::RR::OPT, but it returned a #{opt.class}"
73
+ end
74
+
75
+ def test_2eq
76
+ test = ->(msg1, msg2, expected_result) do
77
+ assert (msg1 == msg2) == expected_result
78
+ end
79
+ msg_a = sample_message
80
+ msg_b = sample_message; msg_b.header.rd = (! msg_b.header.rd)
81
+ test.(msg_a, msg_a, true)
82
+ test.(msg_a, msg_b, false)
83
+ test.(msg_a, msg_a.to_s, false)
84
+ test.(msg_a, nil, false)
85
+ # TODO: Add more tests.
86
+ end
87
+ end
data/test/tc_misc.rb CHANGED
@@ -1,99 +1,95 @@
1
- #--
2
- #Copyright 2007 Nominet UK
3
- #
4
- #Licensed under the Apache License, Version 2.0 (the "License");
5
- #you may not use this file except in compliance with the License.
6
- #You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- #Unless required by applicable law or agreed to in writing, software
11
- #distributed under the License is distributed on an "AS IS" BASIS,
12
- #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- #See the License for the specific language governing permissions and
14
- #limitations under the License.
15
- #++
16
- begin
17
- require 'rubygems'
18
- rescue LoadError
19
- end
20
- require 'test/unit'
21
- require 'dnsruby'
22
- class TestMisc < 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 TestMisc < Minitest::Test
23
20
  def test_wildcard
24
- # test to make sure that wildcarding works.
25
- #
21
+ # test to make sure that wildcarding works.
22
+ #
26
23
  rr = Dnsruby::RR.create('*.t.dnsruby.validation-test-servers.nominet.org.uk 60 IN A 10.0.0.1')
27
-
24
+
28
25
  assert(rr, 'RR got made')
29
-
26
+
30
27
  assert_equal('*.t.dnsruby.validation-test-servers.nominet.org.uk', rr.name.to_s, 'Name is correct' )
31
28
  assert_equal(60, rr.ttl, 'TTL is correct' )
32
29
  assert_equal(Dnsruby::Classes.IN, rr.klass, 'CLASS is correct' )
33
30
  assert_equal(Dnsruby::Types.A, rr.type, 'TYPE is correct' )
34
31
  assert_equal('10.0.0.1', rr.address.to_s, 'Address is correct')
35
32
  end
36
-
33
+
37
34
  def test_misc
38
-
39
- #
40
- # Make sure the underscore in SRV hostnames work.
41
- #
35
+
36
+ #
37
+ # Make sure the underscore in SRV hostnames work.
38
+ #
42
39
  srv = Dnsruby::RR.create('_rvp._tcp.t.dnsruby.validation-test-servers.nominet.org.uk. 60 IN SRV 0 0 80 im.bastardsinc.biz')
43
-
44
- assert(!$@, 'No errors')
45
- assert(srv, 'SRV got made')
46
-
47
-
48
- #~ # Test that the 5.005 Use of uninitialized value at
49
- #~ # /usr/local/lib/perl5/site_perl/5.005/Net/DNS/RR.pm line 639. bug is gone
40
+
41
+ assert(srv, 'SRV not created successfully')
42
+
43
+
44
+ # ~ # Test that the 5.005 Use of uninitialized value at
45
+ # ~ # /usr/local/lib/perl5/site_perl/5.005/Net/DNS/RR.pm line 639. bug is gone
50
46
  rr = Dnsruby::RR.create('mx.t.dnsruby.validation-test-servers.nominet.org.uk 60 IN MX 10 a.t.dnsruby.validation-test-servers.nominet.org.uk')
51
47
  assert(rr, 'RR created')
52
-
48
+
53
49
  assert_equal(rr.preference, 10, 'Preference works')
54
-
55
-
56
-
50
+
51
+
52
+
57
53
  mx = Dnsruby::RR.create('mx.t.dnsruby.validation-test-servers.nominet.org.uk 60 IN MX 0 mail.dnsruby.validation-test-servers.nominet.org.uk')
58
-
54
+
59
55
  assert(mx.to_s =~ /0 mail.dnsruby.validation-test-servers.nominet.org.uk/) # was 'like'
60
56
  assert_equal(mx.preference, 0)
61
57
  assert_equal(mx.exchange.to_s, 'mail.dnsruby.validation-test-servers.nominet.org.uk')
62
-
58
+
63
59
  srv = Dnsruby::RR.create('srv.t.dnsruby.validation-test-servers.nominet.org.uk 60 IN SRV 0 2 3 target.dnsruby.validation-test-servers.nominet.org.uk')
64
-
60
+
65
61
  # # @todo@ Absolute name issues
66
62
  # assert(srv.inspect =~ /0 2 3 target.dnsruby.validation-test-servers.nominet.org.uk\./)
67
63
  # assert_equal(srv.rdatastr, '0 2 3 target.dnsruby.validation-test-servers.nominet.org.uk.')
68
-
69
-
70
-
64
+
65
+
66
+
71
67
  end
72
-
68
+
73
69
  def test_TXT_RR
74
-
75
- #
76
- #
77
- # Below are some thests that have to do with TXT RRs
78
- #
79
- #
80
-
81
-
82
- # QUESTION SECTION:
83
- #txt2.t.net-dns.org. IN TXT
84
-
85
- # ANSWER SECTION:
86
- #txt2.t.net-dns.org. 60 IN TXT "Net-DNS\ complicated $tuff" "sort of \" text\ and binary \000 data"
87
-
88
- # AUTHORITY SECTION:
89
- #net-dns.org. 3600 IN NS ns1.net-dns.org.
90
- #net-dns.org. 3600 IN NS ns.ripe.net.
91
- #net-dns.org. 3600 IN NS ns.hactrn.net.
92
-
93
- # ADDITIONAL SECTION:
94
- #ns1.net-dns.org. 3600 IN A 193.0.4.49
95
- #ns1.net-dns.org. 3600 IN AAAA
96
-
70
+
71
+ #
72
+ #
73
+ # Below are some thests that have to do with TXT RRs
74
+ #
75
+ #
76
+
77
+
78
+ # QUESTION SECTION:
79
+ # txt2.t.net-dns.org. IN TXT
80
+
81
+ # ANSWER SECTION:
82
+ # txt2.t.net-dns.org. 60 IN TXT "Net-DNS\ complicated $tuff" "sort of \" text\ and binary \000 data"
83
+
84
+ # AUTHORITY SECTION:
85
+ # net-dns.org. 3600 IN NS ns1.net-dns.org.
86
+ # net-dns.org. 3600 IN NS ns.ripe.net.
87
+ # net-dns.org. 3600 IN NS ns.hactrn.net.
88
+
89
+ # ADDITIONAL SECTION:
90
+ # ns1.net-dns.org. 3600 IN A 193.0.4.49
91
+ # ns1.net-dns.org. 3600 IN AAAA
92
+
97
93
  uuencodedPacket=%w{
98
94
  11 99 85 00 00 01
99
95
  00 01 00 03 00 02 04 74 78 74 32 01 74 07 6e 65
@@ -109,34 +105,34 @@ class TestMisc < Test::Unit::TestCase
109
105
  73 06 68 61 63 74 72 6e c0 93 c0 79 00 01 00 01
110
106
  00 00 0e 10 00 04 c1 00 04 31 c0 79 00 1c 00 01
111
107
  00 00 0e 10 00 10 20 01 06 10 02 40 00 03 00 00
112
- 12 34 be 21 e3 1e
108
+ 12 34 be 21 e3 1e
113
109
  }
114
-
110
+
115
111
  uuencodedPacket.map!{|e| e.hex}
116
112
  packetdata = uuencodedPacket.pack('c*')
117
113
  packetdata.gsub!("\s*", "")
118
-
114
+
119
115
  packet = Dnsruby::Message.decode(packetdata)
120
116
  txtRr=(packet.answer)[0]
121
117
  assert_equal('Net-DNS; complicated $tuff',txtRr.strings[0],"First Char string in TXT RR read from wireformat")
122
-
123
- # Compare the second char_str this contains a NULL byte (space NULL
124
- # space=200020 in hex)
125
-
118
+
119
+ # Compare the second char_str this contains a NULL byte (space NULL
120
+ # space=200020 in hex)
121
+
126
122
  temp = (txtRr.strings)[1].unpack('H*')[0]
127
- # #assert_equal(unpack('H*',(TXTrr.char_str_list())[1]),"736f7274206f66202220746578743b20616e642062696e61727920002064617461", "Second Char string in TXT RR read from wireformat")
123
+ # #assert_equal(unpack('H*',(TXTrr.char_str_list())[1]),"736f7274206f66202220746578743b20616e642062696e61727920002064617461", "Second Char string in TXT RR read from wireformat")
128
124
  assert_equal("736f7274206f66202220746578743b20616e642062696e61727920002064617461", temp,"Second Char string in TXT RR read from wireformat")
129
-
130
-
125
+
126
+
131
127
  txtRr2=Dnsruby::RR.create('txt2.t.dnsruby.validation-test-servers.nominet.org.uk. 60 IN TXT "Test1 \" \; more stuff" "Test2"')
132
-
128
+
133
129
  assert_equal((txtRr2.strings)[0],'Test1 " ; more stuff', "First arg string in TXT RR read from zonefileformat")
134
130
  assert_equal((txtRr2.strings)[1],'Test2',"Second Char string in TXT RR read from zonefileformat")
135
-
136
-
137
- # txtRr3 = RR.create("baz.example.com 3600 HS TXT '\"' 'Char Str2'")
131
+
132
+
133
+ # txtRr3 = RR.create("baz.example.com 3600 HS TXT '\"' 'Char Str2'")
138
134
  txtRr3 = Dnsruby::RR.create("baz.example.com 3600 IN TXT '\"' 'Char Str2'")
139
-
135
+
140
136
  assert_equal( (txtRr3.strings)[0],'"',"Escaped \" between the single quotes")
141
137
  end
142
138
  end
data/test/tc_name.rb CHANGED
@@ -1,84 +1,81 @@
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 TestName < Test::Unit::TestCase
24
- def test_label_length
25
- Name::Label.set_max_length(Name::Label::MaxLabelLength) # Other tests may have changed this
26
- # Test max label length = 63
27
- begin
28
- name = Name.create("a.b.12345678901234567890123456789012345678901234567890123456789012345.com")
29
- assert(false, "Label of more than max=63 allowed")
30
- rescue ResolvError
31
- end
32
- end
33
-
34
- def test_name_length
35
- # Test max name length=255
36
- begin
37
- name = Name.create("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123.com")
38
- assert(false, "Name of length > 255 allowed")
39
- rescue ResolvError
40
- end
41
- end
42
-
43
- def test_absolute
44
- n = Name.create("example.com")
45
- assert(!n.absolute?)
46
- n = Name.create("example.com.")
47
- assert(n.absolute?)
48
- end
49
-
50
- def test_wild
51
- n = Name.create("example.com")
52
- assert(!n.wild?)
53
- n = Name.create("*.example.com.")
54
- assert(n.wild?)
55
- end
56
-
57
- def test_canonical_ordering
58
- names = []
59
- names.push(Name.create("example"))
60
- names.push(Name.create("a.example"))
61
- names.push(Name.create("yljkjljk.a.example"))
62
- names.push(Name.create("Z.a.example"))
63
- names.push(Name.create("zABC.a.EXAMPLE"))
64
- names.push(Name.create("z.example"))
65
- names.push(Name.create("\001.z.example"))
66
- names.push(Name.create("*.z.example"))
67
- # names.push(Name.create("\200.z.example"))
68
- names.push(Name.create(["c8"].pack("H*")+".z.example"))
69
- names.each_index {|i|
70
- if (i < (names.length() - 1))
71
- assert(names[i].canonically_before(names[i+1]))
72
- assert(!(names[i+1].canonically_before(names[i])))
73
- end
74
- }
75
- assert(Name.create("x.w.example").canonically_before(Name.create("z.w.example")))
76
- assert(Name.create("x.w.example").canonically_before(Name.create("a.z.w.example")))
77
- end
78
-
79
- def test_escapes
80
- n1 = Name.create("\\nall.all.")
81
- n2 = Name.create("nall.all.")
82
- assert(n1 == n2, n1.to_s)
83
- end
84
- 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 TestName < Minitest::Test
21
+ def test_label_length
22
+ Name::Label.set_max_length(Name::Label::MaxLabelLength) # Other tests may have changed this
23
+ # Test max label length = 63
24
+ begin
25
+ name = Name.create("a.b.12345678901234567890123456789012345678901234567890123456789012345.com")
26
+ assert(false, "Label of more than max=63 allowed")
27
+ rescue ResolvError
28
+ end
29
+ end
30
+
31
+ def test_name_length
32
+ # Test max name length=255
33
+ begin
34
+ name = Name.create("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123.com")
35
+ assert(false, "Name of length > 255 allowed")
36
+ rescue ResolvError
37
+ end
38
+ end
39
+
40
+ def test_absolute
41
+ n = Name.create("example.com")
42
+ assert(!n.absolute?)
43
+ n = Name.create("example.com.")
44
+ assert(n.absolute?)
45
+ end
46
+
47
+ def test_wild
48
+ n = Name.create("example.com")
49
+ assert(!n.wild?)
50
+ n = Name.create("*.example.com.")
51
+ assert(n.wild?)
52
+ end
53
+
54
+ def test_canonical_ordering
55
+ names = []
56
+ names.push(Name.create("example"))
57
+ names.push(Name.create("a.example"))
58
+ names.push(Name.create("yljkjljk.a.example"))
59
+ names.push(Name.create("Z.a.example"))
60
+ names.push(Name.create("zABC.a.EXAMPLE"))
61
+ names.push(Name.create("z.example"))
62
+ names.push(Name.create("\001.z.example"))
63
+ names.push(Name.create("*.z.example"))
64
+ # names.push(Name.create("\200.z.example"))
65
+ names.push(Name.create(["c8"].pack("H*")+".z.example"))
66
+ names.each_index {|i|
67
+ if (i < (names.length() - 1))
68
+ assert(names[i].canonically_before(names[i+1]))
69
+ assert(!(names[i+1].canonically_before(names[i])))
70
+ end
71
+ }
72
+ assert(Name.create("x.w.example").canonically_before(Name.create("z.w.example")))
73
+ assert(Name.create("x.w.example").canonically_before(Name.create("a.z.w.example")))
74
+ end
75
+
76
+ def test_escapes
77
+ n1 = Name.create("\\nall.all.")
78
+ n2 = Name.create("nall.all.")
79
+ assert(n1 == n2, n1.to_s)
80
+ end
81
+ end