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_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
|
-
|
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 TestResolverEnv < Test
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
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 TestResOpt < Test
|
20
|
+
class TestResOpt < Minitest::Test
|
24
21
|
def test_dns_file
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
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
|
-
#
|
70
|
-
#
|
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
|
-
#
|
92
|
-
#
|
93
|
-
#
|
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
|
-
#
|
122
|
-
#
|
123
|
-
#
|
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
|
-
|
17
|
-
|
18
|
-
require '
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert(response.kind_of?(Message))
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
assert(error.
|
52
|
-
end
|
53
|
-
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
res=
|
118
|
-
q = Queue.new
|
119
|
-
res.send_async(Message.new("
|
120
|
-
id,
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
#
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
#
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
#
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
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
|