async-dns 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +0,0 @@
1
-
2
- options {
3
- directory "./";
4
-
5
- listen-on-v6 { none; };
6
- listen-on { 127.0.0.1; };
7
-
8
- pid-file "./named.pid";
9
- };
10
-
11
- zone "local" {
12
- type master;
13
- file "./local.zone";
14
- };
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
@@ -1,140 +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
- require 'yaml'
25
-
26
- module Async::DNS::TransactionSpec
27
- SERVER_PORTS = [[:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53]]
28
- IN = Resolv::DNS::Resource::IN
29
-
30
- describe Async::DNS::Transaction do
31
- let(:server) { Async::DNS::Server.new }
32
- let(:query) { Async::DNS::Message.new(0) }
33
- let(:question) { Resolv::DNS::Name.create("www.google.com.") }
34
- let(:response) { Async::DNS::Message.new(0) }
35
- let(:resolver) { Async::DNS::Resolver.new([[:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53]])}
36
-
37
- include_context Async::RSpec::Reactor
38
-
39
- it "should append an address" do
40
- transaction = Async::DNS::Transaction.new(server, query, question, IN::A, response)
41
-
42
- transaction.respond!("1.2.3.4")
43
-
44
- expect(transaction.response.answer[0][0]).to be == question
45
- expect(transaction.response.answer[0][2].address.to_s).to be == "1.2.3.4"
46
- end
47
-
48
- it "should passthrough the request" do
49
- transaction = Async::DNS::Transaction.new(server, query, question, IN::A, response)
50
-
51
- expect(transaction.response.answer.size).to be 0
52
-
53
- transaction.passthrough!(resolver)
54
-
55
- expect(transaction.response.answer.size).to be > 0
56
- end
57
-
58
- it "should return a response on passthrough" do
59
- transaction = Async::DNS::Transaction.new(server, query, question, IN::A, response)
60
-
61
- expect(transaction.response.answer.size).to be 0
62
-
63
- response = transaction.passthrough(resolver)
64
-
65
- expect(response.answer.length).to be > 0
66
- end
67
-
68
- it "should call the block with the response when invoking passthrough!" do
69
- transaction = Async::DNS::Transaction.new(server, query, question, IN::A, response)
70
-
71
- expect(transaction.response.answer.size).to be 0
72
-
73
- passthrough_response = nil
74
-
75
- transaction.passthrough!(resolver) do |response|
76
- passthrough_response = response
77
- end
78
-
79
- expect(passthrough_response.answer.length).to be > 0
80
- end
81
-
82
- it "should fail the request" do
83
- transaction = Async::DNS::Transaction.new(server, query, question, IN::A, response)
84
-
85
- transaction.fail! :NXDomain
86
-
87
- expect(transaction.response.rcode).to be Resolv::DNS::RCode::NXDomain
88
- end
89
-
90
- it "should return AAAA record" do
91
- transaction = Async::DNS::Transaction.new(server, query, question, IN::AAAA, response)
92
-
93
- expect(transaction.response.answer.size).to be 0
94
-
95
- transaction.passthrough!(resolver)
96
-
97
- expect(transaction.response.answer.first[2]).to be_kind_of IN::AAAA
98
- end
99
-
100
- it "should return MX record" do
101
- transaction = Async::DNS::Transaction.new(server,query,"google.com",IN::MX, response)
102
-
103
- expect(transaction.response.answer.size).to be 0
104
-
105
- transaction.passthrough!(resolver)
106
-
107
- expect(transaction.response.answer.first[2]).to be_kind_of IN::MX
108
- end
109
-
110
- it "should return NS record" do
111
- transaction = Async::DNS::Transaction.new(server, query, "google.com", IN::NS, response)
112
-
113
- expect(transaction.response.answer.size).to be 0
114
-
115
- transaction.passthrough!(resolver)
116
-
117
- expect(transaction.response.answer.first[2]).to be_kind_of IN::NS
118
- end
119
-
120
- it "should return PTR record" do
121
- transaction = Async::DNS::Transaction.new(server, query, "8.8.8.8.in-addr.arpa", IN::PTR, response)
122
-
123
- expect(transaction.response.answer.size).to be 0
124
-
125
- transaction.passthrough!(resolver)
126
-
127
- expect(transaction.response.answer.first[2]).to be_kind_of IN::PTR
128
- end
129
-
130
- it "should return SOA record" do
131
- transaction = Async::DNS::Transaction.new(server, query, "google.com", IN::SOA, response)
132
-
133
- expect(transaction.response.answer.size).to be 0
134
-
135
- transaction.passthrough!(resolver)
136
-
137
- expect(transaction.response.answer.first[2]).to be_kind_of IN::SOA
138
- end
139
- end
140
- end
@@ -1,61 +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/extensions/string'
25
-
26
- module Async::DNS::TruncationSpec
27
- SERVER_PORTS = [[:udp, '127.0.0.1', 5520], [:tcp, '127.0.0.1', 5520]]
28
- IN = Resolv::DNS::Resource::IN
29
-
30
- class TestServer < Async::DNS::Server
31
- def process(name, resource_class, transaction)
32
- case [name, resource_class]
33
- when ["truncation", IN::TXT]
34
- text = "Hello World! " * 100
35
- transaction.respond!(*text.chunked)
36
- else
37
- transaction.fail!(:NXDomain)
38
- end
39
- end
40
- end
41
-
42
- describe "Async::DNS Truncation Server" do
43
- include_context Async::RSpec::Reactor
44
-
45
- let(:server) {TestServer.new(SERVER_PORTS)}
46
-
47
- it "should use tcp because of large response" do
48
- task = server.run
49
-
50
- resolver = Async::DNS::Resolver.new(SERVER_PORTS)
51
-
52
- response = resolver.query("truncation", IN::TXT)
53
-
54
- text = response.answer.first
55
-
56
- expect(text[2].strings.join).to be == ("Hello World! " * 100)
57
-
58
- task.stop
59
- end
60
- end
61
- end