rspec-dns 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YWZhYzZhZTc5ZjFiZWY2MzRhMjIwMWMyYzhhNjQ2N2M3YWQxYWEyZg==
5
- data.tar.gz: !binary |-
6
- YTNiNTQyZWU5ZTBmM2ZhYTMzMmI4MjFhMjAyNGFmMWFhYWE3ZGQ0MQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZTAyZWQ5NGM5YWRhNmI3YzIxOWNiZGUxMzcxNWE5ZTI1ZjY1YjVkYjY5YjI2
10
- YjBhMTEzMWQ2OGEzYWYxYTE4MGJjOTFlYzRiNWQ0ZjJkODcyZmUzZmNhZjgw
11
- YWFiZWE1MzQzMTk0Mzk0OTMyZDk3ZjcyOTI4YmZlNjJkNjYwN2I=
12
- data.tar.gz: !binary |-
13
- NmEzYmE0ZjdiYmJhODJlZjllYjhjMjVkZGQ3MjMxZDc0Njc1NDE5ZjAxZjZj
14
- YTdiNDE3ZjQzMTQxZjc1ODhlMjZlZTgzMTQyNTZjNTY1Y2M1M2NmYTE4ZTJm
15
- MDIwZTIzOTRmZWUxNzE0ZmYyNzY0YjA5ZDg2ZGJkZjA1Y2YyZDE=
2
+ SHA1:
3
+ metadata.gz: e2d0c99bfad61e22a989ccc3544a63b9a84bb7f1
4
+ data.tar.gz: c8f66c1099c58144d58bf5bc7887ba0367f2d6ed
5
+ SHA512:
6
+ metadata.gz: af49390d95c4cbf8ae1fc2ba64734c8796f4b73224e5009affe4e04f6fc56869b76e1bd9a203c41091038b0c0e5dbce88f39972da85464c941c44b2899ac59d5
7
+ data.tar.gz: 4b6215758311f378b00bedfe13e4a54a4a5646aa00aa53d0b113b4af47d157b7259af629100c521c09aff2dbf8d9f73de0078f868f094977c069f53d27acce87
data/README.md CHANGED
@@ -61,6 +61,7 @@ Currently the following chaining methods are supported:
61
61
  - in\_authority
62
62
  - refuse\_request
63
63
  - config
64
+ - in\_zone\_file
64
65
 
65
66
  Here's some usage examples:
66
67
 
@@ -77,9 +78,13 @@ Here's some usage examples:
77
78
  expect('example.com').to have_dns.with_type('A').at_least(3)
78
79
  end
79
80
 
80
- it 'check with configuration' do
81
+ it 'checks with configuration' do
81
82
  expect('example.com').to have_dns.with_type('A').config(nameserver: '192.0.2.4')
82
83
  end
