coppertone 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/LICENSE +1 -1
  4. data/Rakefile +2 -2
  5. data/coppertone.gemspec +1 -0
  6. data/lib/coppertone/directive.rb +14 -7
  7. data/lib/coppertone/error.rb +24 -5
  8. data/lib/coppertone/ip_address_wrapper.rb +9 -6
  9. data/lib/coppertone/macro_context.rb +7 -13
  10. data/lib/coppertone/macro_string/macro_expand.rb +3 -2
  11. data/lib/coppertone/macro_string.rb +12 -5
  12. data/lib/coppertone/mechanism/a.rb +5 -1
  13. data/lib/coppertone/mechanism/all.rb +11 -4
  14. data/lib/coppertone/mechanism/cidr_parser.rb +1 -1
  15. data/lib/coppertone/mechanism/domain_spec_mechanism.rb +9 -0
  16. data/lib/coppertone/mechanism/domain_spec_optional.rb +1 -0
  17. data/lib/coppertone/mechanism/domain_spec_required.rb +1 -0
  18. data/lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb +1 -0
  19. data/lib/coppertone/mechanism/exists.rb +5 -1
  20. data/lib/coppertone/mechanism/include.rb +17 -5
  21. data/lib/coppertone/mechanism/ip4.rb +5 -1
  22. data/lib/coppertone/mechanism/ip6.rb +5 -1
  23. data/lib/coppertone/mechanism/ip_mechanism.rb +9 -1
  24. data/lib/coppertone/mechanism/mx.rb +5 -1
  25. data/lib/coppertone/mechanism/ptr.rb +5 -1
  26. data/lib/coppertone/mechanism.rb +25 -2
  27. data/lib/coppertone/modifier/base.rb +1 -0
  28. data/lib/coppertone/modifier/exp.rb +6 -2
  29. data/lib/coppertone/modifier/redirect.rb +5 -1
  30. data/lib/coppertone/modifier/unknown.rb +6 -1
  31. data/lib/coppertone/modifier.rb +11 -2
  32. data/lib/coppertone/null_macro_context.rb +23 -0
  33. data/lib/coppertone/qualifier.rb +8 -0
  34. data/lib/coppertone/record.rb +33 -41
  35. data/lib/coppertone/record_finder.rb +3 -1
  36. data/lib/coppertone/record_term_parser.rb +30 -0
  37. data/lib/coppertone/request.rb +3 -1
  38. data/lib/coppertone/request_context.rb +1 -2
  39. data/lib/coppertone/result.rb +6 -2
  40. data/lib/coppertone/utils/validated_domain_finder.rb +6 -4
  41. data/lib/coppertone/version.rb +1 -1
  42. data/lib/coppertone.rb +3 -1
  43. data/spec/directive_spec.rb +13 -0
  44. data/spec/ip_address_wrapper_spec.rb +3 -0
  45. data/spec/macro_string_spec.rb +20 -0
  46. data/spec/mechanism/a_spec.rb +22 -7
  47. data/spec/mechanism/all_spec.rb +8 -0
  48. data/spec/mechanism/exists_spec.rb +14 -6
  49. data/spec/mechanism/include_spec.rb +13 -1
  50. data/spec/mechanism/ip4_spec.rb +15 -5
  51. data/spec/mechanism/ip6_spec.rb +18 -11
  52. data/spec/mechanism/mx_spec.rb +56 -0
  53. data/spec/mechanism/ptr_spec.rb +7 -0
  54. data/spec/modifier/exp_spec.rb +10 -0
  55. data/spec/modifier/redirect_spec.rb +10 -0
  56. data/spec/open_spf/ALL_mechanism_syntax_spec.rb +6 -6
  57. data/spec/open_spf/A_mechanism_syntax_spec.rb +30 -30
  58. data/spec/open_spf/EXISTS_mechanism_syntax_spec.rb +8 -8
  59. data/spec/open_spf/IP4_mechanism_syntax_spec.rb +10 -10
  60. data/spec/open_spf/IP6_mechanism_syntax_spec.rb +10 -10
  61. data/spec/open_spf/Include_mechanism_semantics_and_syntax_spec.rb +10 -10
  62. data/spec/open_spf/Initial_processing_spec.rb +21 -14
  63. data/spec/open_spf/MX_mechanism_syntax_spec.rb +22 -22
  64. data/spec/open_spf/Macro_expansion_rules_spec.rb +26 -30
  65. data/spec/open_spf/PTR_mechanism_syntax_spec.rb +7 -7
  66. data/spec/open_spf/Processing_limits_spec.rb +12 -12
  67. data/spec/open_spf/Record_evaluation_spec.rb +13 -13
  68. data/spec/open_spf/Record_lookup_spec.rb +8 -8
  69. data/spec/open_spf/Selecting_records_spec.rb +11 -11
  70. data/spec/open_spf/Semantics_of_exp_and_other_modifiers_spec.rb +27 -25
  71. data/spec/open_spf/Test_cases_from_implementation_bugs_spec.rb +2 -2
  72. data/spec/record_spec.rb +34 -13
  73. data/spec/request_context_spec.rb +1 -1
  74. data/spec/rfc7208-tests.yml +10 -0
  75. metadata +59 -48
  76. data/lib/coppertone/dns/error.rb +0 -9
  77. data/lib/coppertone/dns/mock_client.rb +0 -106
  78. data/lib/coppertone/dns/resolv_client.rb +0 -110
  79. data/lib/coppertone/dns.rb +0 -3
  80. data/lib/resolv/dns/resource/in/spf.rb +0 -15
  81. data/spec/dns/resolv_client_spec.rb +0 -307
