async-dns 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/dns/handler.rb +1 -1
- data/lib/async/dns/resolver.rb +1 -1
- data/lib/async/dns/server.rb +1 -1
- data/lib/async/dns/version.rb +1 -1
- metadata +49 -74
- data/.editorconfig +0 -6
- data/.gitignore +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -27
- data/Gemfile +0 -18
- data/README.md +0 -148
- data/Rakefile +0 -32
- data/async-dns.gemspec +0 -31
- data/examples/cloudflare.rb +0 -24
- data/spec/async/dns/handler_spec.rb +0 -60
- data/spec/async/dns/hosts.txt +0 -2
- data/spec/async/dns/ipv6_spec.rb +0 -78
- data/spec/async/dns/junk_server_context.rb +0 -62
- data/spec/async/dns/message_spec.rb +0 -56
- data/spec/async/dns/origin_spec.rb +0 -106
- data/spec/async/dns/replace_spec.rb +0 -44
- data/spec/async/dns/resolver_performance_spec.rb +0 -106
- data/spec/async/dns/resolver_spec.rb +0 -104
- data/spec/async/dns/server/bind9/generate-local.rb +0 -25
- data/spec/async/dns/server/bind9/local.zone +0 -5014
- data/spec/async/dns/server/bind9/named.conf +0 -14
- data/spec/async/dns/server/bind9/named.run +0 -0
- data/spec/async/dns/server/million.rb +0 -83
- data/spec/async/dns/server_performance_spec.rb +0 -159
- data/spec/async/dns/slow_server_spec.rb +0 -97
- data/spec/async/dns/socket_spec.rb +0 -72
- data/spec/async/dns/system_spec.rb +0 -57
- data/spec/async/dns/transaction_spec.rb +0 -140
- data/spec/async/dns/truncation_spec.rb +0 -61
- data/spec/spec_helper.rb +0 -57
File without changes
|
@@ -1,83 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright, 2009, 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 'benchmark'
|
25
|
-
|
26
|
-
require 'stackprof'
|
27
|
-
|
28
|
-
Name = Resolv::DNS::Name
|
29
|
-
IN = Resolv::DNS::Resource::IN
|
30
|
-
|
31
|
-
# Generate a million A record "domains":
|
32
|
-
|
33
|
-
million = {}
|
34
|
-
|
35
|
-
Benchmark.bm do |x|
|
36
|
-
x.report("Generate names") do
|
37
|
-
(1..1_000_000).each do |i|
|
38
|
-
domain = "domain#{i}.local"
|
39
|
-
|
40
|
-
million[domain] = "#{69}.#{(i >> 16)%256}.#{(i >> 8)%256}.#{i%256}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Run the server:
|
46
|
-
|
47
|
-
StackProf.run(mode: :cpu, out: 'async/dns.stackprof') do
|
48
|
-
Async::DNS::run_server(:listen => [[:udp, '0.0.0.0', 5300]]) do
|
49
|
-
match(//, IN::A) do |transaction|
|
50
|
-
transaction.respond!(million[transaction.name])
|
51
|
-
end
|
52
|
-
|
53
|
-
# Default DNS handler
|
54
|
-
otherwise do |transaction|
|
55
|
-
logger.info "Passing DNS request upstream..."
|
56
|
-
transaction.fail!(:NXDomain)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# Expected output:
|
62
|
-
#
|
63
|
-
# > dig @localhost -p 5300 domain1000000
|
64
|
-
#
|
65
|
-
# ; <<>> DiG 9.8.3-P1 <<>> @localhost -p 5300 domain1000000
|
66
|
-
# ; (3 servers found)
|
67
|
-
# ;; global options: +cmd
|
68
|
-
# ;; Got answer:
|
69
|
-
# ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50336
|
70
|
-
# ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
|
71
|
-
# ;; WARNING: recursion requested but not available
|
72
|
-
#
|
73
|
-
# ;; QUESTION SECTION:
|
74
|
-
# ;domain1000000. IN A
|
75
|
-
#
|
76
|
-
# ;; ANSWER SECTION:
|
77
|
-
# domain1000000. 86400 IN A 69.15.66.64
|
78
|
-
#
|
79
|
-
# ;; Query time: 1 msec
|
80
|
-
# ;; SERVER: 127.0.0.1#5300(127.0.0.1)
|
81
|
-
# ;; WHEN: Fri May 16 19:17:48 2014
|
82
|
-
# ;; MSG SIZE rcvd: 47
|
83
|
-
#
|
@@ -1,159 +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 'benchmark'
|
25
|
-
require 'process/daemon'
|
26
|
-
|
27
|
-
module Async::DNS::ServerPerformanceSpec
|
28
|
-
class MillionServer < Async::DNS::Server
|
29
|
-
def initialize(*)
|
30
|
-
super
|
31
|
-
|
32
|
-
@domains = {}
|
33
|
-
|
34
|
-
(1..5_000).each do |i|
|
35
|
-
domain = "domain#{i}.local"
|
36
|
-
|
37
|
-
@domains[domain] = "#{69}.#{(i >> 16)%256}.#{(i >> 8)%256}.#{i%256}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
attr :domains
|
42
|
-
|
43
|
-
def process(name, resource_class, transaction)
|
44
|
-
transaction.respond!(@domains[name])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
RSpec.describe MillionServer do
|
49
|
-
# include_context "profile"
|
50
|
-
include_context Async::RSpec::Reactor
|
51
|
-
|
52
|
-
let(:interfaces) {[[:udp, '127.0.0.1', 8899]]}
|
53
|
-
let(:server) {MillionServer.new(interfaces)}
|
54
|
-
let(:resolver) {Async::DNS::Resolver.new(interfaces)}
|
55
|
-
|
56
|
-
it "should be fast" do
|
57
|
-
task = server.run
|
58
|
-
|
59
|
-
server.domains.each do |name, address|
|
60
|
-
resolved = resolver.addresses_for(name)
|
61
|
-
end
|
62
|
-
|
63
|
-
task.stop
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
RSpec.describe Async::DNS::Server do
|
68
|
-
include_context Async::RSpec::Reactor
|
69
|
-
|
70
|
-
context 'benchmark' do
|
71
|
-
class AsyncServerDaemon < Process::Daemon
|
72
|
-
def working_directory
|
73
|
-
File.expand_path("../tmp", __FILE__)
|
74
|
-
end
|
75
|
-
|
76
|
-
def reactor
|
77
|
-
@reactor ||= Async::Reactor.new
|
78
|
-
end
|
79
|
-
|
80
|
-
def startup
|
81
|
-
puts "Starting DNS server..."
|
82
|
-
@server = MillionServer.new([[:udp, '0.0.0.0', 5300]])
|
83
|
-
|
84
|
-
reactor.async do
|
85
|
-
@task = @server.run
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def run
|
90
|
-
reactor.run
|
91
|
-
end
|
92
|
-
|
93
|
-
def shutdown
|
94
|
-
@task.stop if @task
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class Bind9ServerDaemon < Process::Daemon
|
99
|
-
def working_directory
|
100
|
-
File.expand_path("../server/bind9", __FILE__)
|
101
|
-
end
|
102
|
-
|
103
|
-
def run
|
104
|
-
exec(self.class.named_executable, "-c", "named.conf", "-f", "-p", "5400", "-g")
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.named_executable
|
108
|
-
# Check if named executable is available:
|
109
|
-
@named ||= `which named`.chomp
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
before(:all) do
|
114
|
-
@servers = []
|
115
|
-
@servers << ["Async::DNS::Server", 5300]
|
116
|
-
|
117
|
-
@domains = (1..1000).collect do |i|
|
118
|
-
"domain#{i}.local"
|
119
|
-
end
|
120
|
-
|
121
|
-
AsyncServerDaemon.start
|
122
|
-
|
123
|
-
unless Bind9ServerDaemon.named_executable.empty?
|
124
|
-
Bind9ServerDaemon.start
|
125
|
-
@servers << ["Bind9", 5400]
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
after(:all) do
|
130
|
-
AsyncServerDaemon.stop
|
131
|
-
|
132
|
-
unless Bind9ServerDaemon.named_executable.empty?
|
133
|
-
Bind9ServerDaemon.stop
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'takes time' do
|
138
|
-
Benchmark.bm(30) do |x|
|
139
|
-
@servers.each do |name, port|
|
140
|
-
resolver = Async::DNS::Resolver.new([[:udp, '127.0.0.1', port]])
|
141
|
-
|
142
|
-
x.report(name) do
|
143
|
-
Async::Reactor.run do
|
144
|
-
# Number of requests remaining since this is an asynchronous event loop:
|
145
|
-
5.times do
|
146
|
-
pending = @domains.size
|
147
|
-
|
148
|
-
resolved = @domains.collect{|domain| resolver.addresses_for(domain)}
|
149
|
-
|
150
|
-
expect(resolved).to_not include(nil)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
@@ -1,97 +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::SlowServerSpec
|
26
|
-
IN = Resolv::DNS::Resource::IN
|
27
|
-
|
28
|
-
class SlowServer < Async::DNS::Server
|
29
|
-
def process(name, resource_class, transaction)
|
30
|
-
@resolver ||= Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
31
|
-
|
32
|
-
Async::Task.current.sleep(2) if name.end_with?('.com')
|
33
|
-
|
34
|
-
transaction.fail!(:NXDomain)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "Async::DNS Slow Server" do
|
39
|
-
include_context Async::RSpec::Reactor
|
40
|
-
|
41
|
-
let(:server_interfaces) {[[:udp, '0.0.0.0', 5330], [:tcp, '0.0.0.0', 5330]]}
|
42
|
-
let(:server) {SlowServer.new(server_interfaces)}
|
43
|
-
|
44
|
-
around(:each) do |example|
|
45
|
-
begin
|
46
|
-
task = server.run
|
47
|
-
|
48
|
-
example.run
|
49
|
-
ensure
|
50
|
-
task.stop
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it "get no answer after 2 seconds" do
|
55
|
-
start_time = Time.now
|
56
|
-
|
57
|
-
resolver = Async::DNS::Resolver.new(server_interfaces, :timeout => 10)
|
58
|
-
|
59
|
-
response = resolver.query("apple.com", IN::A)
|
60
|
-
|
61
|
-
expect(response.answer.length).to be == 0
|
62
|
-
|
63
|
-
end_time = Time.now
|
64
|
-
|
65
|
-
expect(end_time - start_time).to be_within(0.1).of(2.0)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "times out after 1 second" do
|
69
|
-
start_time = Time.now
|
70
|
-
|
71
|
-
# Two server interfaces, timeout of 0.5s each:
|
72
|
-
resolver = Async::DNS::Resolver.new(server_interfaces, :timeout => 0.5)
|
73
|
-
|
74
|
-
response = resolver.query("apple.com", IN::A)
|
75
|
-
|
76
|
-
expect(response).to be nil
|
77
|
-
|
78
|
-
end_time = Time.now
|
79
|
-
|
80
|
-
expect(end_time - start_time).to be_within(0.1).of(1.0)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "gets no answer immediately" do
|
84
|
-
start_time = Time.now
|
85
|
-
|
86
|
-
resolver = Async::DNS::Resolver.new(server_interfaces, :timeout => 0.5)
|
87
|
-
|
88
|
-
response = resolver.query("oriontransfer.org", IN::A)
|
89
|
-
|
90
|
-
expect(response.answer.length).to be 0
|
91
|
-
|
92
|
-
end_time = Time.now
|
93
|
-
|
94
|
-
expect(end_time - start_time).to be_within(0.1).of(0.0)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
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
|
-
require 'async/dns/system'
|
25
|
-
|
26
|
-
module Async::DNS::SocketSpec
|
27
|
-
IN = Resolv::DNS::Resource::IN
|
28
|
-
|
29
|
-
class TestServer < Async::DNS::Server
|
30
|
-
def process(name, resource_class, transaction)
|
31
|
-
@resolver ||= Async::DNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
32
|
-
|
33
|
-
transaction.passthrough!(@resolver)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe Async::DNS::StreamHandler do
|
38
|
-
include_context Async::RSpec::Reactor
|
39
|
-
|
40
|
-
let(:server_interfaces) {[TCPServer.new('127.0.0.1', 2002)]}
|
41
|
-
let(:server) {TestServer.new(server_interfaces)}
|
42
|
-
|
43
|
-
it "should create server with existing TCP socket" do
|
44
|
-
task = server.run
|
45
|
-
|
46
|
-
resolver = Async::DNS::Resolver.new([[:tcp, '127.0.0.1', 2002]])
|
47
|
-
response = resolver.query('google.com')
|
48
|
-
expect(response.class).to be == Async::DNS::Message
|
49
|
-
|
50
|
-
task.stop
|
51
|
-
server_interfaces.each(&:close)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe Async::DNS::DatagramHandler do
|
56
|
-
include_context Async::RSpec::Reactor
|
57
|
-
|
58
|
-
let(:server_interfaces) {[UDPSocket.new.tap{|socket| socket.bind('127.0.0.1', 2002)}]}
|
59
|
-
let(:server) {TestServer.new(server_interfaces)}
|
60
|
-
|
61
|
-
it "should create server with existing UDP socket" do
|
62
|
-
task = server.run
|
63
|
-
|
64
|
-
resolver = Async::DNS::Resolver.new([[:udp, '127.0.0.1', 2002]])
|
65
|
-
response = resolver.query('google.com')
|
66
|
-
expect(response.class).to be == Async::DNS::Message
|
67
|
-
|
68
|
-
task.stop
|
69
|
-
server_interfaces.each(&:close)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,57 +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 'async/dns/system'
|
25
|
-
|
26
|
-
module Async::DNS::SystemSpec
|
27
|
-
describe Async::DNS::System do
|
28
|
-
include_context Async::RSpec::Reactor
|
29
|
-
|
30
|
-
it "should have at least one namesever" do
|
31
|
-
expect(Async::DNS::System::nameservers.length).to be > 0
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should respond to query for google.com" do
|
35
|
-
resolver = Async::DNS::Resolver.new(Async::DNS::System.nameservers)
|
36
|
-
|
37
|
-
response = resolver.query('google.com')
|
38
|
-
|
39
|
-
expect(response.class).to be == Async::DNS::Message
|
40
|
-
expect(response.rcode).to be == Resolv::DNS::RCode::NoError
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe Async::DNS::System::Hosts do
|
45
|
-
it "should parse the hosts file" do
|
46
|
-
hosts = Async::DNS::System::Hosts.new
|
47
|
-
|
48
|
-
# Load the test hosts data:
|
49
|
-
File.open(File.expand_path("../hosts.txt", __FILE__)) do |file|
|
50
|
-
hosts.parse_hosts(file)
|
51
|
-
end
|
52
|
-
|
53
|
-
expect(hosts.call('testing')).to be == true
|
54
|
-
expect(hosts['testing']).to be == '1.2.3.4'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|