async-dns 0.10.0
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.
- checksums.yaml +7 -0
- data/.rspec +4 -0
- data/.travis.yml +18 -0
- data/Gemfile +14 -0
- data/README.md +144 -0
- data/Rakefile +32 -0
- data/async-dns.gemspec +31 -0
- data/lib/async/dns.rb +36 -0
- data/lib/async/dns/chunked.rb +34 -0
- data/lib/async/dns/extensions/resolv.rb +136 -0
- data/lib/async/dns/extensions/string.rb +28 -0
- data/lib/async/dns/handler.rb +229 -0
- data/lib/async/dns/logger.rb +31 -0
- data/lib/async/dns/message.rb +75 -0
- data/lib/async/dns/replace.rb +54 -0
- data/lib/async/dns/resolver.rb +280 -0
- data/lib/async/dns/server.rb +154 -0
- data/lib/async/dns/system.rb +146 -0
- data/lib/async/dns/transaction.rb +202 -0
- data/lib/async/dns/transport.rb +78 -0
- data/lib/async/dns/version.rb +25 -0
- data/spec/async/dns/handler_spec.rb +58 -0
- data/spec/async/dns/hosts.txt +2 -0
- data/spec/async/dns/ipv6_spec.rb +78 -0
- data/spec/async/dns/message_spec.rb +56 -0
- data/spec/async/dns/origin_spec.rb +106 -0
- data/spec/async/dns/replace_spec.rb +44 -0
- data/spec/async/dns/resolver_performance_spec.rb +110 -0
- data/spec/async/dns/resolver_spec.rb +151 -0
- data/spec/async/dns/server/bind9/generate-local.rb +25 -0
- data/spec/async/dns/server/bind9/local.zone +5014 -0
- data/spec/async/dns/server/bind9/named.conf +14 -0
- data/spec/async/dns/server/bind9/named.run +0 -0
- data/spec/async/dns/server/million.rb +85 -0
- data/spec/async/dns/server_performance_spec.rb +138 -0
- data/spec/async/dns/slow_server_spec.rb +97 -0
- data/spec/async/dns/socket_spec.rb +70 -0
- data/spec/async/dns/system_spec.rb +57 -0
- data/spec/async/dns/transaction_spec.rb +140 -0
- data/spec/async/dns/truncation_spec.rb +61 -0
- data/spec/spec_helper.rb +60 -0
- metadata +175 -0
@@ -0,0 +1,140 @@
|
|
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 "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
|
@@ -0,0 +1,61 @@
|
|
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 "reactor"
|
44
|
+
|
45
|
+
let(:server) {TestServer.new(listen: 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
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
if ENV['COVERAGE'] || ENV['TRAVIS']
|
3
|
+
begin
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter "/spec/"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Work correctly across forks:
|
11
|
+
pid = Process.pid
|
12
|
+
SimpleCov.at_exit do
|
13
|
+
SimpleCov.result.format! if Process.pid == pid
|
14
|
+
end
|
15
|
+
|
16
|
+
if ENV['TRAVIS']
|
17
|
+
require 'coveralls'
|
18
|
+
Coveralls.wear!
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
warn "Could not load simplecov: #{$!}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
require "bundler/setup"
|
26
|
+
require "pry"
|
27
|
+
require "async/dns"
|
28
|
+
require "pp"
|
29
|
+
|
30
|
+
RSpec.shared_context "reactor" do
|
31
|
+
let(:reactor) {Async::Reactor.new}
|
32
|
+
|
33
|
+
around(:each) do |example|
|
34
|
+
result = nil
|
35
|
+
|
36
|
+
reactor.run do
|
37
|
+
result = example.run
|
38
|
+
|
39
|
+
# Force the reactor to stop running if the result was an error.
|
40
|
+
if result.is_a? Exception
|
41
|
+
reactor.stop
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
reactor.close
|
46
|
+
|
47
|
+
result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# abort "Warning, ulimit is too low!" if `ulimit -n`.to_i < 10000
|
52
|
+
|
53
|
+
RSpec.configure do |config|
|
54
|
+
# Enable flags like --only-failures and --next-failure
|
55
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
56
|
+
|
57
|
+
config.expect_with :rspec do |c|
|
58
|
+
c.syntax = :expect
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: async-dns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: async
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: process-daemon
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.4.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.4.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: "\t\tAsync::DNS provides a high-performance DNS client resolver and server\n\t\twhich
|
84
|
+
can be easily integrated into other projects or used as a stand-alone\n\t\tdaemon.\n"
|
85
|
+
email:
|
86
|
+
- samuel.williams@oriontransfer.co.nz
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- async-dns.gemspec
|
97
|
+
- lib/async/dns.rb
|
98
|
+
- lib/async/dns/chunked.rb
|
99
|
+
- lib/async/dns/extensions/resolv.rb
|
100
|
+
- lib/async/dns/extensions/string.rb
|
101
|
+
- lib/async/dns/handler.rb
|
102
|
+
- lib/async/dns/logger.rb
|
103
|
+
- lib/async/dns/message.rb
|
104
|
+
- lib/async/dns/replace.rb
|
105
|
+
- lib/async/dns/resolver.rb
|
106
|
+
- lib/async/dns/server.rb
|
107
|
+
- lib/async/dns/system.rb
|
108
|
+
- lib/async/dns/transaction.rb
|
109
|
+
- lib/async/dns/transport.rb
|
110
|
+
- lib/async/dns/version.rb
|
111
|
+
- spec/async/dns/handler_spec.rb
|
112
|
+
- spec/async/dns/hosts.txt
|
113
|
+
- spec/async/dns/ipv6_spec.rb
|
114
|
+
- spec/async/dns/message_spec.rb
|
115
|
+
- spec/async/dns/origin_spec.rb
|
116
|
+
- spec/async/dns/replace_spec.rb
|
117
|
+
- spec/async/dns/resolver_performance_spec.rb
|
118
|
+
- spec/async/dns/resolver_spec.rb
|
119
|
+
- spec/async/dns/server/bind9/generate-local.rb
|
120
|
+
- spec/async/dns/server/bind9/local.zone
|
121
|
+
- spec/async/dns/server/bind9/named.conf
|
122
|
+
- spec/async/dns/server/bind9/named.run
|
123
|
+
- spec/async/dns/server/million.rb
|
124
|
+
- spec/async/dns/server_performance_spec.rb
|
125
|
+
- spec/async/dns/slow_server_spec.rb
|
126
|
+
- spec/async/dns/socket_spec.rb
|
127
|
+
- spec/async/dns/system_spec.rb
|
128
|
+
- spec/async/dns/transaction_spec.rb
|
129
|
+
- spec/async/dns/truncation_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: https://github.com/async/async-dns
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.6.10
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: An easy to use DNS client resolver and server for Ruby.
|
155
|
+
test_files:
|
156
|
+
- spec/async/dns/handler_spec.rb
|
157
|
+
- spec/async/dns/hosts.txt
|
158
|
+
- spec/async/dns/ipv6_spec.rb
|
159
|
+
- spec/async/dns/message_spec.rb
|
160
|
+
- spec/async/dns/origin_spec.rb
|
161
|
+
- spec/async/dns/replace_spec.rb
|
162
|
+
- spec/async/dns/resolver_performance_spec.rb
|
163
|
+
- spec/async/dns/resolver_spec.rb
|
164
|
+
- spec/async/dns/server/bind9/generate-local.rb
|
165
|
+
- spec/async/dns/server/bind9/local.zone
|
166
|
+
- spec/async/dns/server/bind9/named.conf
|
167
|
+
- spec/async/dns/server/bind9/named.run
|
168
|
+
- spec/async/dns/server/million.rb
|
169
|
+
- spec/async/dns/server_performance_spec.rb
|
170
|
+
- spec/async/dns/slow_server_spec.rb
|
171
|
+
- spec/async/dns/socket_spec.rb
|
172
|
+
- spec/async/dns/system_spec.rb
|
173
|
+
- spec/async/dns/transaction_spec.rb
|
174
|
+
- spec/async/dns/truncation_spec.rb
|
175
|
+
- spec/spec_helper.rb
|