dns_adapter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f19132b4cfb08ff5ec8ebf1d890930207c2b8878
4
- data.tar.gz: 1b169dc215f89e09f844f64e4f0573704716b706
3
+ metadata.gz: 02c19670fbd1108a45d6c80bdac4329a77e784d2
4
+ data.tar.gz: 9a725d4d553ebec3386a505ee01ab6ce9a92a303
5
5
  SHA512:
6
- metadata.gz: 95f8e9bebe8cbe45c4f9b4c8b102e4184228952c202d274b8b6595dea6a8ccc774c13f5a190e2eabd8976314d61d57da1da79d25bec9ac56444899e96fcef345
7
- data.tar.gz: be86352abc7d1f4f5a038e6ead661fc620cc7f4955ea7d0078a6f10655b1efe5dd30cbe2f0bdddf33891ace87a6a913db2b71c3f2c80eb5aa10f5680108d8616
6
+ metadata.gz: 49fb8d15b30460c3034f36002fc5c891ff6dd02f44266d4c445b1e74f0a75bf9561ffff8993ece11fd5abb94e33466bfdea4e9b97d80363288a978585393022a
7
+ data.tar.gz: 4bf6e56344dae4e03a5ab49cd45d31d4a6060686d41668191ce66158d41ab928f18d0217d55790d80744cf1a8f7a688198dc3080a76a705944112b7398d78a69
@@ -23,13 +23,7 @@ module DNSAdapter
23
23
  end
24
24
 
25
25
  def fetch_ptr_records(arpa_address)
26
- fetch_records(arpa_address, 'PTR') do |record|
27
- {
28
- type: 'PTR',
29
- name: record.name.to_s,
30
- ttl: record.ttl
31
- }
32
- end
26
+ fetch_name_records(arpa_address, 'PTR')
33
27
  end
34
28
 
35
29
  def fetch_txt_records(domain)
@@ -40,6 +34,10 @@ module DNSAdapter
40
34
  fetch_txt_type_records(domain, 'SPF')
41
35
  end
42
36
 
37
+ def fetch_ns_records(domain)
38
+ fetch_name_records(domain, 'NS')
39
+ end
40
+
43
41
  private
44
42
 
45
43
  def fetch_a_type_records(domain, type)
@@ -64,6 +62,16 @@ module DNSAdapter
64
62
  end
65
63
  end
66
64
 
65
+ def fetch_name_records(domain, type)
66
+ fetch_records(domain, type) do |record|
67
+ {
68
+ type: type,
69
+ name: record.name.to_s,
70
+ ttl: record.ttl
71
+ }
72
+ end
73
+ end
74
+
67
75
  def fetch_records(domain, type, &block)
68
76
  records = dns_lookup(domain, type)
69
77
  records.map(&block)
@@ -96,7 +104,7 @@ module DNSAdapter
96
104
  raise DNSAdapter::Error, "Error on DNS lookup of '#{domain}'"
97
105
  end
98
106
 
99
- SUPPORTED_RR_TYPES = %w(A AAAA MX PTR TXT SPF)
107
+ SUPPORTED_RR_TYPES = %w(A AAAA MX PTR TXT SPF NS)
100
108
  def self.type_class(rr_type)
101
109
  if SUPPORTED_RR_TYPES.include?(rr_type)
102
110
  Resolv::DNS::Resource::IN.const_get(rr_type)
@@ -1,3 +1,3 @@
1
1
  module DNSAdapter
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe DNSAdapter::MockClient do
4
+ end
@@ -172,7 +172,8 @@ describe DNSAdapter::ResolvClient do
172
172
  it 'should map the Resolv errors to Coppertone errors' do
173
173
  expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
174
174
  expect(mock_resolver).to receive(:getresources)
175
- .with(domain, Resolv::DNS::Resource::IN::MX).and_raise(Resolv::ResolvError)
175
+ .with(domain, Resolv::DNS::Resource::IN::MX)
176
+ .and_raise(Resolv::ResolvError)
176
177
  expect { subject.fetch_mx_records(domain_with_trailing) }
