async-dns 1.2.1 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'async/dns'
24
- require 'base64'
25
-
26
- module Async::DNS::MessageSpec
27
- describe Async::DNS::Message do
28
- it "should be decoded correctly" do
29
- data = Base64.decode64(<<-EOF)
30
- HQCBgAABAAgAAAABA3d3dwV5YWhvbwNjb20AAAEAAcAMAAUAAQAAASwADwZm
31
- ZC1mcDMDd2cxAWLAEMArAAUAAQAAASwACQZkcy1mcDPAMsBGAAUAAQAAADwA
32
- FQ5kcy1hbnktZnAzLWxmYgN3YTHANsBbAAUAAQAAASwAEg9kcy1hbnktZnAz
33
- LXJlYWzAasB8AAEAAQAAADwABGKK/B7AfAABAAEAAAA8AARii7SVwHwAAQAB
34
- AAAAPAAEYou3GMB8AAEAAQAAADwABGKK/W0AACkQAAAAAAAAAA==
35
- EOF
36
-
37
- message = Async::DNS::decode_message(data)
38
- expect(message.class).to be == Async::DNS::Message
39
- expect(message.id).to be == 0x1d00
40
-
41
- expect(message.question.count).to be == 1
42
- expect(message.answer.count).to be == 8
43
- expect(message.authority.count).to be == 0
44
- expect(message.additional.count).to be == 1
45
- end
46
-
47
- it "should fail to decode due to bad AAAA length" do
48
- data = Base64.decode64(<<-EOF)
49
- 6p6BgAABAAEAAAABCGJhaWNhaWNuA2NvbQAAHAABwAwAHAABAAABHgAEMhd7
50
- dwAAKRAAAAAAAAAA
51
- EOF
52
-
53
- expect{Async::DNS::decode_message(data)}.to raise_error(Async::DNS::DecodeError)
54
- end
55
- end
56
- end
@@ -1,106 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'async/dns'
24
-
25
- module Async::DNS::OriginSpec
26
- describe Async::DNS::Resolver do
27
- it "should generate fully qualified domain name with specified origin" do
28
- resolver = Async::DNS::Resolver.new([], origin: "foo.bar.")
29
-
30
- fully_qualified_name = resolver.fully_qualified_name("baz")
31
-
32
- expect(fully_qualified_name).to be_absolute
33
- expect(fully_qualified_name.to_s).to be == "baz.foo.bar."
34
- end
35
- end
36
-
37
- describe Resolv::DNS::Name do
38
- let(:name) {Resolv::DNS::Name.create("foo.bar")}
39
-
40
- it "should be relative" do
41
- expect(name).to_not be_absolute
42
- expect(name.to_s).to be == "foo.bar"
43
- end
44
-
45
- it "should add the specified origin" do
46
- fully_qualified_name = name.with_origin("org")
47
-
48
- expect(fully_qualified_name.to_a.size).to be 3
49
- expect(fully_qualified_name).to be_absolute
50
- expect(fully_qualified_name.to_s).to be == "foo.bar.org."
51
- end
52
-
53
- it "should handle nil origin as absolute" do
54
- fully_qualified_name = name.with_origin(nil)
55
-
56
- expect(fully_qualified_name.to_a.size).to be 2
57
- expect(fully_qualified_name).to be_absolute
58
- expect(fully_qualified_name.to_s).to be == "foo.bar."
59
- end
60
-
61
- it "should handle empty origin as absolute" do
62
- fully_qualified_name = name.with_origin('')
63
-
64
- expect(fully_qualified_name.to_a.size).to be 2
65
- expect(fully_qualified_name).to be_absolute
66
- expect(fully_qualified_name.to_s).to be == "foo.bar."
67
- end
68
- end
69
-
70
- describe Resolv::DNS::Name do
71
- let(:name) {Resolv::DNS::Name.create("foo.bar.")}
72
-
73
- it "should be absolute" do
74
- expect(name).to be_absolute
75
- expect(name.to_s).to be == "foo.bar."
76
- end
77
-
78
- it "should remove the specified origin" do
79
- relative_name = name.without_origin("bar")
80
-
81
- expect(relative_name.to_a.size).to be 1
82
- expect(relative_name).to_not be_absolute
83
- expect(relative_name.to_s).to be == "foo"
84
- end
85
-
86
- it "should not remove nil origin but become relative" do
87
- relative_name = name.without_origin(nil)
88
-
89
- expect(relative_name.to_a.size).to be 2
90
- expect(relative_name).to_not be_absolute
91
- expect(relative_name.to_s).to be == "foo.bar"
92
- end
93
-
94
- it "should not remove empty string origin but become relative" do
95
- relative_name = name.without_origin('')
96
-
97
- expect(relative_name.to_a.size).to be 2
98
- expect(relative_name).to_not be_absolute
99
- expect(relative_name.to_s).to be == "foo.bar"
100
- end
101
-
102
- it "should not raise an exception when origin isn't valid" do
103
- expect{name.without_origin('bob')}.to raise_exception(Resolv::DNS::OriginError)
104
- end
105
- end
106
- end
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'async/dns'
24
- require 'async/dns/replace'
25
-
26
- module Async::DNS::ReplaceSpec
27
- describe Async::DNS::Replace do
28
- include_context Async::RSpec::Reactor
29
-
30
- let(:default_resolver) {Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])}
31
-
32
- after(:all) do
33
- Async::DNS::Replace.resolver = nil
34
- end
35
-
36
- it "should replace TCPSocket hostname lookup" do
37
- Async::DNS::Replace.resolver = default_resolver
38
-
39
- expect(default_resolver).to receive(:addresses_for).with('www.google.com').and_call_original
40
-
41
- TCPSocket.new('www.google.com', 80)
42
- end
43
- end
44
- end
@@ -1,108 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'async/dns'
24
-
25
- module Async::DNS::ResolverPerformanceSpec
26
- describe Async::DNS::Resolver do
27
- context 'benchmark' do
28
- domains = %W{
29
- Facebook.com
30
- Twitter.com
31
- Google.com
32
- Youtube.com
33
- Wordpress.org
34
- Adobe.com
35
- Blogspot.com
36
- Wikipedia.org
37
- Linkedin.com
38
- Wordpress.com
39
- Yahoo.com
40
- Amazon.com
41
- Flickr.com
42
- Pinterest.com
43
- Tumblr.com
44
- W3.org
45
- Apple.com
46
- Myspace.com
47
- Vimeo.com
48
- Microsoft.com
49
- Youtu.be
50
- Qq.com
51
- Digg.com
52
- Baidu.com
53
- Stumbleupon.com
54
- Addthis.com
55
- Statcounter.com
56
- Feedburner.com
57
- TradeMe.co.nz
58
- Nytimes.com
59
- Reddit.com
60
- Weebly.com
61
- Bbc.co.uk
62
- Blogger.com
63
- Msn.com
64
- Macromedia.com
65
- Goo.gl
66
- Instagram.com
67
- Gov.uk
68
- Icio.us
69
- Yandex.ru
70
- Cnn.com
71
- Webs.com
72
- Google.de
73
- T.co
74
- Livejournal.com
75
- Imdb.com
76
- Mail.ru
77
- Jimdo.com
78
- }
79
-
80
- before do
81
- require 'benchmark'
82
- end
83
-
84
- include_context Async::RSpec::Reactor
85
-
86
- it 'should be faster than native resolver' do
87
- Benchmark.bm(30) do |x|
88
- a = x.report("Async::DNS::Resolver") do
89
- resolver = Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
90
-
91
- resolved = domains.collect{|domain| resolver.addresses_for(domain)}
92
- end
93
-
94
- b = x.report("Resolv::DNS") do
95
- resolver = Resolv::DNS.new(:nameserver => "8.8.8.8")
96
-
97
- resolved = domains.collect do |domain|
98
- [domain, resolver.getaddresses(domain)]
99
- end
100
- end
101
-
102
- # This is a regression, but not important right now.
103
- # expect(a.real).to be < b.real
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env rspec
2
-
3
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'async/dns'
24
-
25
- require_relative 'junk_server_context'
26
-
27
- RSpec.describe Async::DNS::Resolver do
28
- include_context Async::RSpec::Reactor
29
-
30
- it "should result in non-existent domain" do
31
- resolver = Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
32
-
33
- response = resolver.query('foobar.oriontransfer.org')
34
-
35
- expect(response.rcode).to be == Resolv::DNS::RCode::NXDomain
36
- end
37
-
38
- it "should result in some answers" do
39
- resolver = Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
40
-
41
- response = resolver.query('google.com')
42
-
43
- expect(response.class).to be == Async::DNS::Message
44
- expect(response.answer.size).to be > 0
45
- end
46
-
47
- it "should return no results" do
48
- resolver = Async::DNS::Resolver.new([])
49
-
50
- response = resolver.query('google.com')
51
-
52
- expect(response).to be == nil
53
- end
54
-
55
- it "should fail to get addresses" do
56
- resolver = Async::DNS::Resolver.new([])
57
-
58
- expect{resolver.addresses_for('google.com')}.to raise_error(Async::DNS::ResolutionFailure)
59
- end
60
-
61
- context 'with junk UDP server' do
62
- include_context 'Junk UDP Server'
63
-
64
- it "should fail with decode error" do
65
- resolver = Async::DNS::Resolver.new([[:udp, "0.0.0.0", 6060]])
66
-
67
- response = resolver.query('google.com')
68
-
69
- expect(response).to be == nil
70
- end
71
- end
72
-
73
- context 'with junk TCP server' do
74
- include_context 'Junk TCP Server'
75
-
76
- it "should fail with decode error" do
77
- resolver = Async::DNS::Resolver.new([[:tcp, "0.0.0.0", 6060]])
78
-
79
- response = resolver.query('google.com')
80
-
81
- expect(response).to be == nil
82
- end
83
- end
84
-
85
- it "should return some IPv4 and IPv6 addresses" do
86
- resolver = Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
87
-
88
- addresses = resolver.addresses_for("www.google.com.")
89
-
90
- expect(addresses.size).to be > 0
91
-
92
- addresses.each do |address|
93
- expect(address).to be_kind_of(Resolv::IPv4) | be_kind_of(Resolv::IPv6)
94
- end
95
- end
96
-
97
- it "should recursively resolve CNAME records" do
98
- resolver = Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
99
-
100
- addresses = resolver.addresses_for('www.baidu.com')
101
-
102
- expect(addresses.size).to be > 0
103
- end
104
- end
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- File.open("local.zone", "w") do |f|
4
- f.write(DATA.read)
5
-
6
- (1..5_000).each do |i|
7
- f.puts "domain#{i} IN A #{69}.#{(i >> 16)%256}.#{(i >> 8)%256}.#{i%256}"
8
- end
9
- end
10
-
11
- __END__
12
- ;
13
- ; BIND data file for local loopback interface
14
- ;
15
- $TTL 604800
16
- @ IN SOA ns.local. postmaster.localhost (
17
- 2 ; Serial
18
- 604800 ; Refresh
19
- 86400 ; Retry
20
- 2419200 ; Expire
21
- 604800 ) ; Negative Cache TTL
22
- ;
23
- local. IN NS ns.local.
24
- ns.local. IN A 127.0.0.1
25
-