net-dns 0.9.0 → 0.20.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 +4 -4
- data/CHANGELOG.md +29 -16
- data/README.md +1 -1
- data/lib/net/dns/header.rb +48 -64
- data/lib/net/dns/names.rb +8 -10
- data/lib/net/dns/packet.rb +46 -53
- data/lib/net/dns/question.rb +5 -3
- data/lib/net/dns/resolver/socks.rb +5 -7
- data/lib/net/dns/resolver/timeouts.rb +3 -5
- data/lib/net/dns/resolver.rb +54 -69
- data/lib/net/dns/rr/a.rb +3 -4
- data/lib/net/dns/rr/aaaa.rb +3 -5
- data/lib/net/dns/rr/classes.rb +6 -8
- data/lib/net/dns/rr/cname.rb +3 -5
- data/lib/net/dns/rr/hinfo.rb +9 -13
- data/lib/net/dns/rr/mr.rb +3 -5
- data/lib/net/dns/rr/mx.rb +5 -7
- data/lib/net/dns/rr/ns.rb +3 -5
- data/lib/net/dns/rr/null.rb +3 -5
- data/lib/net/dns/rr/ptr.rb +3 -5
- data/lib/net/dns/rr/soa.rb +11 -7
- data/lib/net/dns/rr/srv.rb +5 -2
- data/lib/net/dns/rr/txt.rb +4 -6
- data/lib/net/dns/rr/types.rb +90 -79
- data/lib/net/dns/rr.rb +2 -2
- data/lib/net/dns/version.rb +1 -1
- data/lib/net/dns.rb +3 -1
- metadata +11 -104
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -3
- data/.rubocop_defaults.yml +0 -364
- data/.rubocop_todo.yml +0 -207
- data/Gemfile +0 -8
- data/Rakefile +0 -38
- data/bin/console +0 -14
- data/lib/net/dns/core_ext.rb +0 -45
- data/net-dns.gemspec +0 -23
- data/spec/fixtures/resolv.conf +0 -4
- data/spec/spec_helper.rb +0 -14
- data/spec/unit/resolver/dns_timeout_spec.rb +0 -36
- data/spec/unit/resolver/tcp_timeout_spec.rb +0 -46
- data/spec/unit/resolver/udp_timeout_spec.rb +0 -46
- data/test/test_helper.rb +0 -13
- data/test/unit/header_test.rb +0 -164
- data/test/unit/names_test.rb +0 -21
- data/test/unit/packet_test.rb +0 -47
- data/test/unit/question_test.rb +0 -81
- data/test/unit/resolver_test.rb +0 -114
- data/test/unit/rr/a_test.rb +0 -106
- data/test/unit/rr/aaaa_test.rb +0 -102
- data/test/unit/rr/classes_test.rb +0 -83
- data/test/unit/rr/cname_test.rb +0 -90
- data/test/unit/rr/hinfo_test.rb +0 -111
- data/test/unit/rr/mr_test.rb +0 -99
- data/test/unit/rr/mx_test.rb +0 -106
- data/test/unit/rr/ns_test.rb +0 -80
- data/test/unit/rr/types_test.rb +0 -71
- data/test/unit/rr_test.rb +0 -127
data/spec/spec_helper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'net/dns'
|
3
|
-
|
4
|
-
unless defined?(SPEC_ROOT)
|
5
|
-
SPEC_ROOT = File.expand_path(__dir__)
|
6
|
-
end
|
7
|
-
|
8
|
-
# Requires supporting ruby files with custom matchers and macros, etc,
|
9
|
-
# in spec/support/ and its subdirectories.
|
10
|
-
Dir[File.join(SPEC_ROOT, "support/**/*.rb")].each { |f| require f }
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
config.mock_with :rspec
|
14
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'net/dns/resolver/timeouts'
|
3
|
-
|
4
|
-
describe Net::DNS::Resolver::DnsTimeout do
|
5
|
-
subject { described_class.new(10) }
|
6
|
-
|
7
|
-
describe "#initialize" do
|
8
|
-
it "returns an instance of DnsTimeout" do
|
9
|
-
expect(subject.class).to be(described_class)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "sets timeout" do
|
13
|
-
expect(described_class.new(0).seconds).to eq(0)
|
14
|
-
expect(described_class.new(10).seconds).to eq(10)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "raises ArgumentError when timeout is invalid" do
|
18
|
-
expect { described_class.new(nil) }.to raise_error(ArgumentError)
|
19
|
-
expect { described_class.new("") }.to raise_error(ArgumentError)
|
20
|
-
expect { described_class.new("foo") }.to raise_error(ArgumentError)
|
21
|
-
expect { described_class.new(-1) }.to raise_error(ArgumentError)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#to_s" do
|
26
|
-
it "returns the seconds" do
|
27
|
-
expect(subject.to_s).to eq("10")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#timeout" do
|
32
|
-
it "requires a block" do
|
33
|
-
expect { subject.timeout }.to raise_error(LocalJumpError)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'net/dns/resolver/timeouts'
|
3
|
-
|
4
|
-
describe Net::DNS::Resolver::TcpTimeout do
|
5
|
-
subject { described_class.new(10) }
|
6
|
-
|
7
|
-
it "inherits from DnsTimeout" do
|
8
|
-
expect(described_class.ancestors).to include(Net::DNS::Resolver::DnsTimeout)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#initialize" do
|
12
|
-
it "returns an instance of TcpTimeout" do
|
13
|
-
expect(subject.class).to be(described_class)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "sets timeout" do
|
17
|
-
expect(described_class.new(0).seconds).to eq(0)
|
18
|
-
expect(described_class.new(10).seconds).to eq(10)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "raises ArgumentError when timeout is invalid" do
|
22
|
-
expect { described_class.new(nil) }.to raise_error(ArgumentError)
|
23
|
-
expect { described_class.new("") }.to raise_error(ArgumentError)
|
24
|
-
expect { described_class.new("foo") }.to raise_error(ArgumentError)
|
25
|
-
expect { described_class.new(-1) }.to raise_error(ArgumentError)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#to_s" do
|
30
|
-
it "returns infinite when seconds is 0" do
|
31
|
-
expect(described_class.new(0).to_s).to eq("infinite")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns the seconds" do
|
35
|
-
expect(subject.to_s).to eq("10")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#pretty_to_s" do
|
40
|
-
it "returns a more verbose version" do
|
41
|
-
expect(described_class.new(30).pretty_to_s).to eq("30 seconds")
|
42
|
-
expect(described_class.new(90).pretty_to_s).to eq("1 minutes and 30 seconds")
|
43
|
-
expect(described_class.new(3690).pretty_to_s).to eq("1 hours, 1 minutes and 30 seconds")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'net/dns/resolver/timeouts'
|
3
|
-
|
4
|
-
describe Net::DNS::Resolver::UdpTimeout do
|
5
|
-
subject { described_class.new(10) }
|
6
|
-
|
7
|
-
it "inherits from DnsTimeout" do
|
8
|
-
expect(described_class.ancestors).to include(Net::DNS::Resolver::DnsTimeout)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#initialize" do
|
12
|
-
it "returns an instance of TcpTimeout" do
|
13
|
-
expect(subject.class).to be(described_class)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "sets timeout" do
|
17
|
-
expect(described_class.new(0).seconds).to eq(0)
|
18
|
-
expect(described_class.new(10).seconds).to eq(10)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "raises ArgumentError when timeout is invalid" do
|
22
|
-
expect { described_class.new(nil) }.to raise_error(ArgumentError)
|
23
|
-
expect { described_class.new("") }.to raise_error(ArgumentError)
|
24
|
-
expect { described_class.new("foo") }.to raise_error(ArgumentError)
|
25
|
-
expect { described_class.new(-1) }.to raise_error(ArgumentError)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#to_s" do
|
30
|
-
it "returns infinite when seconds is 0" do
|
31
|
-
expect(described_class.new(0).to_s).to eq("not defined")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns the seconds" do
|
35
|
-
expect(subject.to_s).to eq("10")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#pretty_to_s" do
|
40
|
-
it "returns a more verbose version" do
|
41
|
-
expect(described_class.new(30).pretty_to_s).to eq("30 seconds")
|
42
|
-
expect(described_class.new(90).pretty_to_s).to eq("1 minutes and 30 seconds")
|
43
|
-
expect(described_class.new(3690).pretty_to_s).to eq("1 hours, 1 minutes and 30 seconds")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require "minitest/autorun"
|
2
|
-
require "minitest/reporters"
|
3
|
-
|
4
|
-
Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
7
|
-
require "net/dns"
|
8
|
-
|
9
|
-
module Minitest::Assertions
|
10
|
-
def assert_nothing_raised(*)
|
11
|
-
yield
|
12
|
-
end
|
13
|
-
end
|
data/test/unit/header_test.rb
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'net/dns/header'
|
3
|
-
|
4
|
-
class HeaderTest < Minitest::Test
|
5
|
-
include Net::DNS
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@default = Header.new
|
9
|
-
@hash = Header.new(id: 441,
|
10
|
-
qr: 1,
|
11
|
-
opCode: Header::IQUERY,
|
12
|
-
aa: 1,
|
13
|
-
tc: 1,
|
14
|
-
rd: 0,
|
15
|
-
cd: 0,
|
16
|
-
ad: 0,
|
17
|
-
ra: 1,
|
18
|
-
rCode: Header::RCode::FORMAT,
|
19
|
-
qdCount: 1,
|
20
|
-
anCount: 2,
|
21
|
-
nsCount: 3,
|
22
|
-
arCount: 3)
|
23
|
-
|
24
|
-
@modified = Header.new
|
25
|
-
@modified.id = 442
|
26
|
-
@modified.qr = true
|
27
|
-
@modified.opCode = Header::IQUERY
|
28
|
-
@modified.aa = true
|
29
|
-
@modified.tc = true
|
30
|
-
@modified.rd = false
|
31
|
-
@modified.cd = false
|
32
|
-
@modified.ra = true
|
33
|
-
@modified.rCode = Header::RCode::FORMAT
|
34
|
-
@modified.qdCount = 1
|
35
|
-
@modified.anCount = 2
|
36
|
-
@modified.nsCount = 3
|
37
|
-
@modified.arCount = 3
|
38
|
-
|
39
|
-
@data = @modified.data
|
40
|
-
num = [(@data.unpack("n")[0] + 1)].pack("n")
|
41
|
-
@data[0] = num[0]
|
42
|
-
@data[1] = num[1]
|
43
|
-
@binary = Header.parse(@data)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_simple
|
47
|
-
assert_equal(@default.query?, true)
|
48
|
-
assert_equal(@default.response?, false)
|
49
|
-
assert_equal(@default.opCode, Header::QUERY)
|
50
|
-
assert_equal(@default.auth?, false)
|
51
|
-
assert_equal(@default.truncated?, false)
|
52
|
-
assert_equal(@default.recursive?, true)
|
53
|
-
assert_equal(@default.checking?, true)
|
54
|
-
assert_equal(@default.verified?, false)
|
55
|
-
assert_equal(@default.r_available?, false)
|
56
|
-
assert_equal(@default.rCode.code, Header::RCode::NOERROR)
|
57
|
-
assert_equal(@default.qdCount, 1)
|
58
|
-
assert_equal(@default.anCount, 0)
|
59
|
-
assert_equal(@default.nsCount, 0)
|
60
|
-
assert_equal(@default.arCount, 0)
|
61
|
-
|
62
|
-
assert_equal(@hash.id, 441)
|
63
|
-
assert_equal(@hash.query?, false)
|
64
|
-
assert_equal(@hash.response?, true)
|
65
|
-
assert_equal(@hash.opCode, Header::IQUERY)
|
66
|
-
assert_equal(@hash.auth?, true)
|
67
|
-
assert_equal(@hash.truncated?, true)
|
68
|
-
assert_equal(@hash.recursive?, false)
|
69
|
-
assert_equal(@hash.checking?, true)
|
70
|
-
assert_equal(@hash.verified?, false)
|
71
|
-
assert_equal(@hash.r_available?, true)
|
72
|
-
assert_equal(@hash.rCode.code, Header::RCode::FORMAT)
|
73
|
-
assert_equal(@hash.qdCount, 1)
|
74
|
-
assert_equal(@hash.anCount, 2)
|
75
|
-
assert_equal(@hash.nsCount, 3)
|
76
|
-
assert_equal(@hash.arCount, 3)
|
77
|
-
|
78
|
-
assert_equal(@modified.id, 442)
|
79
|
-
assert_equal(@modified.query?, false)
|
80
|
-
assert_equal(@modified.response?, true)
|
81
|
-
assert_equal(@modified.opCode, Header::IQUERY)
|
82
|
-
assert_equal(@modified.auth?, true)
|
83
|
-
assert_equal(@modified.truncated?, true)
|
84
|
-
assert_equal(@modified.recursive?, false)
|
85
|
-
assert_equal(@modified.checking?, true)
|
86
|
-
assert_equal(@modified.verified?, false)
|
87
|
-
assert_equal(@modified.r_available?, true)
|
88
|
-
assert_equal(@modified.rCode.code, Header::RCode::FORMAT)
|
89
|
-
assert_equal(@modified.qdCount, 1)
|
90
|
-
assert_equal(@modified.anCount, 2)
|
91
|
-
assert_equal(@modified.nsCount, 3)
|
92
|
-
assert_equal(@modified.arCount, 3)
|
93
|
-
|
94
|
-
assert_equal(@binary.data, @data)
|
95
|
-
|
96
|
-
assert_equal(@binary.id, 443)
|
97
|
-
assert_equal(@binary.query?, false)
|
98
|
-
assert_equal(@binary.response?, true)
|
99
|
-
assert_equal(@binary.opCode, Header::IQUERY)
|
100
|
-
assert_equal(@binary.auth?, true)
|
101
|
-
assert_equal(@binary.truncated?, true)
|
102
|
-
assert_equal(@binary.recursive?, false)
|
103
|
-
assert_equal(@binary.checking?, true)
|
104
|
-
assert_equal(@binary.verified?, false)
|
105
|
-
assert_equal(@binary.r_available?, true)
|
106
|
-
assert_equal(@binary.rCode.code, Header::RCode::FORMAT)
|
107
|
-
assert_equal(@binary.qdCount, 1)
|
108
|
-
assert_equal(@binary.anCount, 2)
|
109
|
-
assert_equal(@binary.nsCount, 3)
|
110
|
-
assert_equal(@binary.arCount, 3)
|
111
|
-
|
112
|
-
assert_raises(ArgumentError) do
|
113
|
-
Header.new([])
|
114
|
-
end
|
115
|
-
assert_raises(ArgumentError) do
|
116
|
-
Header.parse([])
|
117
|
-
end
|
118
|
-
assert_raises(ArgumentError) do
|
119
|
-
Header.parse("aa")
|
120
|
-
end
|
121
|
-
assert_raises(ArgumentError) do
|
122
|
-
@default.id = 1_000_000
|
123
|
-
end
|
124
|
-
assert_raises(ArgumentError) do
|
125
|
-
@default.qr = 2
|
126
|
-
end
|
127
|
-
assert_raises(Header::WrongOpcodeError) do
|
128
|
-
@default.opCode = 4
|
129
|
-
end
|
130
|
-
assert_raises(ArgumentError) do
|
131
|
-
@default.aa = 2
|
132
|
-
end
|
133
|
-
assert_raises(ArgumentError) do
|
134
|
-
@default.tc = 2
|
135
|
-
end
|
136
|
-
assert_raises(Header::WrongRecursiveError) do
|
137
|
-
@default.recursive = 2
|
138
|
-
end
|
139
|
-
assert_raises(ArgumentError) do
|
140
|
-
@default.ra = 2
|
141
|
-
end
|
142
|
-
assert_raises(ArgumentError) do
|
143
|
-
@default.cd = 2
|
144
|
-
end
|
145
|
-
assert_raises(ArgumentError) do
|
146
|
-
@default.ad = 2
|
147
|
-
end
|
148
|
-
assert_raises(ArgumentError) do
|
149
|
-
@default.rCode = 46
|
150
|
-
end
|
151
|
-
assert_raises(Header::WrongCountError) do
|
152
|
-
@default.qdCount = 100_000
|
153
|
-
end
|
154
|
-
assert_raises(Header::WrongCountError) do
|
155
|
-
@default.anCount = 100_000
|
156
|
-
end
|
157
|
-
assert_raises(Header::WrongCountError) do
|
158
|
-
@default.nsCount = 100_000
|
159
|
-
end
|
160
|
-
assert_raises(Header::WrongCountError) do
|
161
|
-
@default.arCount = 100_000
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
data/test/unit/names_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
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
|
data/test/unit/packet_test.rb
DELETED
@@ -1,47 +0,0 @@
|
|
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
|
data/test/unit/question_test.rb
DELETED
@@ -1,81 +0,0 @@
|
|
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
|
data/test/unit/resolver_test.rb
DELETED
@@ -1,114 +0,0 @@
|
|
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
|