177
178
  .to raise_error(DNSAdapter::Error)
178
179
  end
@@ -207,8 +208,8 @@ describe DNSAdapter::ResolvClient do
207
208
  it 'should map the Resolv classes to a set of hashes' do
208
209
  expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
209
210
  expect(mock_resolver).to receive(:getresources)
210
- .with(domain, Resolv::DNS::Resource::IN::TXT)
211
- .and_return(record_list)
211
+ .with(domain, Resolv::DNS::Resource::IN::TXT)
212
+ .and_return(record_list)
212
213
  results = subject.fetch_txt_records(domain)
213
214
  expect(results.size).to eq(record_list.length)
214
215
  expect(results.map { |x| x[:type] })
@@ -221,8 +222,8 @@ describe DNSAdapter::ResolvClient do
221
222
  it 'should map when the domain has a trailing dot' do
222
223
  expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
223
224
  expect(mock_resolver).to receive(:getresources)
224
- .with(domain, Resolv::DNS::Resource::IN::TXT)
225
- .and_return(record_list)
225
+ .with(domain, Resolv::DNS::Resource::IN::TXT)
226
+ .and_return(record_list)
226
227
  results = subject.fetch_txt_records(domain_with_trailing)
227
228
  expect(results.size).to eq(record_list.length)
228
229
  expect(results.map { |x| x[:type] })
@@ -271,8 +272,8 @@ describe DNSAdapter::ResolvClient do
271
272
  it 'should map the Resolv classes to a set of hashes' do
272
273
  expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
273
274
  expect(mock_resolver).to receive(:getresources)
274
- .with(domain, Resolv::DNS::Resource::IN::SPF)
275
- .and_return(record_list)
275
+ .with(domain, Resolv::DNS::Resource::IN::SPF)
276
+ .and_return(record_list)
276
277
  results = subject.fetch_spf_records(domain)
277
278
  expect(results.size).to eq(record_list.length)
278
279
  expect(results.map { |x| x[:type] })
@@ -285,8 +286,8 @@ describe DNSAdapter::ResolvClient do
285
286
  it 'should map when the domain has a trailing dot' do
286
287
  expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
287
288
  expect(mock_resolver).to receive(:getresources)
288
- .with(domain, Resolv::DNS::Resource::IN::SPF)
289
- .and_return(record_list)
289
+ .with(domain, Resolv::DNS::Resource::IN::SPF)
290
+ .and_return(record_list)
290
291
  results = subject.fetch_spf_records(domain_with_trailing)
291
292
  expect(results.size).to eq(record_list.length)
292
293
  expect(results.map { |x| x[:type] })
@@ -327,8 +328,8 @@ describe DNSAdapter::ResolvClient do
327
328
  it 'should map the Resolv classes to a set of hashes' do
328
329
  expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
329
330
  expect(mock_resolver).to receive(:getresources)
330
- .with(arpa_domain, Resolv::DNS::Resource::IN::PTR)
331
- .and_return(record_list)
331
+ .with(arpa_domain, Resolv::DNS::Resource::IN::PTR)
332
+ .and_return(record_list)
332
333
  results = subject.fetch_ptr_records(arpa_domain)
333
334
  expect(results.size).to eq(record_list.length)
334
335
  expect(results.map { |x| x[:type] })
@@ -340,8 +341,8 @@ describe DNSAdapter::ResolvClient do
340
341
  it 'should map when the domain has a trailing dot' do
341
342
  expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
342
343
  expect(mock_resolver).to receive(:getresources)
343
- .with(arpa_domain, Resolv::DNS::Resource::IN::PTR)
344
- .and_return(record_list)
344
+ .with(arpa_domain, Resolv::DNS::Resource::IN::PTR)
345
+ .and_return(record_list)
345
346
  results = subject.fetch_ptr_records(arpa_domain_with_trailing)
