dnsruby 1.55 → 1.56.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +96 -0
- data/Rakefile +30 -29
- data/demo/axfr.rb +93 -93
- data/demo/check_soa.rb +99 -99
- data/demo/check_zone.rb +59 -59
- data/demo/digdlv.rb +43 -43
- data/demo/digroot.rb +34 -34
- data/demo/example_recurse.rb +14 -14
- data/demo/mresolv.rb +30 -30
- data/demo/mx.rb +31 -31
- data/demo/rubydig.rb +37 -37
- data/demo/to_resolve.txt +3088 -3088
- data/demo/trace_dns.rb +46 -46
- data/lib/dnsruby.rb +161 -526
- data/lib/dnsruby/DNS.rb +305 -0
- data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
- data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
- data/lib/dnsruby/code_mappers.rb +295 -0
- data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
- data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
- data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
- data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
- data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
- data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
- data/lib/dnsruby/message/decoder.rb +164 -0
- data/lib/dnsruby/message/encoder.rb +75 -0
- data/lib/dnsruby/message/header.rb +249 -0
- data/lib/dnsruby/message/message.rb +629 -0
- data/lib/dnsruby/message/question.rb +86 -0
- data/lib/dnsruby/message/section.rb +96 -0
- data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
- data/lib/dnsruby/packet_sender.rb +661 -0
- data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
- data/lib/dnsruby/resolv.rb +113 -0
- data/lib/dnsruby/resolver.rb +1192 -0
- data/lib/dnsruby/resource/A.rb +56 -0
- data/lib/dnsruby/resource/AAAA.rb +54 -0
- data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
- data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
- data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
- data/lib/dnsruby/resource/DLV.rb +27 -0
- data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
- data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
- data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
- data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
- data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
- data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
- data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
- data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
- data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
- data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
- data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
- data/lib/dnsruby/resource/NSEC.rb +275 -0
- data/lib/dnsruby/resource/NSEC3.rb +332 -0
- data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
- data/lib/dnsruby/resource/OPT.rb +272 -0
- data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
- data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
- data/lib/dnsruby/resource/RR.rb +421 -0
- data/lib/dnsruby/resource/RRSIG.rb +275 -0
- data/lib/dnsruby/resource/RRSet.rb +190 -0
- data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
- data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
- data/lib/dnsruby/resource/SPF.rb +29 -0
- data/lib/dnsruby/resource/SRV.rb +112 -0
- data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
- data/lib/dnsruby/resource/TKEY.rb +163 -0
- data/lib/dnsruby/resource/TSIG.rb +593 -0
- data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
- data/lib/dnsruby/resource/X25.rb +55 -0
- data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
- data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
- data/lib/dnsruby/resource/resource.rb +25 -0
- data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
- data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
- data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
- data/lib/dnsruby/the_log.rb +44 -0
- data/lib/dnsruby/update.rb +278 -0
- data/lib/dnsruby/validator_thread.rb +124 -0
- data/lib/dnsruby/version.rb +3 -0
- data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
- data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
- data/test/spec_helper.rb +16 -0
- data/test/tc_axfr.rb +31 -34
- data/test/tc_cache.rb +32 -32
- data/test/tc_dlv.rb +28 -28
- data/test/tc_dns.rb +73 -76
- data/test/tc_dnskey.rb +31 -32
- data/test/tc_dnsruby.rb +50 -44
- data/test/tc_ds.rb +36 -36
- data/test/tc_escapedchars.rb +252 -255
- data/test/tc_hash.rb +17 -21
- data/test/tc_header.rb +48 -57
- data/test/tc_hip.rb +19 -22
- data/test/tc_ipseckey.rb +18 -21
- data/test/tc_keith.rb +300 -0
- data/test/tc_message.rb +87 -0
- data/test/tc_misc.rb +83 -87
- data/test/tc_name.rb +81 -84
- data/test/tc_naptr.rb +18 -21
- data/test/tc_nsec.rb +55 -55
- data/test/tc_nsec3.rb +23 -24
- data/test/tc_nsec3param.rb +20 -21
- data/test/tc_packet.rb +90 -93
- data/test/tc_packet_unique_push.rb +48 -51
- data/test/tc_question.rb +30 -33
- data/test/tc_queue.rb +16 -17
- data/test/tc_recur.rb +16 -17
- data/test/tc_res_config.rb +38 -41
- data/test/tc_res_env.rb +29 -32
- data/test/tc_res_file.rb +26 -29
- data/test/tc_res_opt.rb +62 -65
- data/test/tc_resolver.rb +287 -242
- data/test/tc_rr-opt.rb +70 -63
- data/test/tc_rr-txt.rb +68 -71
- data/test/tc_rr-unknown.rb +45 -48
- data/test/tc_rr.rb +76 -70
- data/test/tc_rrset.rb +21 -22
- data/test/tc_rrsig.rb +19 -20
- data/test/tc_single_resolver.rb +294 -297
- data/test/tc_soak.rb +199 -202
- data/test/tc_soak_base.rb +29 -34
- data/test/tc_sshfp.rb +20 -23
- data/test/tc_tcp.rb +32 -35
- data/test/tc_tkey.rb +41 -44
- data/test/tc_tsig.rb +81 -84
- data/test/tc_update.rb +108 -111
- data/test/tc_validator.rb +29 -29
- data/test/tc_verifier.rb +81 -82
- data/test/ts_dnsruby.rb +16 -15
- data/test/ts_offline.rb +62 -63
- data/test/ts_online.rb +115 -115
- metadata +155 -90
- data/README +0 -59
- data/lib/Dnsruby/DNS.rb +0 -305
- data/lib/Dnsruby/PacketSender.rb +0 -656
- data/lib/Dnsruby/Resolver.rb +0 -1189
- data/lib/Dnsruby/TheLog.rb +0 -44
- data/lib/Dnsruby/message.rb +0 -1230
- data/lib/Dnsruby/resource/A.rb +0 -56
- data/lib/Dnsruby/resource/AAAA.rb +0 -54
- data/lib/Dnsruby/resource/DLV.rb +0 -27
- data/lib/Dnsruby/resource/NSEC.rb +0 -298
- data/lib/Dnsruby/resource/NSEC3.rb +0 -340
- data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
- data/lib/Dnsruby/resource/OPT.rb +0 -213
- data/lib/Dnsruby/resource/RRSIG.rb +0 -275
- data/lib/Dnsruby/resource/SPF.rb +0 -29
- data/lib/Dnsruby/resource/SRV.rb +0 -112
- data/lib/Dnsruby/resource/TKEY.rb +0 -163
- data/lib/Dnsruby/resource/TSIG.rb +0 -593
- data/lib/Dnsruby/resource/X25.rb +0 -55
- data/lib/Dnsruby/resource/resource.rb +0 -678
- data/lib/Dnsruby/update.rb +0 -278
- data/lib/Dnsruby/validator_thread.rb +0 -124
data/test/tc_hash.rb
CHANGED
@@ -1,30 +1,26 @@
|
|
1
|
-
|
2
|
-
#Copyright 2007 Nominet UK
|
3
|
-
#
|
4
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
#you may not use this file except in compliance with the License.
|
6
|
-
#You may obtain a copy of the License at
|
7
|
-
#
|
1
|
+
# --
|
2
|
+
# Copyright 2007 Nominet UK
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
8
|
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
#Unless required by applicable law or agreed to in writing, software
|
11
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
#See the License for the specific language governing permissions and
|
14
|
-
#limitations under the License.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
rescue LoadError
|
19
|
-
end
|
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'
|
20
18
|
|
21
|
-
require 'test/unit'
|
22
19
|
require 'set'
|
23
|
-
require 'dnsruby'
|
24
20
|
|
25
21
|
module Dnsruby
|
26
22
|
|
27
|
-
class TestHash < Test
|
23
|
+
class TestHash < Minitest::Test
|
28
24
|
|
29
25
|
def test_types_hash
|
30
26
|
object1 = Types.new(Types::NSEC3)
|
data/test/tc_header.rb
CHANGED
@@ -1,53 +1,50 @@
|
|
1
|
-
|
2
|
-
#Copyright 2007 Nominet UK
|
3
|
-
#
|
4
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
#you may not use this file except in compliance with the License.
|
6
|
-
#You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
#Unless required by applicable law or agreed to in writing, software
|
11
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
#See the License for the specific language governing permissions and
|
14
|
-
#limitations under the License.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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 TestHeader < Test
|
20
|
+
class TestHeader < Minitest::Test
|
24
21
|
def test_header
|
25
22
|
header = Header.new();
|
26
23
|
assert(header, "new() returned something")
|
27
|
-
|
24
|
+
|
28
25
|
header.id=41
|
29
26
|
assert_equal(header.id, 41, "id() works")
|
30
|
-
|
27
|
+
|
31
28
|
header.qr=true
|
32
29
|
assert_equal(header.qr, true, "qr() works")
|
33
|
-
|
30
|
+
|
34
31
|
header.opcode="QUERY"
|
35
|
-
assert_equal(OpCode.Query, header.opcode,
|
32
|
+
assert_equal(OpCode.Query, header.opcode,
|
36
33
|
"opcode() works")
|
37
34
|
header.opcode=OpCode::Query
|
38
|
-
assert_equal(header.opcode.string, "Query",
|
35
|
+
assert_equal(header.opcode.string, "Query",
|
39
36
|
"opcode() works")
|
40
|
-
|
41
|
-
|
37
|
+
|
38
|
+
|
42
39
|
header.aa=true
|
43
40
|
assert_equal(header.aa, true, "aa() works")
|
44
|
-
|
41
|
+
|
45
42
|
header.tc=false
|
46
43
|
assert_equal(header.tc, false, "tc() works")
|
47
|
-
|
44
|
+
|
48
45
|
header.rd=true
|
49
46
|
assert_equal(header.rd, true, "rd() works")
|
50
|
-
|
47
|
+
|
51
48
|
header.ad=true
|
52
49
|
assert_equal(header.ad, true, "rd() works")
|
53
50
|
|
@@ -56,52 +53,46 @@ class TestHeader < Test::Unit::TestCase
|
|
56
53
|
|
57
54
|
header.ra=true
|
58
55
|
assert_equal(header.ra, true, "ra() works")
|
59
|
-
|
56
|
+
|
60
57
|
header.qr=true
|
61
58
|
assert_equal(header.qr, true, "qr() works")
|
62
|
-
|
59
|
+
|
63
60
|
header.rcode="NOERROR"
|
64
61
|
assert_equal(header.get_header_rcode, RCode::NOERROR, "rcode() works")
|
65
62
|
header.rcode=RCode.NOERROR
|
66
63
|
assert_equal(header.get_header_rcode.string, "NOERROR", "rcode() works")
|
67
|
-
|
64
|
+
|
68
65
|
header.qdcount=1
|
69
66
|
header.ancount=2
|
70
67
|
header.nscount=3
|
71
68
|
header.arcount=3
|
72
|
-
|
73
|
-
|
74
|
-
#
|
75
|
-
#header.cd=0
|
76
|
-
#assert_equal(header.cd, 0, "cd() works")
|
69
|
+
|
70
|
+
|
71
|
+
# Reenable when support for CD is there
|
72
|
+
# header.cd=0
|
73
|
+
# assert_equal(header.cd, 0, "cd() works")
|
77
74
|
data = header.data
|
78
|
-
|
75
|
+
|
79
76
|
header2 = Header.new_from_data(data);
|
80
|
-
|
77
|
+
|
81
78
|
assert(header==(header2), 'Headers are the same');
|
82
|
-
|
83
|
-
#
|
84
|
-
# Is header.inspect remotely sane?
|
85
|
-
#
|
86
|
-
assert(header.to_s =~ /opcode = Query/, 'inspect() has opcode correct');
|
87
|
-
assert(header.to_s =~ /ancount = 2/, 'inspect() has ancount correct');
|
88
|
-
|
79
|
+
|
89
80
|
header = Header.new;
|
90
|
-
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
81
|
+
|
82
|
+
#
|
83
|
+
# Check that the aliases work properly.
|
84
|
+
#
|
94
85
|
header.zocount=(0);
|
95
86
|
header.prcount=(1);
|
96
87
|
header.upcount=(2);
|
97
88
|
header.adcount=(3);
|
98
|
-
|
89
|
+
|
99
90
|
assert_equal(header.zocount, 0, 'zocount works');
|
100
91
|
assert_equal(header.prcount, 1, 'prcount works');
|
101
92
|
assert_equal(header.upcount, 2, 'upcount works');
|
102
93
|
assert_equal(header.adcount, 3, 'adcount works');
|
103
|
-
|
104
|
-
|
105
|
-
|
94
|
+
|
95
|
+
|
96
|
+
|
106
97
|
end
|
107
98
|
end
|
data/test/tc_hip.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
#Copyright 2007 Nominet UK
|
4
|
-
#
|
5
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
#you may not use this file except in compliance with the License.
|
7
|
-
#You may obtain a copy of the License at
|
8
|
-
#
|
2
|
+
# --
|
3
|
+
# Copyright 2007 Nominet UK
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
9
|
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
#Unless required by applicable law or agreed to in writing, software
|
12
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
#See the License for the specific language governing permissions and
|
15
|
-
#limitations under the License.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
require 'test/unit'
|
22
|
-
require 'dnsruby'
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
# ++
|
17
|
+
|
18
|
+
require_relative 'spec_helper'
|
19
|
+
|
23
20
|
include Dnsruby
|
24
|
-
class TestHIP < Test
|
21
|
+
class TestHIP < Minitest::Test
|
25
22
|
def test_hip
|
26
23
|
[{"www.example.com. IN HIP ( 2 200100107B1A74DF365639CC39F1D578
|
27
24
|
AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D )" =>
|
@@ -70,4 +67,4 @@ class TestHIP < Test::Unit::TestCase
|
|
70
67
|
end
|
71
68
|
|
72
69
|
end
|
73
|
-
|
70
|
+
|
data/test/tc_ipseckey.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
#Copyright 2007 Nominet UK
|
4
|
-
#
|
5
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
#you may not use this file except in compliance with the License.
|
7
|
-
#You may obtain a copy of the License at
|
8
|
-
#
|
2
|
+
# --
|
3
|
+
# Copyright 2007 Nominet UK
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
9
|
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
#Unless required by applicable law or agreed to in writing, software
|
12
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
#See the License for the specific language governing permissions and
|
15
|
-
#limitations under the License.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
require 'test/unit'
|
22
|
-
require 'dnsruby'
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
# ++
|
17
|
+
|
18
|
+
require_relative 'spec_helper'
|
19
|
+
|
23
20
|
include Dnsruby
|
24
|
-
class TestIPSECKEY < Test
|
21
|
+
class TestIPSECKEY < Minitest::Test
|
25
22
|
def test_ipseckey
|
26
23
|
[{"38.1.0.192.in-addr.arpa. 7200 IN IPSECKEY ( 10 3 2
|
27
24
|
mygateway.example.com.
|
data/test/tc_keith.rb
ADDED
@@ -0,0 +1,300 @@
|
|
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
|
288
|
+
|
289
|
+
def test_rd_not_overwritten
|
290
|
+
message = Message.new(GOOD_DOMAIN_NAME)
|
291
|
+
message.header.rd = false
|
292
|
+
assert(! message.header.rd)
|
293
|
+
resolver = Resolver.new
|
294
|
+
raise "Header rd flag was overwritten to true in #{__FILE__}:#{__LINE__}" if message.header.rd
|
295
|
+
_response = resolver.send_message(message)
|
296
|
+
puts "Header rd: #{message.header.rd}"
|
297
|
+
raise "Header rd flag was overwritten to true in #{__FILE__}:#{__LINE__}" if message.header.rd
|
298
|
+
assert(! message.header.rd, "Header rd flag was overwritten to true")
|
299
|
+
end
|
300
|
+
end
|