gitlab-net-dns 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.gitlab-ci.yml +20 -0
- data/.rspec +1 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_defaults.yml +359 -0
- data/.rubocop_todo.yml +207 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +113 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +56 -0
- data/README.md +172 -0
- data/Rakefile +38 -0
- data/THANKS.rdoc +24 -0
- data/bin/console +14 -0
- data/demo/check_soa.rb +104 -0
- data/demo/threads.rb +18 -0
- data/gitlab-net-dns.gemspec +24 -0
- data/lib/net/dns.rb +104 -0
- data/lib/net/dns/header.rb +705 -0
- data/lib/net/dns/names.rb +120 -0
- data/lib/net/dns/packet.rb +560 -0
- data/lib/net/dns/question.rb +185 -0
- data/lib/net/dns/resolver.rb +1214 -0
- data/lib/net/dns/resolver/socks.rb +148 -0
- data/lib/net/dns/resolver/timeouts.rb +70 -0
- data/lib/net/dns/rr.rb +356 -0
- data/lib/net/dns/rr/a.rb +114 -0
- data/lib/net/dns/rr/aaaa.rb +94 -0
- data/lib/net/dns/rr/classes.rb +130 -0
- data/lib/net/dns/rr/cname.rb +74 -0
- data/lib/net/dns/rr/hinfo.rb +96 -0
- data/lib/net/dns/rr/mr.rb +70 -0
- data/lib/net/dns/rr/mx.rb +82 -0
- data/lib/net/dns/rr/ns.rb +70 -0
- data/lib/net/dns/rr/null.rb +50 -0
- data/lib/net/dns/rr/ptr.rb +77 -0
- data/lib/net/dns/rr/soa.rb +75 -0
- data/lib/net/dns/rr/srv.rb +41 -0
- data/lib/net/dns/rr/txt.rb +58 -0
- data/lib/net/dns/rr/types.rb +191 -0
- data/lib/net/dns/version.rb +8 -0
- data/spec/fixtures/resolv.conf +4 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/unit/resolver/dns_timeout_spec.rb +36 -0
- data/spec/unit/resolver/tcp_timeout_spec.rb +46 -0
- data/spec/unit/resolver/udp_timeout_spec.rb +46 -0
- data/test/test_helper.rb +13 -0
- data/test/unit/header_test.rb +164 -0
- data/test/unit/names_test.rb +21 -0
- data/test/unit/packet_test.rb +47 -0
- data/test/unit/question_test.rb +81 -0
- data/test/unit/resolver_test.rb +114 -0
- data/test/unit/rr/a_test.rb +106 -0
- data/test/unit/rr/aaaa_test.rb +102 -0
- data/test/unit/rr/classes_test.rb +83 -0
- data/test/unit/rr/cname_test.rb +90 -0
- data/test/unit/rr/hinfo_test.rb +111 -0
- data/test/unit/rr/mr_test.rb +99 -0
- data/test/unit/rr/mx_test.rb +106 -0
- data/test/unit/rr/ns_test.rb +80 -0
- data/test/unit/rr/types_test.rb +71 -0
- data/test/unit/rr_test.rb +127 -0
- metadata +172 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/names'
|
3
|
+
|
4
|
+
class NamesTest < Minitest::Test
|
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
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/packet'
|
3
|
+
|
4
|
+
class PacketTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@klass = Net::DNS::Packet
|
7
|
+
@domain = 'example.com'
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_initialize
|
11
|
+
@record = @klass.new(@domain, Net::DNS::MX, Net::DNS::HS)
|
12
|
+
assert_instance_of @klass, @record
|
13
|
+
assert_instance_of Net::DNS::Header, @record.header
|
14
|
+
assert_instance_of Array, @record.question
|
15
|
+
assert_instance_of Net::DNS::Question, @record.question.first
|
16
|
+
assert_instance_of Array, @record.answer
|
17
|
+
assert_instance_of Array, @record.authority
|
18
|
+
assert_instance_of Array, @record.additional
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_initialize_should_set_question
|
22
|
+
@question = @klass.new(@domain).question.first
|
23
|
+
assert_equal @domain, @question.qName
|
24
|
+
assert_equal Net::DNS::RR::Types.new(Net::DNS::A).to_s, @question.qType.to_s
|
25
|
+
assert_equal Net::DNS::RR::Classes.new(Net::DNS::IN).to_s, @question.qClass.to_s
|
26
|
+
|
27
|
+
@question = @klass.new(@domain, Net::DNS::MX, Net::DNS::HS).question.first
|
28
|
+
assert_equal @domain, @question.qName
|
29
|
+
assert_equal Net::DNS::RR::Types.new(Net::DNS::MX).to_s, @question.qType.to_s
|
30
|
+
assert_equal Net::DNS::RR::Classes.new(Net::DNS::HS).to_s, @question.qClass.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_self_parse
|
34
|
+
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"
|
35
|
+
@record = @klass.parse(packet)
|
36
|
+
assert_instance_of @klass, @record
|
37
|
+
assert_instance_of Net::DNS::Header, @record.header
|
38
|
+
assert_instance_of Array, @record.question
|
39
|
+
assert_instance_of Net::DNS::Question, @record.question.first
|
40
|
+
assert_instance_of Array, @record.answer
|
41
|
+
assert_instance_of Net::DNS::RR::A, @record.answer.first
|
42
|
+
assert_instance_of Array, @record.authority
|
43
|
+
assert_instance_of Net::DNS::RR::NS, @record.authority.first
|
44
|
+
assert_instance_of Array, @record.additional
|
45
|
+
assert_instance_of Net::DNS::RR::A, @record.additional.first
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/question'
|
3
|
+
|
4
|
+
class QuestionTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@domain = 'example.com.'
|
7
|
+
@type = 'MX'
|
8
|
+
@cls = 'HS'
|
9
|
+
@data = "\006google\003com\000\000\001\000\001"
|
10
|
+
|
11
|
+
@default = Net::DNS::Question.new(@domain)
|
12
|
+
@string = Net::DNS::Question.new(@domain, @type, @cls)
|
13
|
+
@binary = Net::DNS::Question.parse(@data)
|
14
|
+
@binary2 = Net::DNS::Question.parse(@string.data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_simple
|
18
|
+
assert_equal(@default.qName, @domain)
|
19
|
+
assert_equal(@default.qType.to_s, "A")
|
20
|
+
assert_equal(@default.qClass.to_s, "IN")
|
21
|
+
|
22
|
+
assert_equal(@string.qName, @domain)
|
23
|
+
assert_equal(@string.qType.to_s, "MX")
|
24
|
+
assert_equal(@string.qClass.to_s, "HS")
|
25
|
+
|
26
|
+
assert_equal(@binary.qName, "google.com.")
|
27
|
+
assert_equal(@binary.qType.to_s, "A")
|
28
|
+
assert_equal(@binary.qClass.to_s, "IN")
|
29
|
+
|
30
|
+
assert_equal(@binary2.qName, @domain)
|
31
|
+
assert_equal(@binary2.qType.to_s, "MX")
|
32
|
+
assert_equal(@binary2.qClass.to_s, "HS")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_raise
|
36
|
+
# assert_raises(Net::DNS::Question::NameInvalid) do
|
37
|
+
# Net::DNS::Question.new(1)
|
38
|
+
# end
|
39
|
+
assert_raises(Net::DNS::Question::NameInvalid) do
|
40
|
+
Net::DNS::Question.new("test{")
|
41
|
+
end
|
42
|
+
assert_raises(ArgumentError) do
|
43
|
+
Net::DNS::Question.parse([])
|
44
|
+
end
|
45
|
+
assert_raises(ArgumentError) do
|
46
|
+
Net::DNS::Question.parse("test")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_inspect
|
51
|
+
assert_equal "google.com. IN A ",
|
52
|
+
Net::DNS::Question.new("google.com.").inspect
|
53
|
+
assert_equal "google.com. IN A ",
|
54
|
+
Net::DNS::Question.new("google.com.", Net::DNS::A).inspect
|
55
|
+
assert_equal "google.com. IN NS ",
|
56
|
+
Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
|
57
|
+
assert_equal "google.com. IN NS ",
|
58
|
+
Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_inspect_with_name_longer_than_29_chrs
|
62
|
+
assert_equal "supercalifragilistichespiralidoso.com IN A ",
|
63
|
+
Net::DNS::Question.new("supercalifragilistichespiralidoso.com").inspect
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_to_s
|
67
|
+
assert_equal "google.com. IN A ",
|
68
|
+
Net::DNS::Question.new("google.com.").to_s
|
69
|
+
assert_equal "google.com. IN A ",
|
70
|
+
Net::DNS::Question.new("google.com.", Net::DNS::A).to_s
|
71
|
+
assert_equal "google.com. IN NS ",
|
72
|
+
Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
|
73
|
+
assert_equal "google.com. IN NS ",
|
74
|
+
Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_to_s_with_name_longer_than_29_chrs
|
78
|
+
assert_equal "supercalifragilistichespiralidoso.com IN A ",
|
79
|
+
Net::DNS::Question.new("supercalifragilistichespiralidoso.com").to_s
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/resolver'
|
3
|
+
|
4
|
+
class Net::DNS::Resolver
|
5
|
+
attr_reader :config
|
6
|
+
end
|
7
|
+
|
8
|
+
class ResolverTest < Minitest::Test
|
9
|
+
def test_initialize
|
10
|
+
assert_nothing_raised { Net::DNS::Resolver.new }
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize_with_config
|
14
|
+
assert_nothing_raised { Net::DNS::Resolver.new({}) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize_with_multi_name_servers
|
18
|
+
resolver = Net::DNS::Resolver.new(config_file: File.expand_path('../../spec/fixtures/resolv.conf', __dir__))
|
19
|
+
assert_equal ['192.168.1.1', '192.168.1.2', '192.168.1.3', '192.168.1.4'], resolver.nameservers
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initialize_with_invalid_config_should_raise_argumenterror
|
23
|
+
assert_raises(ArgumentError) { Net::DNS::Resolver.new("") }
|
24
|
+
assert_raises(ArgumentError) { Net::DNS::Resolver.new(0) }
|
25
|
+
assert_raises(ArgumentError) { Net::DNS::Resolver.new(:foo) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_query_with_no_nameservers_should_raise_resolvererror
|
29
|
+
assert_raises(Net::DNS::Resolver::Error) { Net::DNS::Resolver.new(nameservers: []).query("example.com") }
|
30
|
+
end
|
31
|
+
|
32
|
+
# def test_send_to_ipv6_nameserver_should_not_raise_einval
|
33
|
+
# assert_nothing_raised { Net::DNS::Resolver.new(:nameservers => ['2001:4860:4860::8888', '2001:4860:4860::8844']).send('example.com')}
|
34
|
+
# end
|
35
|
+
|
36
|
+
# I know private methods are supposed to not be tested directly
|
37
|
+
# but since this library lacks unit tests, for now let me test them in this way.
|
38
|
+
|
39
|
+
def _make_query_packet(*args)
|
40
|
+
Net::DNS::Resolver.new.send(:make_query_packet, *args)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_make_query_packet_from_ipaddr
|
44
|
+
packet = _make_query_packet(IPAddr.new("192.168.1.1"), Net::DNS::A, cls = Net::DNS::IN)
|
45
|
+
assert_equal "1.1.168.192.in-addr.arpa", packet.question.first.qName
|
46
|
+
assert_equal Net::DNS::PTR.to_i, packet.question.first.qType.to_i
|
47
|
+
assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_make_query_packet_from_string_like_ipv4
|
51
|
+
packet = _make_query_packet("192.168.1.1", Net::DNS::A, cls = Net::DNS::IN)
|
52
|
+
assert_equal "1.1.168.192.in-addr.arpa", packet.question.first.qName
|
53
|
+
assert_equal Net::DNS::PTR.to_i, packet.question.first.qType.to_i
|
54
|
+
assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_make_query_packet_from_string_like_ipv6
|
58
|
+
packet = _make_query_packet("2001:1ac0::200:0:a5d1:6004:2", Net::DNS::A, cls = Net::DNS::IN)
|
59
|
+
assert_equal "2.0.0.0.4.0.0.6.1.d.5.a.0.0.0.0.0.0.2.0.0.0.0.0.0.c.a.1.1.0.0.2.ip6.arpa", packet.question.first.qName
|
60
|
+
assert_equal Net::DNS::PTR.to_i, packet.question.first.qType.to_i
|
61
|
+
assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_make_query_packet_from_string_like_hostname
|
65
|
+
packet = _make_query_packet("ns2.google.com", Net::DNS::A, cls = Net::DNS::IN)
|
66
|
+
assert_equal "ns2.google.com", packet.question.first.qName
|
67
|
+
assert_equal Net::DNS::A.to_i, packet.question.first.qType.to_i
|
68
|
+
assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_make_query_packet_from_string_like_hostname_with_number
|
72
|
+
packet = _make_query_packet("ns.google.com", Net::DNS::A, cls = Net::DNS::IN)
|
73
|
+
assert_equal "ns.google.com", packet.question.first.qName
|
74
|
+
assert_equal Net::DNS::A.to_i, packet.question.first.qType.to_i
|
75
|
+
assert_equal Net::DNS::IN.to_i, packet.question.first.qClass.to_i
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_should_return_state_without_exception
|
79
|
+
res = Net::DNS::Resolver.new
|
80
|
+
assert_nothing_raised { res.state }
|
81
|
+
end
|
82
|
+
|
83
|
+
RubyPlatforms = [
|
84
|
+
["darwin9.0", false], # Mac OS X
|
85
|
+
["darwin", false], # JRuby on Mac OS X
|
86
|
+
["linux-gnu", false],
|
87
|
+
["mingw32", true], # ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-mingw32]
|
88
|
+
["mswin32", true], # ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-mswin32]
|
89
|
+
["mswin32", true], # ruby 1.8.6 (2008-04-22 rev 6555) [x86-jruby1.1.1]
|
90
|
+
].freeze
|
91
|
+
|
92
|
+
C = Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG
|
93
|
+
|
94
|
+
def test_self_platform_windows_question
|
95
|
+
RubyPlatforms.each do |platform, is_windows|
|
96
|
+
assert_equal is_windows,
|
97
|
+
override_platform(platform) { Net::DNS::Resolver.platform_windows? },
|
98
|
+
"Expected `#{is_windows}' with platform `#{platform}'"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def override_platform(new_platform, &block)
|
105
|
+
raise LocalJumpError, "no block given" unless block_given?
|
106
|
+
|
107
|
+
old_platform = C["host_os"]
|
108
|
+
C["host_os"] = new_platform
|
109
|
+
result = yield
|
110
|
+
ensure
|
111
|
+
C["host_os"] = old_platform
|
112
|
+
result
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/rr'
|
3
|
+
|
4
|
+
class RRATest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@rr_name = "google.com."
|
7
|
+
@rr_type = "A"
|
8
|
+
@rr_cls = "IN"
|
9
|
+
@rr_ttl = 10_000
|
10
|
+
@rr_value = "64.233.187.99"
|
11
|
+
@rr_address = IPAddr.new(@rr_value)
|
12
|
+
|
13
|
+
@rr_output = "google.com. 10000 IN A 64.233.187.99"
|
14
|
+
|
15
|
+
@rr = Net::DNS::RR::A.new(name: @rr_name, address: @rr_address, ttl: @rr_ttl)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_initialize_from_hash
|
19
|
+
@record = Net::DNS::RR::A.new(name: @rr_name, address: @rr_value, ttl: @rr_ttl)
|
20
|
+
assert_equal @rr_output, @record.to_s
|
21
|
+
assert_equal @rr_name, @record.name
|
22
|
+
assert_equal @rr_type, @record.type
|
23
|
+
assert_equal @rr_cls, @record.cls
|
24
|
+
assert_equal @rr_ttl, @record.ttl
|
25
|
+
assert_equal @rr_address, @record.address
|
26
|
+
assert_equal @rr_value, @record.value
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_initialize_from_string
|
30
|
+
@record = Net::DNS::RR::A.new("#{@rr_name} #{@rr_ttl} #{@rr_cls} #{@rr_type} #{@rr_value}")
|
31
|
+
assert_equal @rr_output, @record.to_s
|
32
|
+
assert_equal @rr_name, @record.name
|
33
|
+
assert_equal @rr_type, @record.type
|
34
|
+
assert_equal @rr_cls, @record.cls
|
35
|
+
assert_equal @rr_ttl, @record.ttl
|
36
|
+
assert_equal @rr_address, @record.address
|
37
|
+
assert_equal @rr_value, @record.value
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_parse
|
41
|
+
data = "\006google\003com\000\000\001\000\001\000\000'\020\000\004@\351\273c"
|
42
|
+
@record = Net::DNS::RR.parse(data)
|
43
|
+
assert_equal @rr_output, @record.to_s
|
44
|
+
assert_equal @rr_name, @record.name
|
45
|
+
assert_equal @rr_type, @record.type
|
46
|
+
assert_equal @rr_cls, @record.cls
|
47
|
+
assert_equal @rr_ttl, @record.ttl
|
48
|
+
assert_equal @rr_address, @record.address
|
49
|
+
assert_equal @rr_value, @record.value
|
50
|
+
end
|
51
|
+
|
52
|
+
InvalidArguments = [
|
53
|
+
{ name: "google.com", address: "255.256" },
|
54
|
+
{ name: "google.com" },
|
55
|
+
Object.new,
|
56
|
+
Array.new(7),
|
57
|
+
"10800 IN A",
|
58
|
+
"google.com. 10800 IN B",
|
59
|
+
"google.com. 10800 IM A",
|
60
|
+
].freeze
|
61
|
+
|
62
|
+
InvalidArguments.each_with_index do |arguments, index|
|
63
|
+
define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
|
64
|
+
assert_raises(ArgumentError) { Net::DNS::RR::A.new(arguments) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_address_getter
|
69
|
+
assert_equal @rr_address, @rr.address
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_address_setter
|
73
|
+
assert_raises(ArgumentError) { @rr.address = nil }
|
74
|
+
|
75
|
+
expected = IPAddr.new("64.233.187.99")
|
76
|
+
assert_equal expected, @rr.address = "64.233.187.99"
|
77
|
+
assert_equal expected, @rr.address
|
78
|
+
|
79
|
+
expected = IPAddr.new("64.233.187.90")
|
80
|
+
assert_equal expected, @rr.address = expected.to_i
|
81
|
+
assert_equal expected, @rr.address
|
82
|
+
|
83
|
+
expected = IPAddr.new("64.233.187.80")
|
84
|
+
assert_equal expected, @rr.address = IPAddr.new("64.233.187.80")
|
85
|
+
assert_equal expected, @rr.address
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_value
|
89
|
+
assert_equal @rr_value, @rr.value
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_inspect
|
93
|
+
assert_equal "google.com. 10000 IN A 64.233.187.99",
|
94
|
+
@rr.inspect
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_to_s
|
98
|
+
assert_equal "google.com. 10000 IN A 64.233.187.99",
|
99
|
+
@rr.to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_to_a
|
103
|
+
assert_equal ["google.com.", 10_000, "IN", "A", "64.233.187.99"],
|
104
|
+
@rr.to_a
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/rr'
|
3
|
+
|
4
|
+
class RRAAAATest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@rr_name = "www.nic.it."
|
7
|
+
@rr_type = "AAAA"
|
8
|
+
@rr_cls = "IN"
|
9
|
+
@rr_ttl = 60
|
10
|
+
@rr_value = "2a00:d40:1:1::239"
|
11
|
+
@rr_address = IPAddr.new(@rr_value)
|
12
|
+
|
13
|
+
@rr_output = "www.nic.it. 60 IN AAAA 2a00:d40:1:1::239"
|
14
|
+
|
15
|
+
@rr = Net::DNS::RR::AAAA.new(name: @rr_name, address: @rr_address, ttl: @rr_ttl)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_initialize_from_hash
|
19
|
+
@record = Net::DNS::RR::AAAA.new(name: @rr_name, address: @rr_value, ttl: @rr_ttl)
|
20
|
+
assert_equal @rr_output, @record.to_s
|
21
|
+
assert_equal @rr_name, @record.name
|
22
|
+
assert_equal @rr_type, @record.type
|
23
|
+
assert_equal @rr_cls, @record.cls
|
24
|
+
assert_equal @rr_ttl, @record.ttl
|
25
|
+
assert_equal @rr_address, @record.address
|
26
|
+
assert_equal @rr_value, @record.value
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_initialize_from_string
|
30
|
+
@record = Net::DNS::RR::AAAA.new("#{@rr_name} #{@rr_ttl} #{@rr_cls} #{@rr_type} #{@rr_value}")
|
31
|
+
assert_equal @rr_output, @record.to_s
|
32
|
+
assert_equal @rr_name, @record.name
|
33
|
+
assert_equal @rr_type, @record.type
|
34
|
+
assert_equal @rr_cls, @record.cls
|
35
|
+
assert_equal @rr_ttl, @record.ttl
|
36
|
+
assert_equal @rr_address, @record.address
|
37
|
+
assert_equal @rr_value, @record.value
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_parse
|
41
|
+
data = "\003www\003nic\002it\000\000\034\000\001\000\000\000<\000\020*\000\r@\000\001\000\001\000\000\000\000\000\000\0029"
|
42
|
+
@record = Net::DNS::RR.parse(data)
|
43
|
+
assert_equal @rr_output, @record.to_s
|
44
|
+
assert_equal @rr_name, @record.name
|
45
|
+
assert_equal @rr_type, @record.type
|
46
|
+
assert_equal @rr_cls, @record.cls
|
47
|
+
assert_equal @rr_ttl, @record.ttl
|
48
|
+
assert_equal @rr_address, @record.address
|
49
|
+
assert_equal @rr_value, @record.value
|
50
|
+
end
|
51
|
+
|
52
|
+
InvalidArguments = [
|
53
|
+
{ name: "google.com", address: "2a00" },
|
54
|
+
{ name: "google.com" },
|
55
|
+
Object.new,
|
56
|
+
Array.new(7),
|
57
|
+
"10800 IN AAAA",
|
58
|
+
# FIXME: "google.com. 10800 IN B",
|
59
|
+
# FIXME: "google.com. 10800 IM AAAA",
|
60
|
+
].freeze
|
61
|
+
|
62
|
+
InvalidArguments.each_with_index do |arguments, index|
|
63
|
+
define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
|
64
|
+
assert_raises(ArgumentError) { Net::DNS::RR::AAAA.new(arguments) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_address_getter
|
69
|
+
assert_equal @rr_address, @rr.address
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_address_setter
|
73
|
+
assert_raises(ArgumentError) { @rr.address = nil }
|
74
|
+
|
75
|
+
expected = IPAddr.new("2a00:d40:1:1::239")
|
76
|
+
assert_equal expected, @rr.address = "2a00:d40:1:1::239"
|
77
|
+
assert_equal expected, @rr.address
|
78
|
+
|
79
|
+
expected = IPAddr.new("2a00:d40:1:1::240")
|
80
|
+
assert_equal expected, @rr.address = IPAddr.new("2a00:d40:1:1::240")
|
81
|
+
assert_equal expected, @rr.address
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_value
|
85
|
+
assert_equal @rr_value, @rr.value
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_inspect
|
89
|
+
assert_equal "www.nic.it. 60 IN AAAA 2a00:d40:1:1::239",
|
90
|
+
@rr.inspect
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_to_s
|
94
|
+
assert_equal "www.nic.it. 60 IN AAAA 2a00:d40:1:1::239",
|
95
|
+
@rr.to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_to_a
|
99
|
+
assert_equal ["www.nic.it.", 60, "IN", "AAAA", "2a00:d40:1:1::239"],
|
100
|
+
@rr.to_a
|
101
|
+
end
|
102
|
+
end
|