net-dns 0.6.1 → 0.7.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.
- data/.gitignore +8 -6
- data/.travis.yml +14 -0
- data/CHANGELOG.md +79 -0
- data/Gemfile +4 -0
- data/Rakefile +56 -66
- data/demo/check_soa.rb +1 -1
- data/demo/threads.rb +1 -1
- data/lib/net/dns.rb +24 -22
- data/lib/net/dns/header.rb +77 -103
- data/lib/net/dns/{names/names.rb → names.rb} +19 -20
- data/lib/net/dns/packet.rb +231 -256
- data/lib/net/dns/question.rb +11 -40
- data/lib/net/dns/resolver.rb +248 -250
- data/lib/net/dns/resolver/socks.rb +6 -6
- data/lib/net/dns/resolver/timeouts.rb +1 -1
- data/lib/net/dns/rr.rb +112 -117
- data/lib/net/dns/rr/a.rb +98 -89
- data/lib/net/dns/rr/aaaa.rb +84 -68
- data/lib/net/dns/rr/classes.rb +91 -106
- data/lib/net/dns/rr/cname.rb +64 -45
- data/lib/net/dns/rr/hinfo.rb +90 -50
- data/lib/net/dns/rr/mr.rb +61 -44
- data/lib/net/dns/rr/mx.rb +73 -48
- data/lib/net/dns/rr/ns.rb +60 -46
- data/lib/net/dns/rr/null.rb +11 -12
- data/lib/net/dns/rr/ptr.rb +47 -34
- data/lib/net/dns/rr/soa.rb +5 -6
- data/lib/net/dns/rr/srv.rb +1 -4
- data/lib/net/dns/rr/txt.rb +14 -14
- data/lib/net/dns/rr/types.rb +13 -13
- data/lib/net/dns/version.rb +8 -14
- data/net-dns.gemspec +35 -0
- data/setup.rb +3 -2
- data/test/header_test.rb +18 -18
- data/test/names_test.rb +21 -0
- data/test/packet_test.rb +38 -31
- data/test/question_test.rb +23 -24
- data/test/resolver/timeouts_test.rb +13 -13
- data/test/resolver_test.rb +28 -20
- data/test/rr/a_test.rb +70 -23
- data/test/rr/aaaa_test.rb +109 -0
- data/test/rr/classes_test.rb +61 -49
- data/test/rr/cname_test.rb +97 -0
- data/test/rr/hinfo_test.rb +117 -0
- data/test/rr/mr_test.rb +105 -0
- data/test/rr/mx_test.rb +112 -0
- data/test/rr/ns_test.rb +34 -12
- data/test/rr/types_test.rb +4 -4
- data/test/rr_test.rb +1 -1
- metadata +77 -52
- data/AUTHORS.rdoc +0 -7
- data/CHANGELOG.rdoc +0 -46
- data/VERSION.yml +0 -5
data/test/names_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/names'
|
3
|
+
|
4
|
+
class NamesTest < Test::Unit::TestCase
|
5
|
+
include Net::DNS::Names
|
6
|
+
|
7
|
+
def test_long_names
|
8
|
+
assert_nothing_raised do
|
9
|
+
pack_name('a' * 63)
|
10
|
+
end
|
11
|
+
assert_raises ArgumentError do
|
12
|
+
pack_name('a' * 64)
|
13
|
+
end
|
14
|
+
assert_nothing_raised do
|
15
|
+
pack_name(['a' * 63, 'b' * 63, 'c' * 63, 'd' * 63].join('.'))
|
16
|
+
end
|
17
|
+
assert_raises ArgumentError do
|
18
|
+
pack_name(['a' * 63, 'b' * 63, 'c' * 63, 'd' * 63, 'e'].join('.'))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/test/packet_test.rb
CHANGED
@@ -2,41 +2,48 @@ require 'test_helper'
|
|
2
2
|
require 'net/dns/packet'
|
3
3
|
|
4
4
|
class PacketTest < Test::Unit::TestCase
|
5
|
-
include Net::DNS
|
6
5
|
|
7
6
|
def setup
|
7
|
+
@klass = Net::DNS::Packet
|
8
8
|
@domain = 'example.com'
|
9
|
-
@type = 'MX'
|
10
|
-
@cls = 'HS'
|
11
|
-
|
12
|
-
@default = Packet.new(@domain)
|
13
|
-
@string = Packet.new(@domain, MX, HS)
|
14
|
-
|
15
|
-
packet = "\337M\201\200\000\001\000\003\000\004\000\004\006google\003com\000\000\001\000\001\300\f\000\001\000\001\000\000\001,\000\004@\351\273c\300\f\000\001\000\001\000\000\001,\000\004H\016\317c\300\f\000\001\000\001\000\000\001,\000\004@\351\247c\300\f\000\002\000\001\000\003\364\200\000\006\003ns1\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns2\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns3\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns4\300\f\300X\000\001\000\001\000\003\307\273\000\004\330\357 \n\300j\000\001\000\001\000\003\307\273\000\004\330\357\"\n\300|\000\001\000\001\000\003\307\273\000\004\330\357$\n\300\216\000\001\000\001\000\003\307\273\000\004\330\357&\n"
|
16
|
-
|
17
|
-
@binary = Packet.parse(packet)
|
18
|
-
|
19
9
|
end
|
20
|
-
|
21
|
-
def test_instances
|
22
|
-
assert_instance_of(Net::DNS::Packet, @string)
|
23
|
-
assert_instance_of(Net::DNS::Header, @string.header)
|
24
|
-
assert_instance_of(Array, @string.question)
|
25
|
-
assert_instance_of(Net::DNS::Question, @string.question[0])
|
26
|
-
assert_instance_of(Array, @string.answer)
|
27
|
-
assert_instance_of(Array, @string.authority)
|
28
|
-
assert_instance_of(Array, @string.additional)
|
29
10
|
|
30
|
-
|
31
|
-
|
32
|
-
assert_instance_of
|
33
|
-
assert_instance_of
|
34
|
-
assert_instance_of
|
35
|
-
assert_instance_of
|
36
|
-
assert_instance_of
|
37
|
-
assert_instance_of
|
38
|
-
assert_instance_of
|
39
|
-
|
11
|
+
def test_initialize
|
12
|
+
@record = @klass.new(@domain, Net::DNS::MX, Net::DNS::HS)
|
13
|
+
assert_instance_of @klass, @record
|
14
|
+
assert_instance_of Net::DNS::Header, @record.header
|
15
|
+
assert_instance_of Array, @record.question
|
16
|
+
assert_instance_of Net::DNS::Question, @record.question.first
|
17
|
+
assert_instance_of Array, @record.answer
|
18
|
+
assert_instance_of Array, @record.authority
|
19
|
+
assert_instance_of Array, @record.additional
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initialize_should_set_question
|
23
|
+
@question = @klass.new(@domain).question.first
|
24
|
+
assert_equal @domain, @question.qName
|
25
|
+
assert_equal Net::DNS::RR::Types.new(Net::DNS::A).to_s, @question.qType.to_s
|
26
|
+
assert_equal Net::DNS::RR::Classes.new(Net::DNS::IN).to_s, @question.qClass.to_s
|
27
|
+
|
28
|
+
@question = @klass.new(@domain, Net::DNS::MX, Net::DNS::HS).question.first
|
29
|
+
assert_equal @domain, @question.qName
|
30
|
+
assert_equal Net::DNS::RR::Types.new(Net::DNS::MX).to_s, @question.qType.to_s
|
31
|
+
assert_equal Net::DNS::RR::Classes.new(Net::DNS::HS).to_s, @question.qClass.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_self_parse
|
35
|
+
packet = "\337M\201\200\000\001\000\003\000\004\000\004\006google\003com\000\000\001\000\001\300\f\000\001\000\001\000\000\001,\000\004@\351\273c\300\f\000\001\000\001\000\000\001,\000\004H\016\317c\300\f\000\001\000\001\000\000\001,\000\004@\351\247c\300\f\000\002\000\001\000\003\364\200\000\006\003ns1\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns2\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns3\300\f\300\f\000\002\000\001\000\003\364\200\000\006\003ns4\300\f\300X\000\001\000\001\000\003\307\273\000\004\330\357 \n\300j\000\001\000\001\000\003\307\273\000\004\330\357\"\n\300|\000\001\000\001\000\003\307\273\000\004\330\357$\n\300\216\000\001\000\001\000\003\307\273\000\004\330\357&\n"
|
36
|
+
@record = @klass.parse(packet)
|
37
|
+
assert_instance_of @klass, @record
|
38
|
+
assert_instance_of Net::DNS::Header, @record.header
|
39
|
+
assert_instance_of Array, @record.question
|
40
|
+
assert_instance_of Net::DNS::Question, @record.question.first
|
41
|
+
assert_instance_of Array, @record.answer
|
42
|
+
assert_instance_of Net::DNS::RR::A, @record.answer.first
|
43
|
+
assert_instance_of Array, @record.authority
|
44
|
+
assert_instance_of Net::DNS::RR::NS, @record.authority.first
|
45
|
+
assert_instance_of Array, @record.additional
|
46
|
+
assert_instance_of Net::DNS::RR::A, @record.additional.first
|
40
47
|
end
|
41
|
-
|
48
|
+
|
42
49
|
end
|
data/test/question_test.rb
CHANGED
@@ -2,20 +2,19 @@ require 'test_helper'
|
|
2
2
|
require 'net/dns/question'
|
3
3
|
|
4
4
|
class QuestionTest < Test::Unit::TestCase
|
5
|
-
include Net::DNS
|
6
5
|
|
7
6
|
def setup
|
8
7
|
@domain = 'example.com.'
|
9
8
|
@type = 'MX'
|
10
9
|
@cls = 'HS'
|
11
10
|
@data = "\006google\003com\000\000\001\000\001"
|
12
|
-
|
13
|
-
@default = Question.new(@domain)
|
14
|
-
@string = Question.new(@domain,@type,@cls)
|
15
|
-
@binary = Question.parse(@data)
|
16
|
-
@binary2 = Question.parse(@string.data)
|
11
|
+
|
12
|
+
@default = Net::DNS::Question.new(@domain)
|
13
|
+
@string = Net::DNS::Question.new(@domain,@type,@cls)
|
14
|
+
@binary = Net::DNS::Question.parse(@data)
|
15
|
+
@binary2 = Net::DNS::Question.parse(@string.data)
|
17
16
|
end
|
18
|
-
|
17
|
+
|
19
18
|
def test_simple
|
20
19
|
assert_equal(@default.qName, @domain)
|
21
20
|
assert_equal(@default.qType.to_s, "A")
|
@@ -24,31 +23,31 @@ class QuestionTest < Test::Unit::TestCase
|
|
24
23
|
assert_equal(@string.qName, @domain)
|
25
24
|
assert_equal(@string.qType.to_s, "MX")
|
26
25
|
assert_equal(@string.qClass.to_s, "HS")
|
27
|
-
|
26
|
+
|
28
27
|
assert_equal(@binary.qName, "google.com.")
|
29
28
|
assert_equal(@binary.qType.to_s, "A")
|
30
29
|
assert_equal(@binary.qClass.to_s, "IN")
|
31
|
-
|
30
|
+
|
32
31
|
assert_equal(@binary2.qName, @domain)
|
33
32
|
assert_equal(@binary2.qType.to_s, "MX")
|
34
33
|
assert_equal(@binary2.qClass.to_s, "HS")
|
35
34
|
end
|
36
35
|
|
37
36
|
def test_raise
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
Question.new("test{")
|
37
|
+
# assert_raises(Net::DNS::Question::NameInvalid) do
|
38
|
+
# Net::DNS::Question.new(1)
|
39
|
+
# end
|
40
|
+
assert_raises(Net::DNS::Question::NameInvalid) do
|
41
|
+
Net::DNS::Question.new("test{")
|
43
42
|
end
|
44
|
-
|
45
|
-
Question.parse(Array.new)
|
43
|
+
assert_raises(ArgumentError) do
|
44
|
+
Net::DNS::Question.parse(Array.new)
|
46
45
|
end
|
47
|
-
|
48
|
-
Question.parse("test")
|
46
|
+
assert_raises(ArgumentError) do
|
47
|
+
Net::DNS::Question.parse("test")
|
49
48
|
end
|
50
49
|
end
|
51
|
-
|
50
|
+
|
52
51
|
def test_inspect
|
53
52
|
assert_equal "google.com. IN A ",
|
54
53
|
Net::DNS::Question.new("google.com.").inspect
|
@@ -59,12 +58,12 @@ class QuestionTest < Test::Unit::TestCase
|
|
59
58
|
assert_equal "google.com. IN NS ",
|
60
59
|
Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
|
61
60
|
end
|
62
|
-
|
61
|
+
|
63
62
|
def test_inspect_with_name_longer_than_29_chrs
|
64
63
|
assert_equal "supercalifragilistichespiralidoso.com IN A ",
|
65
64
|
Net::DNS::Question.new("supercalifragilistichespiralidoso.com").inspect
|
66
65
|
end
|
67
|
-
|
66
|
+
|
68
67
|
def test_to_s
|
69
68
|
assert_equal "google.com. IN A ",
|
70
69
|
Net::DNS::Question.new("google.com.").to_s
|
@@ -75,10 +74,10 @@ class QuestionTest < Test::Unit::TestCase
|
|
75
74
|
assert_equal "google.com. IN NS ",
|
76
75
|
Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
|
77
76
|
end
|
78
|
-
|
77
|
+
|
79
78
|
def test_to_s_with_name_longer_than_29_chrs
|
80
79
|
assert_equal "supercalifragilistichespiralidoso.com IN A ",
|
81
80
|
Net::DNS::Question.new("supercalifragilistichespiralidoso.com").to_s
|
82
81
|
end
|
83
|
-
|
84
|
-
end
|
82
|
+
|
83
|
+
end
|
@@ -18,10 +18,10 @@ class DnsTimeoutTest < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_initialize_should_set_raise_with_invalid_timeout
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
assert_raises(ArgumentError) { @klass.new(nil) }
|
22
|
+
assert_raises(ArgumentError) { @klass.new("") }
|
23
|
+
assert_raises(ArgumentError) { @klass.new("foo") }
|
24
|
+
assert_raises(ArgumentError) { @klass.new(-1) }
|
25
25
|
end
|
26
26
|
|
27
27
|
|
@@ -33,7 +33,7 @@ class DnsTimeoutTest < Test::Unit::TestCase
|
|
33
33
|
|
34
34
|
|
35
35
|
def test_timeout_should_raise_localjumperror_without_block
|
36
|
-
|
36
|
+
assert_raises(LocalJumpError) { @klass.new(1).timeout }
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -41,13 +41,13 @@ end
|
|
41
41
|
class TcpTimeoutTest < Test::Unit::TestCase
|
42
42
|
|
43
43
|
def test_initialize
|
44
|
-
|
44
|
+
assert_raises(ArgumentError) do
|
45
45
|
Net::DNS::Resolver::TcpTimeout.new("a")
|
46
46
|
end
|
47
|
-
|
47
|
+
assert_raises(ArgumentError) do
|
48
48
|
Net::DNS::Resolver::TcpTimeout.new(-1)
|
49
49
|
end
|
50
|
-
|
50
|
+
assert_raises(TimeoutError) do
|
51
51
|
Net::DNS::Resolver::TcpTimeout.new(0.1).timeout { sleep 2 }
|
52
52
|
end
|
53
53
|
end
|
@@ -68,7 +68,7 @@ class TcpTimeoutTest < Test::Unit::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_timeout_should_raise_localjumperror_without_block
|
71
|
-
|
71
|
+
assert_raises(LocalJumpError) { Net::DNS::Resolver::TcpTimeout.new(1).timeout }
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
@@ -76,13 +76,13 @@ end
|
|
76
76
|
class UdpTimeoutTest < Test::Unit::TestCase
|
77
77
|
|
78
78
|
def test_initialize
|
79
|
-
|
79
|
+
assert_raises(ArgumentError) do
|
80
80
|
Net::DNS::Resolver::UdpTimeout.new("a")
|
81
81
|
end
|
82
|
-
|
82
|
+
assert_raises(ArgumentError) do
|
83
83
|
Net::DNS::Resolver::UdpTimeout.new(-1)
|
84
84
|
end
|
85
|
-
|
85
|
+
assert_raises(TimeoutError) do
|
86
86
|
Net::DNS::Resolver::UdpTimeout.new(0.1).timeout {sleep 2}
|
87
87
|
end
|
88
88
|
end
|
@@ -103,7 +103,7 @@ class UdpTimeoutTest < Test::Unit::TestCase
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def test_timeout_should_raise_localjumperror_without_block
|
106
|
-
|
106
|
+
assert_raises(LocalJumpError) { Net::DNS::Resolver::UdpTimeout.new(1).timeout }
|
107
107
|
end
|
108
108
|
|
109
109
|
end
|
data/test/resolver_test.rb
CHANGED
@@ -9,26 +9,32 @@ end
|
|
9
9
|
class ResolverTest < Test::Unit::TestCase
|
10
10
|
|
11
11
|
def test_initialize
|
12
|
-
assert_nothing_raised { Net::DNS::Resolver.new }
|
12
|
+
assert_nothing_raised { Net::DNS::Resolver.new }
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_initialize_with_config
|
16
|
-
assert_nothing_raised { Net::DNS::Resolver.new({}) }
|
16
|
+
assert_nothing_raised { Net::DNS::Resolver.new({}) }
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_initialize_with_invalid_config_should_raise_argumenterror
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
assert_raises(ArgumentError) { Net::DNS::Resolver.new("") }
|
21
|
+
assert_raises(ArgumentError) { Net::DNS::Resolver.new(0) }
|
22
|
+
assert_raises(ArgumentError) { Net::DNS::Resolver.new(:foo) }
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_query_with_no_nameservers_should_raise_resolvererror
|
26
|
+
assert_raises(Net::DNS::Resolver::Error) { Net::DNS::Resolver.new(:nameservers => []).query("example.com") }
|
27
|
+
end
|
28
|
+
|
29
|
+
# def test_send_to_ipv6_nameserver_should_not_raise_einval
|
30
|
+
# assert_nothing_raised { Net::DNS::Resolver.new(:nameservers => ['2001:4860:4860::8888', '2001:4860:4860::8844']).send('example.com')}
|
31
|
+
# end
|
25
32
|
|
26
33
|
# I know private methods are supposed to not be tested directly
|
27
34
|
# but since this library lacks unit tests, for now let me test them in this way.
|
28
35
|
|
29
36
|
def _make_query_packet(*args)
|
30
|
-
|
31
|
-
Net::DNS::Resolver.new.old_send(:make_query_packet, *args)
|
37
|
+
Net::DNS::Resolver.new.send(:make_query_packet, *args)
|
32
38
|
end
|
33
39
|
|
34
40
|
def test_make_query_packet_from_ipaddr
|
@@ -76,25 +82,27 @@ class ResolverTest < Test::Unit::TestCase
|
|
76
82
|
["mswin32", true], # ruby 1.8.6 (2008-04-22 rev 6555) [x86-jruby1.1.1]
|
77
83
|
]
|
78
84
|
|
85
|
+
C = Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG
|
86
|
+
|
79
87
|
def test_self_platform_windows_question
|
80
88
|
RubyPlatforms.each do |platform, is_windows|
|
81
|
-
assert_equal is_windows,
|
82
|
-
override_platform(platform) { Net::DNS::Resolver.platform_windows? },
|
89
|
+
assert_equal is_windows,
|
90
|
+
override_platform(platform) { Net::DNS::Resolver.platform_windows? },
|
83
91
|
"Expected `#{is_windows}' with platform `#{platform}'"
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
87
95
|
|
88
|
-
|
96
|
+
private
|
89
97
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
98
|
+
def override_platform(new_platform, &block)
|
99
|
+
raise LocalJumpError, "no block given" unless block_given?
|
100
|
+
old_platform = C["host_os"]
|
101
|
+
C["host_os"] = new_platform
|
102
|
+
result = yield
|
103
|
+
ensure
|
104
|
+
C["host_os"] = old_platform
|
105
|
+
result
|
106
|
+
end
|
99
107
|
|
100
|
-
end
|
108
|
+
end
|
data/test/rr/a_test.rb
CHANGED
@@ -2,50 +2,56 @@ require 'test_helper'
|
|
2
2
|
require 'net/dns/rr'
|
3
3
|
|
4
4
|
class RRATest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
def setup
|
7
7
|
@rr_name = "google.com."
|
8
8
|
@rr_type = "A"
|
9
9
|
@rr_cls = "IN"
|
10
|
-
@rr_ttl =
|
11
|
-
@
|
12
|
-
|
13
|
-
|
10
|
+
@rr_ttl = 10000
|
11
|
+
@rr_value = "64.233.187.99"
|
12
|
+
@rr_address = IPAddr.new(@rr_value)
|
13
|
+
|
14
|
+
@rr_output = "google.com. 10000 IN A 64.233.187.99"
|
15
|
+
|
16
|
+
@rr = Net::DNS::RR::A.new(:name => @rr_name, :address => @rr_address, :ttl => @rr_ttl)
|
14
17
|
end
|
15
|
-
|
16
|
-
|
18
|
+
|
19
|
+
|
17
20
|
def test_initialize_from_hash
|
18
|
-
@record = Net::DNS::RR::A.new(:name => @rr_name, :address => @
|
19
|
-
assert_equal @rr_output, @record.
|
21
|
+
@record = Net::DNS::RR::A.new(:name => @rr_name, :address => @rr_value, :ttl => @rr_ttl)
|
22
|
+
assert_equal @rr_output, @record.to_s
|
20
23
|
assert_equal @rr_name, @record.name
|
21
24
|
assert_equal @rr_type, @record.type
|
22
25
|
assert_equal @rr_cls, @record.cls
|
23
26
|
assert_equal @rr_ttl, @record.ttl
|
24
|
-
assert_equal @rr_address, @record.address
|
27
|
+
assert_equal @rr_address, @record.address
|
28
|
+
assert_equal @rr_value, @record.value
|
25
29
|
end
|
26
|
-
|
30
|
+
|
27
31
|
def test_initialize_from_string
|
28
|
-
@record = Net::DNS::RR::A.new("#{@rr_name}
|
29
|
-
assert_equal @rr_output, @record.
|
32
|
+
@record = Net::DNS::RR::A.new("#{@rr_name} #{@rr_ttl} #{@rr_cls} #{@rr_type} #{@rr_value}")
|
33
|
+
assert_equal @rr_output, @record.to_s
|
30
34
|
assert_equal @rr_name, @record.name
|
31
35
|
assert_equal @rr_type, @record.type
|
32
36
|
assert_equal @rr_cls, @record.cls
|
33
37
|
assert_equal @rr_ttl, @record.ttl
|
34
|
-
assert_equal @rr_address, @record.address
|
38
|
+
assert_equal @rr_address, @record.address
|
39
|
+
assert_equal @rr_value, @record.value
|
35
40
|
end
|
36
|
-
|
41
|
+
|
37
42
|
def test_parse
|
38
|
-
data = "\006google\003com\000\000\001\000\001\000\000
|
43
|
+
data = "\006google\003com\000\000\001\000\001\000\000'\020\000\004@\351\273c"
|
39
44
|
@record = Net::DNS::RR.parse(data)
|
40
|
-
assert_equal @rr_output, @record.
|
45
|
+
assert_equal @rr_output, @record.to_s
|
41
46
|
assert_equal @rr_name, @record.name
|
42
47
|
assert_equal @rr_type, @record.type
|
43
48
|
assert_equal @rr_cls, @record.cls
|
44
49
|
assert_equal @rr_ttl, @record.ttl
|
45
|
-
assert_equal @rr_address, @record.address
|
50
|
+
assert_equal @rr_address, @record.address
|
51
|
+
assert_equal @rr_value, @record.value
|
46
52
|
end
|
47
|
-
|
48
|
-
|
53
|
+
|
54
|
+
|
49
55
|
InvalidArguments = [
|
50
56
|
{ :name => "google.com", :address => "255.256" },
|
51
57
|
{ :name => "google.com" },
|
@@ -55,12 +61,53 @@ class RRATest < Test::Unit::TestCase
|
|
55
61
|
"google.com. 10800 IN B",
|
56
62
|
"google.com. 10800 IM A",
|
57
63
|
]
|
58
|
-
|
64
|
+
|
59
65
|
InvalidArguments.each_with_index do |arguments, index|
|
60
66
|
define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
|
61
|
-
|
67
|
+
assert_raises(ArgumentError) { Net::DNS::RR::A.new(arguments) }
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
71
|
+
|
72
|
+
def test_address_getter
|
73
|
+
assert_equal @rr_address, @rr.address
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_address_setter
|
77
|
+
assert_raises(ArgumentError) { @rr.address = nil }
|
78
|
+
|
79
|
+
expected = IPAddr.new("64.233.187.99")
|
80
|
+
assert_equal expected, @rr.address = "64.233.187.99"
|
81
|
+
assert_equal expected, @rr.address
|
82
|
+
|
83
|
+
expected = IPAddr.new("64.233.187.90")
|
84
|
+
assert_equal expected, @rr.address = 1089059674
|
85
|
+
assert_equal expected, @rr.address
|
86
|
+
|
87
|
+
expected = IPAddr.new("64.233.187.80")
|
88
|
+
assert_equal expected, @rr.address = IPAddr.new("64.233.187.80")
|
89
|
+
assert_equal expected, @rr.address
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def test_value
|
94
|
+
assert_equal @rr_value, @rr.value
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def test_inspect
|
99
|
+
assert_equal "google.com. 10000 IN A 64.233.187.99",
|
100
|
+
@rr.inspect
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_to_s
|
104
|
+
assert_equal "google.com. 10000 IN A 64.233.187.99",
|
105
|
+
@rr.to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_to_a
|
109
|
+
assert_equal ["google.com.", 10000, "IN", "A", "64.233.187.99"],
|
110
|
+
@rr.to_a
|
111
|
+
end
|
112
|
+
|
65
113
|
end
|
66
|
-
|