dns_adapter 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dns_adapter/mock_client.rb +5 -0
- data/lib/dns_adapter/resolv_client.rb +5 -1
- data/lib/dns_adapter/version.rb +1 -1
- data/spec/resolv_client_spec.rb +54 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d8dfc76014b9bfd17a92150ac19f3846adad58e
|
4
|
+
data.tar.gz: 6aea0dfbb4a549a6304243cc7a777944027fea83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32bd75b2bdb092278b03737d27d3fefb4e1a5a1401b241e5507c1f710e870a314ff0cee804a0da547f46c20feac077d6a406e356fe23fe6fed0d408fba55012e
|
7
|
+
data.tar.gz: c027ec4d89fb7b870c823ff8f0dd80e6239fde10c2089cd23524d09938e610fa834c803e64ed07ac7707e760da85002e4348cfa062674775501f6fc109449525
|
@@ -30,6 +30,10 @@ module DNSAdapter
|
|
30
30
|
fetch_records(domain, 'NS')
|
31
31
|
end
|
32
32
|
|
33
|
+
def fetch_cname_records(domain)
|
34
|
+
fetch_records(domain, 'CNAME')
|
35
|
+
end
|
36
|
+
|
33
37
|
def fetch_txt_records(domain)
|
34
38
|
fetch_records(domain, 'TXT')
|
35
39
|
end
|
@@ -80,6 +84,7 @@ module DNSAdapter
|
|
80
84
|
'MX' => :exchange,
|
81
85
|
'PTR' => :name,
|
82
86
|
'NS' => :name,
|
87
|
+
'CNAME' => :name,
|
83
88
|
'SPF' => :text,
|
84
89
|
'TXT' => :text
|
85
90
|
}
|
@@ -38,6 +38,10 @@ module DNSAdapter
|
|
38
38
|
fetch_name_records(domain, 'NS')
|
39
39
|
end
|
40
40
|
|
41
|
+
def fetch_cname_records(domain)
|
42
|
+
fetch_name_records(domain, 'CNAME')
|
43
|
+
end
|
44
|
+
|
41
45
|
private
|
42
46
|
|
43
47
|
def fetch_a_type_records(domain, type)
|
@@ -104,7 +108,7 @@ module DNSAdapter
|
|
104
108
|
raise DNSAdapter::Error, "Error on DNS lookup of '#{domain}'"
|
105
109
|
end
|
106
110
|
|
107
|
-
SUPPORTED_RR_TYPES = %w(A AAAA MX PTR TXT SPF NS)
|
111
|
+
SUPPORTED_RR_TYPES = %w(A AAAA MX PTR TXT SPF NS CNAME)
|
108
112
|
def self.type_class(rr_type)
|
109
113
|
if SUPPORTED_RR_TYPES.include?(rr_type)
|
110
114
|
Resolv::DNS::Resource::IN.const_get(rr_type)
|
data/lib/dns_adapter/version.rb
CHANGED
data/spec/resolv_client_spec.rb
CHANGED
@@ -423,4 +423,58 @@ describe DNSAdapter::ResolvClient do
|
|
423
423
|
.to raise_error(DNSAdapter::TimeoutError)
|
424
424
|
end
|
425
425
|
end
|
426
|
+
|
427
|
+
context '#fetch_cname_records' do
|
428
|
+
let(:first_cname_name) { SecureRandom.hex(10) }
|
429
|
+
let(:first_cname_record) do
|
430
|
+
Resolv::DNS::Resource::IN::CNAME.new(first_cname_name)
|
431
|
+
end
|
432
|
+
let(:record_list) { [first_cname_record] }
|
433
|
+
let(:cname_domain) { 'example.com' }
|
434
|
+
let(:cname_domain_with_trailing) { "#{cname_domain}." }
|
435
|
+
|
436
|
+
it 'should map the Resolv classes to a set of hashes' do
|
437
|
+
expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
|
438
|
+
expect(mock_resolver).to receive(:getresources)
|
439
|
+
.with(cname_domain, Resolv::DNS::Resource::IN::CNAME)
|
440
|
+
.and_return(record_list)
|
441
|
+
results = subject.fetch_cname_records(cname_domain)
|
442
|
+
expect(results.size).to eq(record_list.length)
|
443
|
+
expect(results.map { |x| x[:type] })
|
444
|
+
.to eq(record_list.length.times.map { 'CNAME' })
|
445
|
+
expect(results.map { |x| x[:name] }).to eq(
|
446
|
+
[first_cname_name])
|
447
|
+
end
|
448
|
+
|
449
|
+
it 'should map when the domain has a trailing dot' do
|
450
|
+
expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
|
451
|
+
expect(mock_resolver).to receive(:getresources)
|
452
|
+
.with(cname_domain, Resolv::DNS::Resource::IN::CNAME)
|
453
|
+
.and_return(record_list)
|
454
|
+
results = subject.fetch_cname_records(cname_domain_with_trailing)
|
455
|
+
expect(results.size).to eq(record_list.length)
|
456
|
+
expect(results.map { |x| x[:type] })
|
457
|
+
.to eq(record_list.length.times.map { 'CNAME' })
|
458
|
+
expect(results.map { |x| x[:name] }).to eq(
|
459
|
+
[first_cname_name])
|
460
|
+
end
|
461
|
+
|
462
|
+
it 'should map the Resolv errors to Coppertone errors' do
|
463
|
+
expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
|
464
|
+
expect(mock_resolver).to receive(:getresources)
|
465
|
+
.with(cname_domain, Resolv::DNS::Resource::IN::CNAME)
|
466
|
+
.and_raise(Resolv::ResolvError)
|
467
|
+
expect { subject.fetch_cname_records(cname_domain_with_trailing) }
|
468
|
+
.to raise_error(DNSAdapter::Error)
|
469
|
+
end
|
470
|
+
|
471
|
+
it 'should map the Resolv timeout errors to Coppertone errors' do
|
472
|
+
expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
|
473
|
+
expect(mock_resolver).to receive(:getresources)
|
474
|
+
.with(cname_domain, Resolv::DNS::Resource::IN::CNAME)
|
475
|
+
.and_raise(Resolv::ResolvTimeout)
|
476
|
+
expect { subject.fetch_cname_records(cname_domain_with_trailing) }
|
477
|
+
.to raise_error(DNSAdapter::TimeoutError)
|
478
|
+
end
|
479
|
+
end
|
426
480
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dns_adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter M. Goldstein
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.4.
|
112
|
+
rubygems_version: 2.4.8
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: An adapter layer for DNS queries.
|