rubydns 0.6.0 → 2.0.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 +6 -14
- data/.gitignore +23 -14
- data/.rspec +4 -0
- data/.simplecov +15 -0
- data/.travis.yml +9 -5
- data/.yardopts +1 -0
- data/Gemfile +6 -2
- data/README.md +82 -92
- data/Rakefile +2 -5
- data/bin/rubydns-check +374 -0
- data/examples/Gemfile +7 -0
- data/examples/README.md +137 -0
- data/examples/basic-dns.rb +24 -0
- data/examples/cname.rb +25 -0
- data/{test/examples/dropping-dns.rb → examples/flakey-dns.rb} +28 -31
- data/{test/examples → examples}/fortune-dns.rb +42 -46
- data/examples/geoip-dns.rb +115 -0
- data/examples/simple.rb +25 -0
- data/{test/examples → examples}/soa-dns.rb +27 -27
- data/{test/examples → examples}/test-dns-1.rb +26 -20
- data/{test/examples → examples}/test-dns-2.rb +17 -19
- data/examples/wikipedia-dns.rb +107 -0
- data/lib/rubydns/rule_based_server.rb +180 -0
- data/lib/rubydns/version.rb +1 -1
- data/lib/rubydns.rb +13 -63
- data/rubydns.gemspec +29 -23
- data/spec/rubydns/daemon_spec.rb +114 -0
- data/{test/test_system.rb → spec/rubydns/injected_supervisor_spec.rb} +32 -25
- data/spec/rubydns/passthrough_spec.rb +85 -0
- data/spec/rubydns/rules_spec.rb +74 -0
- data/spec/spec_helper.rb +30 -0
- metadata +101 -78
- data/bin/rd-dns-check +0 -374
- data/bin/rd-resolve-test +0 -160
- data/lib/rubydns/chunked.rb +0 -34
- data/lib/rubydns/extensions/hexdump.rb +0 -38
- data/lib/rubydns/extensions/logger.rb +0 -30
- data/lib/rubydns/extensions/resolv.rb +0 -53
- data/lib/rubydns/extensions/string-1.8.rb +0 -35
- data/lib/rubydns/extensions/string-1.9.2.rb +0 -29
- data/lib/rubydns/extensions/string-1.9.3.rb +0 -31
- data/lib/rubydns/extensions/string.rb +0 -27
- data/lib/rubydns/handler.rb +0 -140
- data/lib/rubydns/message.rb +0 -41
- data/lib/rubydns/resolver.rb +0 -239
- data/lib/rubydns/server.rb +0 -241
- data/lib/rubydns/system.rb +0 -146
- data/lib/rubydns/transaction.rb +0 -250
- data/test/examples/geoip-dns.rb +0 -86
- data/test/helper.rb +0 -9
- data/test/test_daemon.rb +0 -100
- data/test/test_domains.txt +0 -185
- data/test/test_passthrough.rb +0 -80
- data/test/test_resolver.rb +0 -105
- data/test/test_rules.rb +0 -74
- data/test/test_slow_server.rb +0 -98
- data/test/test_truncation.rb +0 -78
- /data/{test → spec/rubydns}/hosts.txt +0 -0
data/test/test_resolver.rb
DELETED
|
@@ -1,105 +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 'helper'
|
|
24
|
-
require 'rubydns'
|
|
25
|
-
|
|
26
|
-
class ResolverTest < Test::Unit::TestCase
|
|
27
|
-
def test_basic_resolver
|
|
28
|
-
resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
|
29
|
-
|
|
30
|
-
EventMachine::run do
|
|
31
|
-
resolver.query('google.com') do |response|
|
|
32
|
-
assert_equal RubyDNS::Message, response.class
|
|
33
|
-
EventMachine::stop
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
EventMachine::run do
|
|
38
|
-
resolver.query('nonexistant.private') do |response|
|
|
39
|
-
assert_equal response.rcode, Resolv::DNS::RCode::NXDomain
|
|
40
|
-
EventMachine::stop
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_broken_resolver
|
|
46
|
-
resolver = RubyDNS::Resolver.new([])
|
|
47
|
-
|
|
48
|
-
EventMachine::run do
|
|
49
|
-
resolver.query('google.com') do |response|
|
|
50
|
-
assert_equal RubyDNS::ResolutionFailure, response.class
|
|
51
|
-
|
|
52
|
-
EventMachine::stop
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class MockRequest
|
|
58
|
-
attr :response
|
|
59
|
-
|
|
60
|
-
def process_response!(response)
|
|
61
|
-
@response = response
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_dirty_packets_udp
|
|
66
|
-
mock_request = MockRequest.new
|
|
67
|
-
|
|
68
|
-
handler_class = Class.new{ include RubyDNS::Resolver::Request::UDPRequestHandler }
|
|
69
|
-
handler = handler_class.new(mock_request, nil, nil)
|
|
70
|
-
|
|
71
|
-
handler.receive_data("This is not a real message!")
|
|
72
|
-
|
|
73
|
-
assert_equal Resolv::DNS::DecodeError, mock_request.response.class
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_dirty_packets_tcp
|
|
77
|
-
mock_request = MockRequest.new
|
|
78
|
-
|
|
79
|
-
handler_class = Class.new{ include RubyDNS::Resolver::Request::TCPRequestHandler }
|
|
80
|
-
handler = handler_class.new(mock_request)
|
|
81
|
-
|
|
82
|
-
data = "This is not a real message!"
|
|
83
|
-
handler.receive_data([data.length].pack('n') + data)
|
|
84
|
-
|
|
85
|
-
assert_equal Resolv::DNS::DecodeError, mock_request.response.class
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def test_addresses_for
|
|
89
|
-
resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
|
90
|
-
resolved_addresses = nil
|
|
91
|
-
|
|
92
|
-
EventMachine::run do
|
|
93
|
-
resolver.addresses_for("www.google.com.") do |addresses|
|
|
94
|
-
resolved_addresses = addresses
|
|
95
|
-
|
|
96
|
-
EventMachine::stop
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
assert resolved_addresses.count > 0
|
|
101
|
-
|
|
102
|
-
address = resolved_addresses[0]
|
|
103
|
-
assert address.kind_of?(Resolv::IPv4) || address.kind_of?(Resolv::IPv6)
|
|
104
|
-
end
|
|
105
|
-
end
|
data/test/test_rules.rb
DELETED
|
@@ -1,74 +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 'helper'
|
|
24
|
-
require 'pathname'
|
|
25
|
-
|
|
26
|
-
require 'rubydns'
|
|
27
|
-
require 'rubydns/resolver'
|
|
28
|
-
require 'rubydns/extensions/string'
|
|
29
|
-
|
|
30
|
-
class RulesTest < Test::Unit::TestCase
|
|
31
|
-
IN = Resolv::DNS::Resource::IN
|
|
32
|
-
|
|
33
|
-
def setup
|
|
34
|
-
@server = RubyDNS::Server.new
|
|
35
|
-
@true_callback = Proc.new { true }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def teardown
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def test_string_pattern
|
|
42
|
-
rule = RubyDNS::Server::Rule.new(["foobar", IN::A], @true_callback)
|
|
43
|
-
|
|
44
|
-
assert rule.call(@server, "foobar", IN::A)
|
|
45
|
-
assert !rule.call(@server, "barfoo", IN::A)
|
|
46
|
-
assert !rule.call(@server, "foobar", IN::TXT)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_regexp_pattern
|
|
50
|
-
rule = RubyDNS::Server::Rule.new([/foo/, IN::A], @true_callback)
|
|
51
|
-
|
|
52
|
-
assert rule.call(@server, "foobar", IN::A)
|
|
53
|
-
assert !rule.call(@server, "barbaz", IN::A)
|
|
54
|
-
assert !rule.call(@server, "foobar", IN::TXT)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_callback_pattern
|
|
58
|
-
calls = 0
|
|
59
|
-
|
|
60
|
-
callback = Proc.new do |name, resource_class|
|
|
61
|
-
# A counter used to check the number of times this block was invoked.
|
|
62
|
-
calls += 1
|
|
63
|
-
|
|
64
|
-
name.size == 6
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
rule = RubyDNS::Server::Rule.new([callback], @true_callback)
|
|
68
|
-
|
|
69
|
-
assert rule.call(@server, "foobar", IN::A)
|
|
70
|
-
assert !rule.call(@server, "foobarbaz", IN::A)
|
|
71
|
-
|
|
72
|
-
assert_equal 2, calls
|
|
73
|
-
end
|
|
74
|
-
end
|
data/test/test_slow_server.rb
DELETED
|
@@ -1,98 +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 'helper'
|
|
24
|
-
require 'pathname'
|
|
25
|
-
|
|
26
|
-
require 'rubydns'
|
|
27
|
-
require 'rubydns/resolver'
|
|
28
|
-
require 'rubydns/extensions/string'
|
|
29
|
-
|
|
30
|
-
class SlowServer < RExec::Daemon::Base
|
|
31
|
-
SERVER_PORTS = [[:udp, '127.0.0.1', 5330], [:tcp, '127.0.0.1', 5330]]
|
|
32
|
-
|
|
33
|
-
@@base_directory = File.dirname(__FILE__)
|
|
34
|
-
|
|
35
|
-
Name = Resolv::DNS::Name
|
|
36
|
-
IN = Resolv::DNS::Resource::IN
|
|
37
|
-
|
|
38
|
-
def self.run
|
|
39
|
-
RubyDNS::run_server(:listen => SERVER_PORTS) do
|
|
40
|
-
match(/\.*.com/, IN::A) do |transaction|
|
|
41
|
-
transaction.defer!
|
|
42
|
-
|
|
43
|
-
# No domain exists, after 5 seconds:
|
|
44
|
-
EventMachine::Timer.new(2) do
|
|
45
|
-
transaction.failure!(:NXDomain)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
otherwise do |transaction|
|
|
50
|
-
transaction.failure!(:NXDomain)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
class SlowServerTest < Test::Unit::TestCase
|
|
57
|
-
def setup
|
|
58
|
-
SlowServer.start
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def teardown
|
|
62
|
-
SlowServer.stop
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_slow_request
|
|
66
|
-
start_time = Time.now
|
|
67
|
-
end_time = nil
|
|
68
|
-
|
|
69
|
-
resolver = RubyDNS::Resolver.new(SlowServer::SERVER_PORTS, :timeout => 10)
|
|
70
|
-
|
|
71
|
-
EventMachine::run do
|
|
72
|
-
resolver.query("apple.com", IN::A) do |response|
|
|
73
|
-
end_time = Time.now
|
|
74
|
-
|
|
75
|
-
EventMachine::stop
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
assert (end_time - start_time) > 2.0
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_normal_request
|
|
83
|
-
start_time = Time.now
|
|
84
|
-
end_time = nil
|
|
85
|
-
|
|
86
|
-
resolver = RubyDNS::Resolver.new(SlowServer::SERVER_PORTS, :timeout => 10)
|
|
87
|
-
|
|
88
|
-
EventMachine::run do
|
|
89
|
-
resolver.query("oriontransfer.org", IN::A) do |response|
|
|
90
|
-
end_time = Time.now
|
|
91
|
-
|
|
92
|
-
EventMachine::stop
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
assert (end_time - start_time) < 2.0
|
|
97
|
-
end
|
|
98
|
-
end
|
data/test/test_truncation.rb
DELETED
|
@@ -1,78 +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 'helper'
|
|
24
|
-
require 'pathname'
|
|
25
|
-
|
|
26
|
-
require 'rubydns'
|
|
27
|
-
require 'rubydns/resolver'
|
|
28
|
-
require 'rubydns/extensions/string'
|
|
29
|
-
|
|
30
|
-
class TruncatedServer < RExec::Daemon::Base
|
|
31
|
-
SERVER_PORTS = [[:udp, '127.0.0.1', 5320], [:tcp, '127.0.0.1', 5320]]
|
|
32
|
-
|
|
33
|
-
@@base_directory = File.dirname(__FILE__)
|
|
34
|
-
|
|
35
|
-
Name = Resolv::DNS::Name
|
|
36
|
-
IN = Resolv::DNS::Resource::IN
|
|
37
|
-
|
|
38
|
-
def self.run
|
|
39
|
-
# Start the RubyDNS server
|
|
40
|
-
RubyDNS::run_server(:listen => SERVER_PORTS) do
|
|
41
|
-
match("truncation", IN::TXT) do |transaction|
|
|
42
|
-
text = "Hello World! " * 100
|
|
43
|
-
transaction.respond!(*text.chunked)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Default DNS handler
|
|
47
|
-
otherwise do |transaction|
|
|
48
|
-
transaction.failure!(:NXDomain)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
class TruncationTest < Test::Unit::TestCase
|
|
55
|
-
def setup
|
|
56
|
-
TruncatedServer.start
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def teardown
|
|
60
|
-
TruncatedServer.stop
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def test_tcp_failover
|
|
64
|
-
resolver = RubyDNS::Resolver.new(TruncatedServer::SERVER_PORTS)
|
|
65
|
-
|
|
66
|
-
EventMachine::run do
|
|
67
|
-
resolver.query("truncation", IN::TXT) do |response|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
text = response.answer.first
|
|
71
|
-
|
|
72
|
-
assert_equal "Hello World! " * 100, text[2].strings.join
|
|
73
|
-
|
|
74
|
-
EventMachine::stop
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
File without changes
|