346
347
  expect(results.size).to eq(record_list.length)
347
348
  expect(results.map { |x| x[:type] })
@@ -368,4 +369,58 @@ describe DNSAdapter::ResolvClient do
368
369
  .to raise_error(DNSAdapter::TimeoutError)
369
370
  end
370
371
  end
372
+
373
+ context '#fetch_ns_records' do
374
+ let(:first_ns_name) { SecureRandom.hex(10) }
375
+ let(:first_ns_record) do
376
+ Resolv::DNS::Resource::IN::NS.new(first_ns_name)
377
+ end
378
+ let(:record_list) { [first_ns_record] }
379
+ let(:ns_domain) { 'example.com' }
380
+ let(:ns_domain_with_trailing) { "#{ns_domain}." }
381
+
382
+ it 'should map the Resolv classes to a set of hashes' do
383
+ expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
384
+ expect(mock_resolver).to receive(:getresources)
385
+ .with(ns_domain, Resolv::DNS::Resource::IN::NS)
386
+ .and_return(record_list)
387
+ results = subject.fetch_ns_records(ns_domain)
388
+ expect(results.size).to eq(record_list.length)
389
+ expect(results.map { |x| x[:type] })
390
+ .to eq(record_list.length.times.map { 'NS' })
391
+ expect(results.map { |x| x[:name] }).to eq(
392
+ [first_ns_name])
393
+ end
394
+
395
+ it 'should map when the domain has a trailing dot' do
396
+ expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
397
+ expect(mock_resolver).to receive(:getresources)
398
+ .with(ns_domain, Resolv::DNS::Resource::IN::NS)
399
+ .and_return(record_list)
400
+ results = subject.fetch_ns_records(ns_domain_with_trailing)
401
+ expect(results.size).to eq(record_list.length)
402
+ expect(results.map { |x| x[:type] })
403
+ .to eq(record_list.length.times.map { 'NS' })
404
+ expect(results.map { |x| x[:name] }).to eq(
405
+ [first_ns_name])
406
+ end
407
+
408
+ it 'should map the Resolv errors to Coppertone errors' do
409
+ expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
410
+ expect(mock_resolver).to receive(:getresources)
411
+ .with(ns_domain, Resolv::DNS::Resource::IN::NS)
412
+ .and_raise(Resolv::ResolvError)
413
+ expect { subject.fetch_ns_records(ns_domain_with_trailing) }
414
+ .to raise_error(DNSAdapter::Error)
415
+ end
416
+
417
+ it 'should map the Resolv timeout errors to Coppertone errors' do
418
+ expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
419
+ expect(mock_resolver).to receive(:getresources)
420
+ .with(ns_domain, Resolv::DNS::Resource::IN::NS)
421
+ .and_raise(Resolv::ResolvTimeout)
422
+ expect { subject.fetch_ns_records(ns_domain_with_trailing) }
423
+ .to raise_error(DNSAdapter::TimeoutError)
424
+ end
425
+ end
371
426
  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.2
4
+ version: 0.0.3
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-01-05 00:00:00.000000000 Z
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - lib/dns_adapter/resolv_client.rb
87
87
  - lib/dns_adapter/version.rb
88
88
  - lib/resolv/dns/resource/in/spf.rb
89
+ - spec/mock_client_spec.rb
89
90
  - spec/resolv_client_spec.rb
90
91
  - spec/spec_helper.rb
91
92
  homepage: https://github.com/petergoldstein/dns_adapter
@@ -108,10 +109,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  requirements: []
110
111
  rubyforge_project:
111
- rubygems_version: 2.4.5
112
+ rubygems_version: 2.4.6
112
113
  signing_key:
113
114
  specification_version: 4
114
115
  summary: An adapter layer for DNS queries.
115
116
  test_files:
117
+ - spec/mock_client_spec.rb
116
118
  - spec/resolv_client_spec.rb
117
119
  - spec/spec_helper.rb