redns 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +16 -0
- data/README.rdoc +10 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/redns/address.rb +44 -0
- data/lib/redns/buffer.rb +138 -0
- data/lib/redns/fragment.rb +105 -0
- data/lib/redns/message.rb +144 -0
- data/lib/redns/name.rb +79 -0
- data/lib/redns/question.rb +38 -0
- data/lib/redns/record/mx.rb +28 -0
- data/lib/redns/record/null.rb +30 -0
- data/lib/redns/record/soa.rb +65 -0
- data/lib/redns/record.rb +7 -0
- data/lib/redns/resource.rb +86 -0
- data/lib/redns/support.rb +19 -0
- data/lib/redns.rb +84 -0
- data/redns.gemspec +77 -0
- data/test/helper.rb +13 -0
- data/test/test_redns.rb +4 -0
- data/test/test_redns_address.rb +23 -0
- data/test/test_redns_buffer.rb +180 -0
- data/test/test_redns_fragment.rb +55 -0
- data/test/test_redns_message.rb +35 -0
- data/test/test_redns_name.rb +76 -0
- data/test/test_redns_question.rb +24 -0
- data/test/test_redns_resource.rb +184 -0
- data/test/test_redns_support.rb +16 -0
- metadata +101 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestReDNSName < Test::Unit::TestCase
|
4
|
+
def test_defaults
|
5
|
+
name = ReDNS::Name.new
|
6
|
+
|
7
|
+
assert_equal '.', name.to_s
|
8
|
+
assert_equal %w[ . ], name.to_a
|
9
|
+
|
10
|
+
assert name.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_string_initializer
|
14
|
+
name = ReDNS::Name.new('example.net')
|
15
|
+
|
16
|
+
assert_equal 'example.net.', name.to_s
|
17
|
+
|
18
|
+
assert !name.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_defaults
|
22
|
+
example_buffer = ReDNS::Buffer.new(
|
23
|
+
[
|
24
|
+
7, ?e, ?x, ?a, ?m, ?p, ?l, ?e,
|
25
|
+
3, ?c, ?o, ?m,
|
26
|
+
0
|
27
|
+
].collect(&:chr).join
|
28
|
+
)
|
29
|
+
|
30
|
+
name = ReDNS::Name.new(example_buffer)
|
31
|
+
|
32
|
+
assert_equal 'example.com.', name.to_s
|
33
|
+
|
34
|
+
assert !name.empty?
|
35
|
+
|
36
|
+
assert_equal 0, example_buffer.length
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_decode_cycle
|
40
|
+
name_string = 'example.com.'.freeze
|
41
|
+
|
42
|
+
name = ReDNS::Name.new(name_string)
|
43
|
+
|
44
|
+
assert_equal name_string, name.to_s
|
45
|
+
|
46
|
+
buffer = ReDNS::Buffer.new(name)
|
47
|
+
|
48
|
+
assert_equal name_string.length + 1, buffer.length
|
49
|
+
|
50
|
+
assert_equal 'example.com.', ReDNS::Name.new(buffer).to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_example_pointer
|
54
|
+
example_buffer = ReDNS::Buffer.new(
|
55
|
+
[
|
56
|
+
3, ?n, ?e, ?t,
|
57
|
+
0,
|
58
|
+
3, ?c, ?o, ?m,
|
59
|
+
0,
|
60
|
+
7, ?e, ?x, ?a, ?m, ?p, ?l, ?e,
|
61
|
+
192, 5
|
62
|
+
].collect(&:chr).join
|
63
|
+
)
|
64
|
+
|
65
|
+
# Skip past the first "net." / "com." part
|
66
|
+
example_buffer.advance(10)
|
67
|
+
|
68
|
+
name = ReDNS::Name.new(example_buffer)
|
69
|
+
|
70
|
+
assert_equal 'example.com.', name.to_s
|
71
|
+
|
72
|
+
assert !name.empty?
|
73
|
+
|
74
|
+
assert_equal 0, example_buffer.length
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestReDNSQuestion < Test::Unit::TestCase
|
4
|
+
def test_defaults
|
5
|
+
question = ReDNS::Question.new
|
6
|
+
|
7
|
+
assert_equal :any, question.qtype
|
8
|
+
assert_equal :in, question.qclass
|
9
|
+
|
10
|
+
assert_equal '. IN ANY', question.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_example_query
|
14
|
+
question = ReDNS::Question.new(
|
15
|
+
:name => 'example.com',
|
16
|
+
:qtype => :a
|
17
|
+
)
|
18
|
+
|
19
|
+
assert_equal :a, question.qtype
|
20
|
+
assert_equal :in, question.qclass
|
21
|
+
|
22
|
+
assert_equal 'example.com. IN A', question.to_s
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestReDNSResource < Test::Unit::TestCase
|
4
|
+
def test_defaults
|
5
|
+
resource = ReDNS::Resource.new
|
6
|
+
|
7
|
+
assert resource.empty?
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_serialize_cycle_mx
|
11
|
+
mx = ReDNS::Record::MX.new(
|
12
|
+
:preference => 10,
|
13
|
+
:name => 'mx.example.com'
|
14
|
+
)
|
15
|
+
|
16
|
+
assert_equal 10, mx.preference
|
17
|
+
assert_equal 'mx.example.com.', mx.name.to_s
|
18
|
+
|
19
|
+
assert_equal '10 mx.example.com.', mx.to_s
|
20
|
+
|
21
|
+
buffer = mx.serialize
|
22
|
+
assert_equal 0, buffer.offset
|
23
|
+
|
24
|
+
assert_equal 'mx.example.com.'.length + 1 + 2, buffer.length
|
25
|
+
|
26
|
+
decoded_mx = ReDNS::Record::MX.new(buffer)
|
27
|
+
|
28
|
+
assert_equal '10 mx.example.com.', decoded_mx.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_serialize_cycle_record_mx
|
32
|
+
mx = ReDNS::Resource.new(
|
33
|
+
:name => 'example.com',
|
34
|
+
:rdata => ReDNS::Record::MX.new(
|
35
|
+
:preference => 10,
|
36
|
+
:name => 'mx.example.com'
|
37
|
+
),
|
38
|
+
:ttl => 123456,
|
39
|
+
:rtype => :mx
|
40
|
+
)
|
41
|
+
|
42
|
+
assert_equal 'example.com.', mx.name.to_s
|
43
|
+
assert_equal 10, mx.rdata.preference
|
44
|
+
assert_equal 'mx.example.com.', mx.rdata.name.to_s
|
45
|
+
assert_equal 123456, mx.ttl
|
46
|
+
assert_equal :mx, mx.rtype
|
47
|
+
|
48
|
+
assert_equal 'example.com. 123456 IN MX 10 mx.example.com.', mx.to_s
|
49
|
+
|
50
|
+
buffer = mx.serialize
|
51
|
+
assert_equal 0, buffer.offset
|
52
|
+
|
53
|
+
rdata_length = mx.rdata.serialize.length
|
54
|
+
|
55
|
+
assert_equal 'example.com.'.length + 1 + 4 + 2 * 3 + rdata_length, buffer.length
|
56
|
+
|
57
|
+
decoded_mx = ReDNS::Resource.new(buffer)
|
58
|
+
|
59
|
+
assert_equal mx.to_s, decoded_mx.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_serialize_cycle_soa
|
63
|
+
soa = ReDNS::Record::SOA.new(
|
64
|
+
:mname => 'example.com',
|
65
|
+
:rname => 'domainadmin.example.com',
|
66
|
+
:serial => 1001,
|
67
|
+
:refresh => 1002,
|
68
|
+
:retry => 1003,
|
69
|
+
:expire => 1004,
|
70
|
+
:minimum => 1005
|
71
|
+
)
|
72
|
+
|
73
|
+
assert_equal 'example.com.', soa.mname.to_s
|
74
|
+
assert_equal 'domainadmin.example.com.', soa.rname.to_s
|
75
|
+
|
76
|
+
assert_equal 1001, soa.serial
|
77
|
+
assert_equal 1002, soa.refresh
|
78
|
+
assert_equal 1003, soa.retry
|
79
|
+
assert_equal 1004, soa.expire
|
80
|
+
assert_equal 1005, soa.minimum
|
81
|
+
|
82
|
+
buffer = soa.serialize
|
83
|
+
assert_equal 0, buffer.offset
|
84
|
+
|
85
|
+
assert_equal 'example.com.'.length + 1 + 'domainadmin.example.com.'.length + 1 + 4 * 5, buffer.length
|
86
|
+
|
87
|
+
decoded_soa = ReDNS::Record::SOA.new(buffer)
|
88
|
+
|
89
|
+
assert_equal 'example.com. domainadmin.example.com. 1001 1002 1003 1004 1005', decoded_soa.to_s
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_serialize_cycle_record_soa
|
93
|
+
soa = ReDNS::Resource.new(
|
94
|
+
:name => 'example.com',
|
95
|
+
:rdata => ReDNS::Record::SOA.new(
|
96
|
+
:mname => 'example.com',
|
97
|
+
:rname => 'domainadmin.example.com',
|
98
|
+
:serial => 1001,
|
99
|
+
:refresh => 1002,
|
100
|
+
:retry => 1003,
|
101
|
+
:expire => 1004,
|
102
|
+
:minimum => 1005
|
103
|
+
),
|
104
|
+
:ttl => 123456,
|
105
|
+
:rtype => :soa
|
106
|
+
)
|
107
|
+
|
108
|
+
assert_equal 'example.com.', soa.name.to_s
|
109
|
+
assert_equal 123456, soa.ttl
|
110
|
+
assert_equal :soa, soa.rtype
|
111
|
+
|
112
|
+
assert_equal 'example.com.', soa.rdata.mname.to_s
|
113
|
+
assert_equal 'domainadmin.example.com.', soa.rdata.rname.to_s
|
114
|
+
|
115
|
+
assert_equal 1001, soa.rdata.serial
|
116
|
+
assert_equal 1002, soa.rdata.refresh
|
117
|
+
assert_equal 1003, soa.rdata.retry
|
118
|
+
assert_equal 1004, soa.rdata.expire
|
119
|
+
assert_equal 1005, soa.rdata.minimum
|
120
|
+
|
121
|
+
assert_equal 'example.com. 123456 IN SOA example.com. domainadmin.example.com. 1001 1002 1003 1004 1005', soa.to_s
|
122
|
+
|
123
|
+
buffer = soa.serialize
|
124
|
+
assert_equal 0, buffer.offset
|
125
|
+
|
126
|
+
rdata_length = soa.rdata.serialize.length
|
127
|
+
|
128
|
+
assert_equal 'example.com.'.length + 1 + 4 + 2 * 3 + rdata_length, buffer.length
|
129
|
+
|
130
|
+
decoded_soa = ReDNS::Resource.new(buffer)
|
131
|
+
|
132
|
+
assert_equal soa.to_s, decoded_soa.to_s
|
133
|
+
|
134
|
+
assert_equal :soa, decoded_soa.rtype
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_serialize_cycle_null
|
138
|
+
null = ReDNS::Record::Null.new(
|
139
|
+
:contents => 'random data goes here'.freeze
|
140
|
+
)
|
141
|
+
|
142
|
+
assert_equal 'random data goes here', null.contents
|
143
|
+
|
144
|
+
assert_equal 'random data goes here', null.to_s
|
145
|
+
|
146
|
+
buffer = null.serialize
|
147
|
+
assert_equal 0, buffer.offset
|
148
|
+
|
149
|
+
assert_equal 'random data goes here'.length, buffer.length
|
150
|
+
|
151
|
+
decoded_null = ReDNS::Record::Null.new(buffer)
|
152
|
+
|
153
|
+
assert_equal 'random data goes here', decoded_null.to_s
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_serialize_cycle_record_null
|
157
|
+
null = ReDNS::Resource.new(
|
158
|
+
:name => 'example.com',
|
159
|
+
:rdata => ReDNS::Record::Null.new(
|
160
|
+
:contents => 'random data goes here'.freeze
|
161
|
+
),
|
162
|
+
:ttl => 123456,
|
163
|
+
:rtype => :null
|
164
|
+
)
|
165
|
+
|
166
|
+
assert_equal 'example.com.', null.name.to_s
|
167
|
+
assert_equal 'random data goes here', null.rdata.contents
|
168
|
+
assert_equal 123456, null.ttl
|
169
|
+
assert_equal :null, null.rtype
|
170
|
+
|
171
|
+
assert_equal 'example.com. 123456 IN NULL random data goes here', null.to_s
|
172
|
+
|
173
|
+
buffer = null.serialize
|
174
|
+
assert_equal 0, buffer.offset
|
175
|
+
|
176
|
+
rdata_length = null.rdata.serialize.length
|
177
|
+
|
178
|
+
assert_equal 'example.com.'.length + 1 + 4 + 2 * 3 + rdata_length, buffer.length
|
179
|
+
|
180
|
+
decoded_null = ReDNS::Resource.new(buffer)
|
181
|
+
|
182
|
+
assert_equal null.to_s, decoded_null.to_s
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestReDNSSupport < Test::Unit::TestCase
|
4
|
+
include ReDNS::Support
|
5
|
+
|
6
|
+
def test_addr_to_arpa
|
7
|
+
assert_equal '4.3.2.1.in-addr.arpa.', addr_to_arpa('1.2.3.4')
|
8
|
+
assert_equal '3.2.1.in-addr.arpa.', addr_to_arpa('1.2.3')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_inet_ntoa
|
12
|
+
assert_equal '0.0.0.0', inet_ntoa(inet_aton('0.0.0.0'))
|
13
|
+
assert_equal '1.2.3.4', inet_ntoa(inet_aton('1.2.3.4'))
|
14
|
+
assert_equal '255.255.255.255', inet_ntoa(inet_aton('255.255.255.255'))
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- tadman
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-13 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: ReDNS is a pure Ruby DNS library with drivers for reactor-model engines such as EventMachine
|
22
|
+
email: github@tadman.ca
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.rdoc
|
29
|
+
files:
|
30
|
+
- .document
|
31
|
+
- .gitignore
|
32
|
+
- README.rdoc
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- lib/redns.rb
|
36
|
+
- lib/redns/address.rb
|
37
|
+
- lib/redns/buffer.rb
|
38
|
+
- lib/redns/fragment.rb
|
39
|
+
- lib/redns/message.rb
|
40
|
+
- lib/redns/name.rb
|
41
|
+
- lib/redns/question.rb
|
42
|
+
- lib/redns/record.rb
|
43
|
+
- lib/redns/record/mx.rb
|
44
|
+
- lib/redns/record/null.rb
|
45
|
+
- lib/redns/record/soa.rb
|
46
|
+
- lib/redns/resource.rb
|
47
|
+
- lib/redns/support.rb
|
48
|
+
- redns.gemspec
|
49
|
+
- test/helper.rb
|
50
|
+
- test/test_redns.rb
|
51
|
+
- test/test_redns_address.rb
|
52
|
+
- test/test_redns_buffer.rb
|
53
|
+
- test/test_redns_fragment.rb
|
54
|
+
- test/test_redns_message.rb
|
55
|
+
- test/test_redns_name.rb
|
56
|
+
- test/test_redns_question.rb
|
57
|
+
- test/test_redns_resource.rb
|
58
|
+
- test/test_redns_support.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/tadman/redns
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Ruby Reactor-Ready DNS Library
|
91
|
+
test_files:
|
92
|
+
- test/helper.rb
|
93
|
+
- test/test_redns.rb
|
94
|
+
- test/test_redns_address.rb
|
95
|
+
- test/test_redns_buffer.rb
|
96
|
+
- test/test_redns_fragment.rb
|
97
|
+
- test/test_redns_message.rb
|
98
|
+
- test/test_redns_name.rb
|
99
|
+
- test/test_redns_question.rb
|
100
|
+
- test/test_redns_resource.rb
|
101
|
+
- test/test_redns_support.rb
|