84
+
85
+ it 'checks zone file("example.zone") with specified origin("example.com.")' do
86
+ expect('example.com').to have_dns.with_type('A').in_zone_file('example.zone', 'example.com.')
87
+ end
83
88
  ```
84
89
 
85
90
  The other method chains are actually [Dnsruby](http://dnsruby.rubyforge.org/classes/Dnsruby/RR.html) attributes on the record. You can prefix them with `and_`, `with_`, `and_with` or whatever your heart desires. The predicate is what is checked. The rest is syntactic sugar.
@@ -17,7 +17,9 @@ RSpec::Matchers.define :have_dns do
17
17
  matched = _options.all? do |option, value|
18
18
  begin
19
19
  # To distinguish types because not all Resolv returns have type
20
- if value.is_a? String
20
+ if ipaddr = (IPAddr.new(value) rescue nil) # IPAddr(v4/v6)?
21
+ ipaddr.include?(record.send(option).to_s)
22
+ elsif value.is_a? String
21
23
  record.send(option).to_s == value
22
24
  elsif value.is_a? Regexp
23
25
  record.send(option).to_s =~ value
@@ -84,6 +86,11 @@ RSpec::Matchers.define :have_dns do
84
86
  @config = c
85
87
  end
86
88
 
89
+ chain :in_zone_file do |file = nil, origin = '.'|
90
+ @zone_file = file
91
+ @zone_origin = origin
92
+ end
93
+
87
94
  def method_missing(m, *args, &block)
88
95
  if m.to_s =~ /(and\_with|and|with)?\_(.*)$/
89
96
  _options[$2.to_sym] = args.first
@@ -126,6 +133,12 @@ RSpec::Matchers.define :have_dns do
126
133
  end
127
134
 
128
135
  def _records
136
+ if @zone_file
137
+ @_records = Dnsruby::Message.new
138
+ rrs = Dnsruby::ZoneReader.new(@zone_origin).process_file(@zone_file)
139
+ rrs.each { |rr| @_records.add_answer(rr) }
140
+ end
141
+
129
142
  @_records ||= begin
130
143
  config = _config || {}
131
144
  # Backwards compatible config option for rspec-dnsruby
data/rspec-dns.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  Gem::Specification.new do |s|
2
- s.version = '0.1.3'
2
+ s.version = '0.1.4'
3
3
  s.name = 'rspec-dns'
4
4
  s.authors = ['Seth Vargo', 'Alexey Lapitsky', 'Johannes Russek', 'Hiroshi OTA']
5
5
  s.email = 'alexey@spotify.com'
@@ -0,0 +1,14 @@
1
+ $TTL 86400
2
+
3
+ @ IN SOA ns.example.com. root.example.com. (
4
+ 2014122413 ; Serial
5
+ 3600 ; Refresh
6
+ 900 ; Retry
7
+ 604800 ; Expire
8
+ 900 ; Minimum
9
+ )
10
+ IN NS ns
11
+ IN MX 40 mail
12
+ IN A 192.0.2.4
13
+ www IN A 192.0.2.4
14
+ www IN AAAA 2001:DB8:6C::430
@@ -31,6 +31,16 @@ describe 'rspec-dns matchers' do
31
31
  .and_address('2001:DB8:6C::430')
32
32
  end
33
33
 
34
+ it 'can evalutate an A/AAAA record with IPAddr range' do
35
+ stub_records(['example.com 86400 A 192.0.2.4',
36
+ 'example.com 86400 AAAA 2001:DB8:6c::430'])
37
+
38
+ expect('example.com').to have_dns.with_type('A')
39
+ .and_address('192.0.2.0/24')
40
+ expect('example.com').to have_dns.with_type('AAAA')
41
+ .and_address('2001:DB8:6C::/64')
42
+ end
43
+
34
44
  it 'can evalutate a CNAME record' do
35
45
  stub_records(['www.example.com 300 IN CNAME example.com'])
36
46
 
@@ -106,6 +116,47 @@ describe 'rspec-dns matchers' do
106
116
  end
107
117
  end
108
118
 
119
+ context 'with zone file' do
120
+ it 'can evalutate records in zone file with origin' do
121
+ file = 'spec/rspec-dns/example.zone'
122
+ origin = 'example.com.'
123
+
124
+ expect('example.com').to have_dns.with_type('NS')
125
+ .and_domainname('ns.example.com')
126
+ .in_zone_file(file, origin)
127
+ expect('example.com').to have_dns.with_type('A')
128
+ .and_address('192.0.2.4')
129
+ .in_zone_file(file, origin)
130
+ expect('example.com').to have_dns.with_type('MX')
131
+ .and_preference(40).and_exchange('mail.example.com')
132
+ .in_zone_file(file, origin)
133
+ expect('www.example.com').to have_dns.with_type('A')
134
+ .and_address('192.0.2.4')
135
+ .in_zone_file(file, origin)
136
+ expect('www.example.com').to have_dns.with_type('AAAA')
137
+ .and_address('2001:DB8:6C::430')
138
+ .in_zone_file(file, origin)
139
+ end
140
+ it 'can evalutate records in zone file without origin' do
141
+ file = 'spec/rspec-dns/example.zone'
142
+
143
+ expect('.').to have_dns.with_type('NS')
144
+ .and_domainname('ns').in_zone_file(file)
145
+ expect('www').to have_dns.with_type('A')
146
+ .and_address('192.0.2.4').in_zone_file(file)
147
+ end
148
+ it 'can evalutate records with dns servers if file is nil' do
149
+ file = nil
150
+ stub_records(['example.com 86400 A 192.0.2.4'])
151
+ expect('example.com').to have_dns.with_type('A')
152
+ .and_address('192.0.2.4')
153
+ .in_zone_file(file)
154
+ expect('example.com').to have_dns.with_type('A')
155
+ .and_address('192.0.2.4')
156
+ .in_zone_file
157
+ end
158
+ end
159
+
109
160
  context 'with changable connection timeout' do
110
161
  it 'is_expected.to timeout within 3 seconds in default' do
111
162
  stub_records(['example.com 86400 A 192.168.100.100']) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
@@ -11,34 +11,34 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-10-19 00:00:00.000000000 Z
14
+ date: 2015-01-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - ! '>='
20
+ - - '>='
21
21
  - !ruby/object:Gem::Version
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ! '>='
27
+ - - '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - ! '>='
34
+ - - '>='
35
35
  - !ruby/object:Gem::Version
36
36
  version: '2.9'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ! '>='
41
+ - - '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: '2.9'
44
44
  - !ruby/object:Gem::Dependency
@@ -71,6 +71,7 @@ files:
71
71
  - lib/rspec-dns.rb
72
72
  - lib/rspec-dns/have_dns.rb
73
73
  - rspec-dns.gemspec
74
+ - spec/rspec-dns/example.zone
74
75
  - spec/rspec-dns/have_dns_spec.rb
75
76
  - spec/spec_helper.rb
76
77
  homepage: https://github.com/spotify/rspec-dns
@@ -83,22 +84,22 @@ require_paths:
83
84
  - lib
84
85
  required_ruby_version: !ruby/object:Gem::Requirement
85
86
  requirements:
86
- - - ! '>='
87
+ - - '>='
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  requirements:
91
- - - ! '>='
92
+ - - '>='
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  requirements: []
95
96
  rubyforge_project:
96
- rubygems_version: 2.0.14
97
+ rubygems_version: 2.0.3
97
98
  signing_key:
98
99
  specification_version: 4
99
100
  summary: rspec-dns provides an easy-to-use DSL for testing your DNS records are responding
100
101
  as they should.
101
102
  test_files:
103
+ - spec/rspec-dns/example.zone
102
104
  - spec/rspec-dns/have_dns_spec.rb
103
105
  - spec/spec_helper.rb
104
- has_rdoc: