rubydns 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/Gemfile +1 -1
- data/README.md +9 -4
- data/lib/rubydns/binary_string.rb +0 -1
- data/lib/rubydns/extensions/string.rb +1 -1
- data/lib/rubydns/handler.rb +2 -2
- data/lib/rubydns/{extensions/logger.rb → logger.rb} +2 -1
- data/lib/rubydns/message.rb +2 -1
- data/lib/rubydns/resolver.rb +2 -2
- data/lib/rubydns/server.rb +7 -7
- data/lib/rubydns/version.rb +1 -1
- data/lib/rubydns.rb +5 -15
- data/rubydns.gemspec +7 -5
- data/test/examples/dropping-dns.rb +3 -9
- data/test/examples/fortune-dns.rb +3 -4
- data/test/examples/geoip-dns.rb +3 -9
- data/test/examples/test-dns-2.rb +3 -5
- data/test/examples/wikipedia-dns.rb +4 -9
- data/test/test_daemon.rb +11 -12
- data/test/test_message.rb +48 -24
- data/test/test_passthrough.rb +31 -23
- data/test/test_resolver.rb +3 -2
- data/test/test_rules.rb +6 -6
- data/test/test_slow_server.rb +17 -12
- data/test/test_system.rb +2 -5
- data/test/test_truncation.rb +18 -9
- metadata +44 -18
- data/test/helper.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca335a666974f8ec5e2a9c3cfe075e2d156593f0
|
4
|
+
data.tar.gz: ff3d9313d716dcf7c25cf40272fc97e7a36c508e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4603602b5a55406025fb7064a6e4ed002bbeec6216397f458ca1f0105eeecda08d90d66cc360440cbdd8e3d172e38cad114130a988ec9830919ade26e0339506
|
7
|
+
data.tar.gz: 9f9efda65a0c352060278fb229f4d61b9a35514b13e4fab35ad996bb3a37dfc973589ea1614e928230828b47b648f2418c1aeabef67b4f7b50612f06ef3dfd05
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# RubyDNS
|
2
2
|
|
3
|
-
RubyDNS is a high-performance DNS server which can be easily integrated into other projects or used as a stand-alone daemon
|
3
|
+
RubyDNS is a high-performance DNS server which can be easily integrated into other projects or used as a stand-alone daemon. By default it uses rule-based pattern matching. Results can be hard-coded, computed, fetched from a remote DNS server or fetched from a local cache, depending on requirements.
|
4
4
|
|
5
5
|
In addition, RubyDNS includes a high-performance asynchronous DNS resolver built on top of EventMachine. This module can be used by itself in client applications without using the full RubyDNS server stack.
|
6
6
|
|
7
7
|
For examples and documentation please see the main [project page][1].
|
8
8
|
|
9
|
-
[1]: http://www.
|
9
|
+
[1]: http://www.codeotaku.com/projects/rubydns/
|
10
10
|
|
11
|
-
[![Build Status](https://
|
11
|
+
[![Build Status](https://travis-ci.org/ioquatix/rubydns.svg)](https://travis-ci.org/ioquatix/rubydns)
|
12
12
|
[![Code Climate](https://codeclimate.com/github/ioquatix/rubydns.png)](https://codeclimate.com/github/ioquatix/rubydns)
|
13
13
|
|
14
14
|
## Installation
|
@@ -42,7 +42,7 @@ This is copied from `test/examples/test-dns-2.rb`. It has been simplified slight
|
|
42
42
|
# Use upstream DNS for name resolution.
|
43
43
|
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
44
44
|
|
45
|
-
def
|
45
|
+
def startup
|
46
46
|
# Start the RubyDNS server
|
47
47
|
RubyDNS::run_server(:listen => INTERFACES) do
|
48
48
|
match(/test.mydomain.org/, IN::A) do |transaction|
|
@@ -81,6 +81,10 @@ This is the best way to integrate with other projects.
|
|
81
81
|
|
82
82
|
## Compatibility
|
83
83
|
|
84
|
+
### Migrating from RubyDNS 0.7.x to 0.8.x
|
85
|
+
|
86
|
+
The primary change is the removal of the dependency on `RExec` which was used for daemons and the addition of the testing dependency `process-daemon`. In order to create and run your own daemon, you may use `process-daemon` or another tool of your choice.
|
87
|
+
|
84
88
|
### Migrating from RubyDNS 0.6.x to 0.7.x
|
85
89
|
|
86
90
|
The asynchronous deferred processing became the default and only method for processing requests in `0.7.0`. This simplifies the API but there were a few changes, notably the removal of `defer!` and the addition of `defer`. The reason for this was due to issues relating to deferred processing and the flow of control, which were confusing and introduced bugs in specific situations. Now, you can assume flow control through the entire block even with non-blocking functions.
|
@@ -180,6 +184,7 @@ becomes
|
|
180
184
|
|
181
185
|
* Support for more features of DNS such as zone transfer.
|
182
186
|
* Support reverse records more easily.
|
187
|
+
* Some kind of system level integration, e.g. registering a DNS server with the currently running system resolver.
|
183
188
|
|
184
189
|
## License
|
185
190
|
|
data/lib/rubydns/handler.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
require_relative 'message'
|
22
|
+
require_relative 'binary_string'
|
23
23
|
|
24
24
|
module RubyDNS
|
25
25
|
# @returns the [port, ip address] of the given connection.
|
@@ -18,6 +18,8 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
+
require 'logger'
|
22
|
+
|
21
23
|
module RubyDNS
|
22
24
|
# Logs an exception nicely to a standard `Logger`.
|
23
25
|
def self.log_exception(logger, exception)
|
@@ -25,6 +27,5 @@ module RubyDNS
|
|
25
27
|
if exception.backtrace
|
26
28
|
Array(exception.backtrace).each { |at| logger.error at }
|
27
29
|
end
|
28
|
-
|
29
30
|
end
|
30
31
|
end
|
data/lib/rubydns/message.rb
CHANGED
data/lib/rubydns/resolver.rb
CHANGED
@@ -18,8 +18,8 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
require_relative 'message'
|
22
|
+
require_relative 'binary_string'
|
23
23
|
|
24
24
|
module RubyDNS
|
25
25
|
class InvalidProtocolError < StandardError
|
data/lib/rubydns/server.rb
CHANGED
@@ -20,8 +20,8 @@
|
|
20
20
|
|
21
21
|
require 'fiber'
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
require_relative 'transaction'
|
24
|
+
require_relative 'logger'
|
25
25
|
|
26
26
|
module RubyDNS
|
27
27
|
|
@@ -37,8 +37,8 @@ module RubyDNS
|
|
37
37
|
# end
|
38
38
|
# end
|
39
39
|
#
|
40
|
-
def initialize
|
41
|
-
@logger = Logger.new($stderr)
|
40
|
+
def initialize(options)
|
41
|
+
@logger = options[:logger] || Logger.new($stderr)
|
42
42
|
end
|
43
43
|
|
44
44
|
attr_accessor :logger
|
@@ -208,8 +208,8 @@ module RubyDNS
|
|
208
208
|
# end
|
209
209
|
# end
|
210
210
|
#
|
211
|
-
def initialize(&block)
|
212
|
-
super()
|
211
|
+
def initialize(options = {}, &block)
|
212
|
+
super(options)
|
213
213
|
|
214
214
|
@events = {}
|
215
215
|
@rules = []
|
@@ -235,7 +235,7 @@ module RubyDNS
|
|
235
235
|
# Register a named event which may be invoked later using #fire
|
236
236
|
#
|
237
237
|
# on(:start) do |server|
|
238
|
-
#
|
238
|
+
# Process::Daemon::Permissions.change_user(RUN_AS)
|
239
239
|
# end
|
240
240
|
def on(event_name, &block)
|
241
241
|
@events[event_name] = block
|
data/lib/rubydns/version.rb
CHANGED
data/lib/rubydns.rb
CHANGED
@@ -18,22 +18,14 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
|
21
|
+
require_relative 'rubydns/version'
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
require 'logger'
|
29
|
-
|
30
|
-
require 'rexec'
|
31
|
-
require 'rexec/daemon'
|
32
|
-
|
33
|
-
require 'rubydns/handler'
|
23
|
+
require_relative 'rubydns/message'
|
24
|
+
require_relative 'rubydns/server'
|
25
|
+
require_relative 'rubydns/resolver'
|
26
|
+
require_relative 'rubydns/handler'
|
34
27
|
|
35
28
|
module RubyDNS
|
36
|
-
|
37
29
|
# Run a server with the given rules.
|
38
30
|
def self.run_server (options = {}, &block)
|
39
31
|
server = RubyDNS::RuleBasedServer.new(&block)
|
@@ -44,6 +36,4 @@ module RubyDNS
|
|
44
36
|
|
45
37
|
server.fire(:stop)
|
46
38
|
end
|
47
|
-
|
48
|
-
|
49
39
|
end
|
data/rubydns.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
11
|
spec.description = <<-EOF
|
12
12
|
RubyDNS is a high-performance DNS server which can be easily integrated into
|
13
|
-
other projects or used as a stand-alone daemon
|
13
|
+
other projects or used as a stand-alone daemon. By default it uses
|
14
14
|
rule-based pattern matching. Results can be hard-coded, computed, fetched from
|
15
15
|
a remote DNS server or fetched from a local cache, depending on requirements.
|
16
16
|
|
@@ -26,11 +26,13 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
27
27
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
28
28
|
spec.require_paths = ["lib"]
|
29
|
-
|
29
|
+
spec.has_rdoc = "yard"
|
30
|
+
|
30
31
|
spec.required_ruby_version = '>= 1.9.3'
|
31
32
|
|
32
|
-
spec.add_dependency("rexec", "~> 1.6.2")
|
33
33
|
spec.add_dependency("eventmachine", "~> 1.0.0")
|
34
|
-
|
35
|
-
spec.
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
36
|
+
spec.add_development_dependency "process-daemon", "~> 0.5.0"
|
37
|
+
spec.add_development_dependency "rake"
|
36
38
|
end
|
@@ -20,22 +20,16 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require '
|
23
|
+
require 'process/daemon'
|
24
24
|
|
25
|
-
require 'rexec'
|
26
|
-
require 'rexec/daemon'
|
27
|
-
|
28
|
-
require 'rubygems'
|
29
25
|
require 'rubydns'
|
30
|
-
|
31
|
-
require 'rubydns/resolver'
|
32
26
|
require 'rubydns/system'
|
33
27
|
|
34
28
|
INTERFACES = [
|
35
29
|
[:udp, "0.0.0.0", 5300]
|
36
30
|
]
|
37
31
|
|
38
|
-
class DroppingDaemon <
|
32
|
+
class DroppingDaemon < Process::Daemon
|
39
33
|
# You can specify a specific directory to use for run-time information (pid, logs, etc):
|
40
34
|
# @@base_directory = File.expand_path("../", __FILE__)
|
41
35
|
# @@base_directory = "/var"
|
@@ -44,7 +38,7 @@ class DroppingDaemon < RExec::Daemon::Base
|
|
44
38
|
IN = Resolv::DNS::Resource::IN
|
45
39
|
R = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
|
46
40
|
|
47
|
-
def
|
41
|
+
def startup
|
48
42
|
RubyDNS::run_server(:listen => INTERFACES) do
|
49
43
|
# Fail the resolution of certain domains ;)
|
50
44
|
match(/(m?i?c?r?o?s?o?f?t)/) do |transaction, match_data|
|
@@ -23,8 +23,7 @@
|
|
23
23
|
|
24
24
|
require 'rubygems'
|
25
25
|
|
26
|
-
require '
|
27
|
-
require 'rexec/daemon'
|
26
|
+
require 'process/daemon'
|
28
27
|
|
29
28
|
require 'rubygems'
|
30
29
|
|
@@ -43,13 +42,13 @@ end
|
|
43
42
|
|
44
43
|
# To use, start the daemon and try:
|
45
44
|
# dig @localhost fortune CNAME
|
46
|
-
class FortuneDNS <
|
45
|
+
class FortuneDNS < Process::Daemon
|
47
46
|
@@base_directory = File.dirname(__FILE__)
|
48
47
|
|
49
48
|
Name = Resolv::DNS::Name
|
50
49
|
IN = Resolv::DNS::Resource::IN
|
51
50
|
|
52
|
-
def
|
51
|
+
def startup
|
53
52
|
# Don't buffer output (for debug purposes)
|
54
53
|
$stderr.sync = true
|
55
54
|
|
data/test/examples/geoip-dns.rb
CHANGED
@@ -20,17 +20,11 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require 'rubygems'
|
24
|
-
|
25
23
|
require 'geoip'
|
26
24
|
|
27
|
-
require '
|
28
|
-
require 'rexec/daemon'
|
25
|
+
require 'process-daemon'
|
29
26
|
|
30
|
-
require 'rubygems'
|
31
27
|
require 'rubydns'
|
32
|
-
|
33
|
-
require 'rubydns/resolver'
|
34
28
|
require 'rubydns/system'
|
35
29
|
|
36
30
|
INTERFACES = [
|
@@ -40,7 +34,7 @@ INTERFACES = [
|
|
40
34
|
# This daemon requires the file downloaded from http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
|
41
35
|
# For more information, please see http://www.maxmind.com/en/geolite and http://geoip.rubyforge.org
|
42
36
|
|
43
|
-
class GeoIPDNSDaemon <
|
37
|
+
class GeoIPDNSDaemon < Process::Daemon
|
44
38
|
# You can specify a specific directory to use for run-time information (pid, logs, etc):
|
45
39
|
# @@base_directory = File.expand_path("../", __FILE__)
|
46
40
|
# @@base_directory = "/var"
|
@@ -50,7 +44,7 @@ class GeoIPDNSDaemon < RExec::Daemon::Base
|
|
50
44
|
R = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
|
51
45
|
GEO = GeoIP.new(File.expand_path('../GeoLiteCountry.dat', __FILE__))
|
52
46
|
|
53
|
-
def
|
47
|
+
def startup
|
54
48
|
RubyDNS::run_server(:listen => INTERFACES) do
|
55
49
|
match(//, IN::A) do |transaction|
|
56
50
|
location = nil
|
data/test/examples/test-dns-2.rb
CHANGED
@@ -20,10 +20,8 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require 'rubygems'
|
24
|
-
require 'rexec'
|
25
|
-
require 'rexec/daemon'
|
26
23
|
require 'rubydns'
|
24
|
+
require 'process-daemon'
|
27
25
|
|
28
26
|
# To run this command, use the standard daemon syntax as root
|
29
27
|
# ./daemon2.rb start
|
@@ -51,14 +49,14 @@ if RExec.current_user != "root"
|
|
51
49
|
end
|
52
50
|
|
53
51
|
# The Daemon itself
|
54
|
-
class Server <
|
52
|
+
class Server < Process::Daemon
|
55
53
|
Name = Resolv::DNS::Name
|
56
54
|
IN = Resolv::DNS::Resource::IN
|
57
55
|
|
58
56
|
# Use upstream DNS for name resolution.
|
59
57
|
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
60
58
|
|
61
|
-
def
|
59
|
+
def startup
|
62
60
|
# Don't buffer output (for debug purposes)
|
63
61
|
$stderr.sync = true
|
64
62
|
|
@@ -21,16 +21,11 @@
|
|
21
21
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
22
|
# THE SOFTWARE.
|
23
23
|
|
24
|
-
require 'rubygems'
|
25
|
-
|
26
|
-
require 'rexec'
|
27
|
-
require 'rexec/daemon'
|
28
|
-
|
29
|
-
require 'rubygems'
|
30
|
-
|
31
24
|
require 'rubydns'
|
32
25
|
require 'rubydns/extensions/string'
|
33
26
|
|
27
|
+
require 'process/daemon'
|
28
|
+
|
34
29
|
require 'em-http'
|
35
30
|
require 'cgi'
|
36
31
|
require 'nokogiri'
|
@@ -61,13 +56,13 @@ end
|
|
61
56
|
|
62
57
|
# To use, start the daemon and try:
|
63
58
|
# dig @localhost fortune CNAME
|
64
|
-
class WikipediaDNS <
|
59
|
+
class WikipediaDNS < Process::Daemon
|
65
60
|
@@base_directory = File.dirname(__FILE__)
|
66
61
|
|
67
62
|
Name = Resolv::DNS::Name
|
68
63
|
IN = Resolv::DNS::Resource::IN
|
69
64
|
|
70
|
-
def
|
65
|
+
def startup
|
71
66
|
# Don't buffer output (for debug purposes)
|
72
67
|
$stderr.sync = true
|
73
68
|
|
data/test/test_daemon.rb
CHANGED
@@ -20,21 +20,20 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require '
|
24
|
-
require 'pathname'
|
23
|
+
require 'minitest/autorun'
|
25
24
|
|
26
25
|
require 'rubydns'
|
27
|
-
require 'rubydns/resolver'
|
28
26
|
|
29
|
-
require '
|
30
|
-
require 'rexec/daemon'
|
27
|
+
require 'process/daemon'
|
31
28
|
|
32
|
-
class BasicTestServer <
|
29
|
+
class BasicTestServer < Process::Daemon
|
33
30
|
SERVER_PORTS = [[:udp, '127.0.0.1', 5350], [:tcp, '127.0.0.1', 5350]]
|
34
31
|
|
35
32
|
@@base_directory = File.dirname(__FILE__)
|
36
33
|
|
37
|
-
|
34
|
+
IN = Resolv::DNS::Resource::IN
|
35
|
+
|
36
|
+
def startup
|
38
37
|
# Start the RubyDNS server
|
39
38
|
RubyDNS::run_server(:listen => SERVER_PORTS) do
|
40
39
|
match("test.local", IN::A) do |transaction|
|
@@ -53,19 +52,19 @@ class BasicTestServer < RExec::Daemon::Base
|
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
|
-
class DaemonTest < Test
|
55
|
+
class DaemonTest < MiniTest::Test
|
57
56
|
def setup
|
58
|
-
|
57
|
+
BasicTestServer.controller output: File.open("/dev/null", "w")
|
58
|
+
|
59
59
|
BasicTestServer.start
|
60
60
|
end
|
61
61
|
|
62
62
|
def teardown
|
63
|
-
$stderr.puts "Stoping test server..."
|
64
63
|
BasicTestServer.stop
|
65
64
|
end
|
66
65
|
|
67
66
|
def test_basic_dns
|
68
|
-
assert_equal :running,
|
67
|
+
assert_equal :running, BasicTestServer.status
|
69
68
|
|
70
69
|
EventMachine.run do
|
71
70
|
resolver = RubyDNS::Resolver.new(BasicTestServer::SERVER_PORTS)
|
@@ -82,7 +81,7 @@ class DaemonTest < Test::Unit::TestCase
|
|
82
81
|
end
|
83
82
|
|
84
83
|
def test_pattern_matching
|
85
|
-
assert_equal :running,
|
84
|
+
assert_equal :running, BasicTestServer.status
|
86
85
|
|
87
86
|
EventMachine.run do
|
88
87
|
resolver = RubyDNS::Resolver.new(BasicTestServer::SERVER_PORTS)
|
data/test/test_message.rb
CHANGED
@@ -1,41 +1,65 @@
|
|
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 'minitest/autorun'
|
24
|
+
|
1
25
|
require 'rubydns'
|
2
26
|
|
3
|
-
class MessageTest < Test
|
27
|
+
class MessageTest < MiniTest::Test
|
4
28
|
def setup
|
5
29
|
end
|
6
30
|
|
7
31
|
def teardown
|
8
32
|
end
|
9
33
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
34
|
+
def hex2bin(hexstring)
|
35
|
+
ret = "\x00" * (hexstring.length / 2)
|
36
|
+
ret.force_encoding("BINARY")
|
37
|
+
offset = 0
|
38
|
+
while offset < hexstring.length
|
39
|
+
hex_byte = hexstring[offset..(offset+1)]
|
40
|
+
ret.setbyte(offset/2, hex_byte.to_i(16))
|
41
|
+
offset += 2
|
42
|
+
end
|
43
|
+
ret
|
44
|
+
end
|
21
45
|
|
22
46
|
def test_good_decode
|
23
|
-
|
47
|
+
data = hex2bin("1d008180000100080000000103777777057961686f6f03636f6d0000010001c00c000500010000012c000f0666642d667033037767310162c010c02b000500010000012c00090664732d667033c032c046000500010000003c00150e64732d616e792d6670332d6c666203776131c036c05b000500010000012c00120f64732d616e792d6670332d7265616cc06ac07c000100010000003c0004628afc1ec07c000100010000003c0004628bb495c07c000100010000003c0004628bb718c07c000100010000003c0004628afd6d0000291000000000000000")
|
24
48
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
49
|
+
decoded = RubyDNS.decode_message(data)
|
50
|
+
assert_equal(RubyDNS::Message, decoded.class)
|
51
|
+
assert_equal(0x1d00, decoded.id)
|
52
|
+
assert_equal(1, decoded.question.count)
|
53
|
+
assert_equal(8, decoded.answer.count)
|
54
|
+
assert_equal(0, decoded.authority.count)
|
55
|
+
assert_equal(1, decoded.additional.count)
|
32
56
|
end
|
33
57
|
|
34
58
|
def test_bad_AAAA_length
|
35
|
-
|
59
|
+
data = hex2bin("ea9e8180000100010000000108626169636169636e03636f6d00001c0001c00c001c00010000011e000432177b770000291000000000000000")
|
36
60
|
|
37
|
-
|
38
|
-
|
39
|
-
|
61
|
+
assert_raises Resolv::DNS::DecodeError do
|
62
|
+
RubyDNS.decode_message(data)
|
63
|
+
end
|
40
64
|
end
|
41
65
|
end
|
data/test/test_passthrough.rb
CHANGED
@@ -20,21 +20,23 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require '
|
24
|
-
require 'pathname'
|
23
|
+
require 'minitest/autorun'
|
25
24
|
|
26
25
|
require 'rubydns'
|
27
|
-
require 'rubydns/resolver'
|
28
26
|
|
29
|
-
require '
|
30
|
-
require 'rexec/daemon'
|
27
|
+
require 'process/daemon'
|
31
28
|
|
32
|
-
class
|
29
|
+
class PassthroughServer < Process::Daemon
|
33
30
|
SERVER_PORTS = [[:udp, '127.0.0.1', 5340], [:tcp, '127.0.0.1', 5340]]
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
def working_directory
|
33
|
+
File.join(__dir__, "tmp")
|
34
|
+
end
|
35
|
+
|
36
|
+
Name = Resolv::DNS::Name
|
37
|
+
IN = Resolv::DNS::Resource::IN
|
38
|
+
|
39
|
+
def startup
|
38
40
|
resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
39
41
|
|
40
42
|
# Start the RubyDNS server
|
@@ -55,28 +57,32 @@ class TestPassthroughServer < RExec::Daemon::Base
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
class PassthroughTest < Test
|
59
|
-
# LOG_PATH = File.join(__dir__, "log/TestPassthroughServer.log")
|
60
|
-
|
60
|
+
class PassthroughTest < MiniTest::Test
|
61
61
|
def setup
|
62
|
-
|
63
|
-
|
62
|
+
PassthroughServer.controller output: File.open("/dev/null", "w")
|
63
|
+
|
64
|
+
PassthroughServer.start
|
64
65
|
end
|
65
66
|
|
66
67
|
def teardown
|
67
|
-
|
68
|
-
# system("cat", LOG_PATH)
|
68
|
+
PassthroughServer.stop
|
69
69
|
end
|
70
70
|
|
71
71
|
def test_basic_dns
|
72
72
|
answer = nil, response = nil
|
73
73
|
|
74
|
-
assert_equal :running,
|
74
|
+
assert_equal :running, PassthroughServer.status
|
75
75
|
|
76
76
|
EventMachine.run do
|
77
|
-
resolver = RubyDNS::Resolver.new(
|
78
|
-
|
77
|
+
resolver = RubyDNS::Resolver.new(
|
78
|
+
PassthroughServer::SERVER_PORTS,
|
79
|
+
# Enable this to get more debug output from the resolver:
|
80
|
+
# :logger => Logger.new($stderr)
|
81
|
+
)
|
82
|
+
|
79
83
|
resolver.query("google.com") do |response|
|
84
|
+
refute_kind_of RubyDNS::ResolutionFailure, response
|
85
|
+
|
80
86
|
assert_equal 1, response.ra
|
81
87
|
|
82
88
|
answer = response.answer.first
|
@@ -86,20 +92,22 @@ class PassthroughTest < Test::Unit::TestCase
|
|
86
92
|
end
|
87
93
|
|
88
94
|
# Check whether we got some useful records in the answer:
|
89
|
-
|
95
|
+
refute_nil answer
|
90
96
|
assert answer.count > 0
|
91
|
-
assert answer.any? {|record| record.kind_of? Resolv::DNS::Resource::IN::A
|
97
|
+
assert answer.any? {|record| record.kind_of? Resolv::DNS::Resource::IN::A}
|
92
98
|
end
|
93
99
|
|
94
100
|
def test_basic_dns_prefix
|
95
101
|
answer = nil
|
96
102
|
|
97
|
-
assert_equal :running,
|
103
|
+
assert_equal :running, PassthroughServer.status
|
98
104
|
|
99
105
|
EventMachine.run do
|
100
|
-
resolver = RubyDNS::Resolver.new(
|
106
|
+
resolver = RubyDNS::Resolver.new(PassthroughServer::SERVER_PORTS)
|
101
107
|
|
102
108
|
resolver.query("a-slashdot.org") do |response|
|
109
|
+
refute_kind_of RubyDNS::ResolutionFailure, response
|
110
|
+
|
103
111
|
answer = response.answer.first
|
104
112
|
|
105
113
|
EventMachine.stop
|
data/test/test_resolver.rb
CHANGED
@@ -20,10 +20,11 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require '
|
23
|
+
require 'minitest/autorun'
|
24
|
+
|
24
25
|
require 'rubydns'
|
25
26
|
|
26
|
-
class ResolverTest < Test
|
27
|
+
class ResolverTest < MiniTest::Test
|
27
28
|
def test_basic_resolver
|
28
29
|
resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
29
30
|
|
data/test/test_rules.rb
CHANGED
@@ -20,18 +20,18 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require '
|
24
|
-
require 'pathname'
|
23
|
+
require 'minitest/autorun'
|
25
24
|
|
26
25
|
require 'rubydns'
|
27
|
-
require 'rubydns/resolver'
|
28
|
-
require 'rubydns/extensions/string'
|
29
26
|
|
30
|
-
class RulesTest < Test
|
27
|
+
class RulesTest < MiniTest::Test
|
31
28
|
IN = Resolv::DNS::Resource::IN
|
32
29
|
|
33
30
|
def setup
|
34
|
-
@
|
31
|
+
@logger = Logger.new($stderr)
|
32
|
+
@logger.level = Logger::INFO
|
33
|
+
|
34
|
+
@server = RubyDNS::Server.new(logger: @logger)
|
35
35
|
@true_callback = Proc.new { true }
|
36
36
|
end
|
37
37
|
|
data/test/test_slow_server.rb
CHANGED
@@ -20,22 +20,24 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require '
|
24
|
-
require 'pathname'
|
23
|
+
require 'minitest/autorun'
|
25
24
|
|
26
25
|
require 'rubydns'
|
27
|
-
require 'rubydns/resolver'
|
28
|
-
require 'rubydns/extensions/string'
|
29
26
|
|
30
|
-
|
27
|
+
require 'process/daemon'
|
28
|
+
|
29
|
+
class SlowServer < Process::Daemon
|
31
30
|
SERVER_PORTS = [[:udp, '127.0.0.1', 5330], [:tcp, '127.0.0.1', 5330]]
|
32
31
|
|
33
32
|
@@base_directory = File.dirname(__FILE__)
|
34
33
|
|
35
|
-
|
34
|
+
def working_directory
|
35
|
+
File.join(__dir__, "tmp")
|
36
|
+
end
|
37
|
+
|
36
38
|
IN = Resolv::DNS::Resource::IN
|
37
|
-
|
38
|
-
def
|
39
|
+
|
40
|
+
def startup
|
39
41
|
RubyDNS::run_server(:listen => SERVER_PORTS) do
|
40
42
|
match(/\.*.com/, IN::A) do |transaction|
|
41
43
|
defer do |fiber|
|
@@ -55,8 +57,9 @@ class SlowServer < RExec::Daemon::Base
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
class SlowServerTest < Test
|
60
|
+
class SlowServerTest < MiniTest::Test
|
59
61
|
def setup
|
62
|
+
SlowServer.controller output: File.open("/dev/null", "w")
|
60
63
|
SlowServer.start
|
61
64
|
end
|
62
65
|
|
@@ -64,6 +67,8 @@ class SlowServerTest < Test::Unit::TestCase
|
|
64
67
|
SlowServer.stop
|
65
68
|
end
|
66
69
|
|
70
|
+
IN = Resolv::DNS::Resource::IN
|
71
|
+
|
67
72
|
def test_timeout
|
68
73
|
start_time = Time.now
|
69
74
|
end_time = nil
|
@@ -82,7 +87,7 @@ class SlowServerTest < Test::Unit::TestCase
|
|
82
87
|
end
|
83
88
|
end
|
84
89
|
|
85
|
-
|
90
|
+
assert_operator end_time - start_time, :<=, 2.5, "Response should fail within timeout period."
|
86
91
|
assert_equal RubyDNS::ResolutionFailure, got_response.class, "Response should be resolution failure."
|
87
92
|
end
|
88
93
|
|
@@ -100,7 +105,7 @@ class SlowServerTest < Test::Unit::TestCase
|
|
100
105
|
end
|
101
106
|
end
|
102
107
|
|
103
|
-
|
108
|
+
assert_operator end_time - start_time, :>, 2.0, "Response should fail within timeout period."
|
104
109
|
end
|
105
110
|
|
106
111
|
def test_normal_request
|
@@ -117,6 +122,6 @@ class SlowServerTest < Test::Unit::TestCase
|
|
117
122
|
end
|
118
123
|
end
|
119
124
|
|
120
|
-
|
125
|
+
assert_operator end_time - start_time, :<, 2.0, "Response should fail immediately"
|
121
126
|
end
|
122
127
|
end
|
data/test/test_system.rb
CHANGED
@@ -20,15 +20,12 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require '
|
24
|
-
require 'pathname'
|
23
|
+
require 'minitest/autorun'
|
25
24
|
|
26
25
|
require 'rubydns'
|
27
26
|
require 'rubydns/system'
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
class SystemTest < Test::Unit::TestCase
|
28
|
+
class SystemTest < MiniTest::Test
|
32
29
|
def test_system_nameservers
|
33
30
|
# There technically should be at least one nameserver:
|
34
31
|
resolver = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
|
data/test/test_truncation.rb
CHANGED
@@ -20,22 +20,25 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require '
|
24
|
-
require 'pathname'
|
23
|
+
require 'minitest/autorun'
|
25
24
|
|
26
25
|
require 'rubydns'
|
27
|
-
require 'rubydns/resolver'
|
28
26
|
require 'rubydns/extensions/string'
|
29
27
|
|
30
|
-
|
28
|
+
require 'process/daemon'
|
29
|
+
|
30
|
+
class TruncatedServer < Process::Daemon
|
31
31
|
SERVER_PORTS = [[:udp, '127.0.0.1', 5320], [:tcp, '127.0.0.1', 5320]]
|
32
32
|
|
33
33
|
@@base_directory = File.dirname(__FILE__)
|
34
|
-
|
35
|
-
|
34
|
+
|
35
|
+
def working_directory
|
36
|
+
File.join(__dir__, "tmp")
|
37
|
+
end
|
38
|
+
|
36
39
|
IN = Resolv::DNS::Resource::IN
|
37
|
-
|
38
|
-
def
|
40
|
+
|
41
|
+
def startup
|
39
42
|
# RubyDNS::log_bad_messages!("bad.log")
|
40
43
|
|
41
44
|
# Start the RubyDNS server
|
@@ -53,8 +56,10 @@ class TruncatedServer < RExec::Daemon::Base
|
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
56
|
-
class TruncationTest < Test
|
59
|
+
class TruncationTest < MiniTest::Test
|
57
60
|
def setup
|
61
|
+
TruncatedServer.controller output: File.open("/dev/null", "w")
|
62
|
+
|
58
63
|
TruncatedServer.start
|
59
64
|
end
|
60
65
|
|
@@ -62,11 +67,15 @@ class TruncationTest < Test::Unit::TestCase
|
|
62
67
|
TruncatedServer.stop
|
63
68
|
end
|
64
69
|
|
70
|
+
IN = Resolv::DNS::Resource::IN
|
71
|
+
|
65
72
|
def test_tcp_failover
|
66
73
|
resolver = RubyDNS::Resolver.new(TruncatedServer::SERVER_PORTS)
|
67
74
|
|
68
75
|
EventMachine::run do
|
69
76
|
resolver.query("truncation", IN::TXT) do |response|
|
77
|
+
refute_kind_of RubyDNS::ResolutionFailure, response
|
78
|
+
|
70
79
|
text = response.answer.first
|
71
80
|
|
72
81
|
assert_equal "Hello World! " * 100, text[2].strings.join
|
metadata
CHANGED
@@ -1,50 +1,78 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: eventmachine
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
34
|
-
type: :
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: process-daemon
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.5.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
description: "\t\tRubyDNS is a high-performance DNS server which can be easily integrated
|
42
|
-
into\n\t\tother projects or used as a stand-alone daemon
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
70
|
+
into\n\t\tother projects or used as a stand-alone daemon. By default it uses\n\t\trule-based
|
71
|
+
pattern matching. Results can be hard-coded, computed, fetched from\n\t\ta remote
|
72
|
+
DNS server or fetched from a local cache, depending on requirements.\n\n\t\tIn addition,
|
73
|
+
RubyDNS includes a high-performance asynchronous DNS resolver\n\t\tbuilt on top
|
74
|
+
of EventMachine. This module can be used by itself in client\n\t\tapplications without
|
75
|
+
using the full RubyDNS server stack.\n"
|
48
76
|
email:
|
49
77
|
- samuel.williams@oriontransfer.co.nz
|
50
78
|
executables:
|
@@ -64,10 +92,10 @@ files:
|
|
64
92
|
- lib/rubydns.rb
|
65
93
|
- lib/rubydns/binary_string.rb
|
66
94
|
- lib/rubydns/chunked.rb
|
67
|
-
- lib/rubydns/extensions/logger.rb
|
68
95
|
- lib/rubydns/extensions/resolv.rb
|
69
96
|
- lib/rubydns/extensions/string.rb
|
70
97
|
- lib/rubydns/handler.rb
|
98
|
+
- lib/rubydns/logger.rb
|
71
99
|
- lib/rubydns/message.rb
|
72
100
|
- lib/rubydns/resolver.rb
|
73
101
|
- lib/rubydns/server.rb
|
@@ -82,7 +110,6 @@ files:
|
|
82
110
|
- test/examples/test-dns-1.rb
|
83
111
|
- test/examples/test-dns-2.rb
|
84
112
|
- test/examples/wikipedia-dns.rb
|
85
|
-
- test/helper.rb
|
86
113
|
- test/hosts.txt
|
87
114
|
- test/test_daemon.rb
|
88
115
|
- test/test_domains.txt
|
@@ -125,7 +152,6 @@ test_files:
|
|
125
152
|
- test/examples/test-dns-1.rb
|
126
153
|
- test/examples/test-dns-2.rb
|
127
154
|
- test/examples/wikipedia-dns.rb
|
128
|
-
- test/helper.rb
|
129
155
|
- test/hosts.txt
|
130
156
|
- test/test_daemon.rb
|
131
157
|
- test/test_domains.txt
|