@@ -1,307 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Coppertone::DNS::ResolvClient do
4
- subject { Coppertone::DNS::ResolvClient.new }
5
- let(:mock_resolver) { double(:resolver) }
6
-
7
- context '#fetch_a_records' do
8
- let(:first_a_addr) { Resolv::IPv4.new([127, 0, 0, 1].pack('CCCC')) }
9
- let(:first_a_record) { Resolv::DNS::Resource::IN::A.new(first_a_addr) }
10
- let(:second_a_addr) { Resolv::IPv4.new([192, 168, 8, 14].pack('CCCC')) }
11
- let(:second_a_record) { Resolv::DNS::Resource::IN::A.new(second_a_addr) }
12
- let(:record_list) { [first_a_record, second_a_record] }
13
- let(:domain) { 'example.com' }
14
- let(:domain_with_trailing) { "#{domain}." }
15
-
16
- it 'should map the Resolv classes to a set of hashes' do
17
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
18
- expect(mock_resolver).to receive(:getresources)
19
- .with(domain, Resolv::DNS::Resource::IN::A).and_return(record_list)
20
- results = subject.fetch_a_records(domain)
21
- expect(results.size).to eq(record_list.length)
22
- expect(results.map { |x| x[:type] })
23
- .to eq(record_list.length.times.map { 'A' })
24
- expect(results.map { |x| x[:address] })
25
- .to eq(record_list.map(&:address).map(&:to_s))
26
- end
27
-
28
- it 'should map when the domain has a trailing dot' do
29
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
30
- expect(mock_resolver).to receive(:getresources)
31
- .with(domain, Resolv::DNS::Resource::IN::A).and_return(record_list)
32
- results = subject.fetch_a_records(domain_with_trailing)
33
- expect(results.size).to eq(record_list.length)
34
- expect(results.map { |x| x[:type] })
35
- .to eq(record_list.length.times.map { 'A' })
36
- expect(results.map { |x| x[:address] })
37
- .to eq(record_list.map(&:address).map(&:to_s))
38
- end
39
-
40
- it 'should map the Resolv errors to Coppertone errors' do
41
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
42
- expect(mock_resolver).to receive(:getresources)
43
- .with(domain, Resolv::DNS::Resource::IN::A)
44
- .and_raise(Resolv::ResolvError)
45
- expect do
46
- subject.fetch_a_records(domain_with_trailing)
47
- end.to raise_error(Coppertone::DNS::Error)
48
- end
49
-
50
- it 'should map the Resolv timeout errors to Coppertone errors' do
51
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
52
- expect(mock_resolver).to receive(:getresources)
53
- .with(domain, Resolv::DNS::Resource::IN::A)
54
- .and_raise(Resolv::ResolvTimeout)
55
- expect do
56
- subject.fetch_a_records(domain_with_trailing)
57
- end.to raise_error(Coppertone::DNS::TimeoutError)
58
- end
59
- end
60
-
61
- context '#fetch_aaaa_records' do
62
- let(:first_aaaa_addr) do
63
- Resolv::IPv6.create('FE80:10:1:1:202:B3FF:FE1E:8329')
64
- end
65
- let(:first_aaaa_record) do
66
- Resolv::DNS::Resource::IN::AAAA.new(first_aaaa_addr)
67
- end
68
- let(:second_aaaa_addr) do
69
- Resolv::IPv6.create('AB61:10:111:891:4202:B3FF:FE1E:7329')
70
- end
71
- let(:second_aaaa_record) do
72
- Resolv::DNS::Resource::IN::AAAA.new(second_aaaa_addr)
73
- end
74
- let(:record_list) { [first_aaaa_record, second_aaaa_record] }
75
- let(:domain) { 'example.com' }
76
- let(:domain_with_trailing) { "#{domain}." }
77
-
78
- it 'should map the Resolv classes to a set of hashes' do
79
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
80
- expect(mock_resolver).to receive(:getresources)
81
- .with(domain, Resolv::DNS::Resource::IN::AAAA).and_return(record_list)
82
- results = subject.fetch_aaaa_records(domain)
83
- expect(results.size).to eq(record_list.length)
84
- expect(results.map { |x| x[:type] })
85
- .to eq(record_list.length.times.map { 'AAAA' })
86
- expect(results.map { |x| x[:address] })
87
- .to eq(record_list.map(&:address).map(&:to_s))
88
- end
89
-
90
- it 'should map when the domain has a trailing dot' do
91
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
92
- expect(mock_resolver).to receive(:getresources)
93
- .with(domain, Resolv::DNS::Resource::IN::AAAA).and_return(record_list)
94
- results = subject.fetch_aaaa_records(domain_with_trailing)
95
- expect(results.size).to eq(record_list.length)
96
- expect(results.map { |x| x[:type] })
97
- .to eq(record_list.length.times.map { 'AAAA' })
98
- expect(results.map { |x| x[:address] })
99
- .to eq(record_list.map(&:address).map(&:to_s))
100
- end
101
-
102
- it 'should map the Resolv errors to Coppertone errors' do
103
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
104
- expect(mock_resolver).to receive(:getresources)
105
- .with(domain, Resolv::DNS::Resource::IN::AAAA)
106
- .and_raise(Resolv::ResolvError)
107
- expect { subject.fetch_aaaa_records(domain_with_trailing) }
108
- .to raise_error(Coppertone::DNS::Error)
109
- end
110
-
111
- it 'should map the Resolv timeout errors to Coppertone errors' do
112
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
113
- expect(mock_resolver).to receive(:getresources)
114
- .with(domain, Resolv::DNS::Resource::IN::AAAA)
115
- .and_raise(Resolv::ResolvTimeout)
116
- expect { subject.fetch_aaaa_records(domain_with_trailing) }
117
- .to raise_error(Coppertone::DNS::TimeoutError)
118
- end
119
- end
120
-
121
- context '#fetch_mx_records' do
122
- let(:first_mx_name) do
123
- Resolv::DNS::Name.create('alt1.aspmx.l.google.com.')
124
- end
125
- let(:first_mx_record) do
126
- Resolv::DNS::Resource::IN::MX.new(20, first_mx_name)
127
- end
128
- let(:second_mx_name) do
129
- Resolv::DNS::Name.create('aspmx.l.google.com')
130
- end
131
- let(:second_mx_record) do
132
- Resolv::DNS::Resource::IN::MX.new(10, second_mx_name)
133
- end
134
- let(:record_list) { [first_mx_record, second_mx_record] }
135
- let(:domain) { 'example.com' }
136
- let(:domain_with_trailing) { "#{domain}." }
137
-
138
- it 'should map the Resolv classes to a set of hashes' do
139
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
140
- expect(mock_resolver).to receive(:getresources)
141
- .with(domain, Resolv::DNS::Resource::IN::MX).and_return(record_list)
142
- results = subject.fetch_mx_records(domain)
143
- expect(results.size).to eq(record_list.length)
144
- expect(results.map { |x| x[:type] })
145
- .to eq(record_list.length.times.map { 'MX' })
146
- expect(results.map { |x| x[:exchange] })
147
- .to eq(record_list.map(&:exchange).map(&:to_s))
148
- end
149
-
150
- it 'should map when the domain has a trailing dot' do
151
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
152
- expect(mock_resolver).to receive(:getresources)
153
- .with(domain, Resolv::DNS::Resource::IN::MX).and_return(record_list)
154
- results = subject.fetch_mx_records(domain_with_trailing)
155
- expect(results.size).to eq(record_list.length)
156
- expect(results.map { |x| x[:type] })
157
- .to eq(record_list.length.times.map { 'MX' })
158
- expect(results.map { |x| x[:exchange] })
159
- .to eq(record_list.map(&:exchange).map(&:to_s))
160
- end
161
-
162
- it 'should map the Resolv errors to Coppertone errors' do
163
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
164
- expect(mock_resolver).to receive(:getresources)
165
- .with(domain, Resolv::DNS::Resource::IN::MX).and_raise(Resolv::ResolvError)
166
- expect { subject.fetch_mx_records(domain_with_trailing) }
167
- .to raise_error(Coppertone::DNS::Error)
168
- end
169
-
170
- it 'should map the Resolv timeout errors to Coppertone errors' do
171
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
172
- expect(mock_resolver).to receive(:getresources)
173
- .with(domain, Resolv::DNS::Resource::IN::MX)
174
- .and_raise(Resolv::ResolvTimeout)
175
- expect { subject.fetch_mx_records(domain_with_trailing) }
176
- .to raise_error(Coppertone::DNS::TimeoutError)
177
- end
178
- end
179
-
180
- context '#fetch_txt_records' do
181
- let(:first_txt_string) { SecureRandom.hex(10) }
182
- let(:first_txt_record) do
183
- Resolv::DNS::Resource::IN::TXT.new(first_txt_string)
184
- end
185
- let(:second_txt_string) { SecureRandom.hex(10) }
186
- let(:second_txt_string_array) do
187
- [SecureRandom.hex(10), SecureRandom.hex(10)]
188
- end
189
- let(:second_txt_record) do
190
- Resolv::DNS::Resource::IN::TXT.new(second_txt_string,
191
- second_txt_string_array)
192
- end
193
- let(:record_list) { [first_txt_record, second_txt_record] }
194
- let(:domain) { 'example.com' }
195
- let(:domain_with_trailing) { "#{domain}." }
196
-
197
- it 'should map the Resolv classes to a set of hashes' do
198
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
199
- expect(mock_resolver).to receive(:getresources)
200
- .with(domain, Resolv::DNS::Resource::IN::TXT)
201
- .and_return(record_list)
202
- results = subject.fetch_txt_records(domain)
203
- expect(results.size).to eq(record_list.length)
204
- expect(results.map { |x| x[:type] })
205
- .to eq(record_list.length.times.map { 'TXT' })
206
- expect(results.map { |x| x[:text] }).to eq(
207
- [first_txt_string,
208
- ([second_txt_string] + second_txt_string_array).join('')])
209
- end
210
-
211
- it 'should map when the domain has a trailing dot' do
212
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
213
- expect(mock_resolver).to receive(:getresources)
214
- .with(domain, Resolv::DNS::Resource::IN::TXT)
215
- .and_return(record_list)
216
- results = subject.fetch_txt_records(domain_with_trailing)
217
- expect(results.size).to eq(record_list.length)
218
- expect(results.map { |x| x[:type] })
219
- .to eq(record_list.length.times.map { 'TXT' })
220
- expect(results.map { |x| x[:text] }).to eq(
221
- [first_txt_string,
222
- ([second_txt_string] + second_txt_string_array).join('')])
223
- end
224
-
225
- it 'should map the Resolv errors to Coppertone errors' do
226
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
227
- expect(mock_resolver).to receive(:getresources)
228
- .with(domain, Resolv::DNS::Resource::IN::TXT)
229
- .and_raise(Resolv::ResolvError)
230
- expect { subject.fetch_txt_records(domain_with_trailing) }
231
- .to raise_error(Coppertone::DNS::Error)
232
- end
233
-
234
- it 'should map the Resolv timeout errors to Coppertone errors' do
235
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
236
- expect(mock_resolver).to receive(:getresources)
237
- .with(domain, Resolv::DNS::Resource::IN::TXT)
238
- .and_raise(Resolv::ResolvTimeout)
239
- expect { subject.fetch_txt_records(domain_with_trailing) }
240
- .to raise_error(Coppertone::DNS::TimeoutError)
241
- end
242
- end
243
-
244
- context '#fetch_spf_records' do
245
- let(:first_spf_string) { SecureRandom.hex(10) }
246
- let(:first_spf_record) do
247
- Resolv::DNS::Resource::IN::TXT.new(first_spf_string)
248
- end
249
- let(:second_spf_string) { SecureRandom.hex(10) }
250
- let(:second_spf_string_array) do
251
- [SecureRandom.hex(10), SecureRandom.hex(10)]
252
- end
253
- let(:second_spf_record) do
254
- Resolv::DNS::Resource::IN::SPF.new(second_spf_string,
255
- second_spf_string_array)
256
- end
257
- let(:record_list) { [first_spf_record, second_spf_record] }
258
- let(:domain) { 'example.com' }
259
- let(:domain_with_trailing) { "#{domain}." }
260
-
261
- it 'should map the Resolv classes to a set of hashes' do
262
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
263
- expect(mock_resolver).to receive(:getresources)
264
- .with(domain, Resolv::DNS::Resource::IN::SPF)
265
- .and_return(record_list)
266
- results = subject.fetch_spf_records(domain)
267
- expect(results.size).to eq(record_list.length)
268
- expect(results.map { |x| x[:type] })
269
- .to eq(record_list.length.times.map { 'SPF' })
270
- expect(results.map { |x| x[:text] }).to eq(
271
- [first_spf_string,
272
- ([second_spf_string] + second_spf_string_array).join('')])
273
- end
274
-
275
- it 'should map when the domain has a trailing dot' do
276
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
277
- expect(mock_resolver).to receive(:getresources)
278
- .with(domain, Resolv::DNS::Resource::IN::SPF)
279
- .and_return(record_list)
280
- results = subject.fetch_spf_records(domain_with_trailing)
281
- expect(results.size).to eq(record_list.length)
282
- expect(results.map { |x| x[:type] })
283
- .to eq(record_list.length.times.map { 'SPF' })
284
- expect(results.map { |x| x[:text] }).to eq(
285
- [first_spf_string,
286
- ([second_spf_string] + second_spf_string_array).join('')])
287
- end
288
-
289
- it 'should map the Resolv errors to Coppertone errors' do
290
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
291
- expect(mock_resolver).to receive(:getresources)
292
- .with(domain, Resolv::DNS::Resource::IN::SPF)
293
- .and_raise(Resolv::ResolvError)
294
- expect { subject.fetch_spf_records(domain_with_trailing) }
295
- .to raise_error(Coppertone::DNS::Error)
296
- end
297
-
298
- it 'should map the Resolv timeout errors to Coppertone errors' do
299
- expect(Resolv::DNS).to receive(:new).and_return(mock_resolver)
300
- expect(mock_resolver).to receive(:getresources)
301
- .with(domain, Resolv::DNS::Resource::IN::SPF)
302
- .and_raise(Resolv::ResolvTimeout)
303
- expect { subject.fetch_spf_records(domain_with_trailing) }
304
- .to raise_error(Coppertone::DNS::TimeoutError)
305
- end
306
- end
307
- end