dmarc 0.3.0 → 0.4.0

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: 9a12630bf22487064d3d35386f55e7af00f6b542
4
- data.tar.gz: 35f68803f6820445c7e38d9e37078737075807e4
3
+ metadata.gz: 97e07c7f904e46b02faa4ce8358e3420b4ae4869
4
+ data.tar.gz: 41f067c094fcf208cf93d7f06c2c3fdd139d2c18
5
5
  SHA512:
6
- metadata.gz: 3214787e24b80ce2eb162473d43e9e77f152d8e1ff6cfcf1fbbb2fadfe8d565b27c4e0b97c3c17180783e10ff6c62a18714c8be3925a97309a886f79a7d2eee4
7
- data.tar.gz: f7ed4b603e8541e97c7d29d733f45d5b7f93ee1d737f9cc70916c1459098a570a01e1cdece1b2b182dd683c8b2322d279ed4db2c3fbe5187ec8be9eb2389d7fe
6
+ metadata.gz: 3083a287ebfbf9aa267721fb7383f17404ce392c3481aa76e4873ac135bf2cad67a7148bfc787100447b6351b6e9459dc3a2d1c62f628b94543310831d42aabd
7
+ data.tar.gz: ba197f0a39720736446c499cecb1b93e2f8b41826f3113a2014e4655503da3837a9c2501d42ea0218c963dd5337dd832f82a84fdc233855784f4542827f66072
data/.travis.yml CHANGED
@@ -1,9 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0
5
- - 2.1
6
- - 2.2
3
+ - 2.1.8
4
+ - 2.2.4
5
+ - 2.3.0
7
6
  - jruby
8
7
  - rbx-2
9
8
  matrix:
data/ChangeLog.md CHANGED
@@ -1,3 +1,17 @@
1
+ ### 0.4.0 / 2016-07-10
2
+
3
+ * Added {DMARC::Record#to_h}.
4
+ * Added {DMARC::Record#adkim?}.
5
+ * Added {DMARC::Record#aspf?}.
6
+ * Added {DMARC::Record#fo?}.
7
+ * Added {DMARC::Record#p?}.
8
+ * Added {DMARC::Record#pct?}.
9
+ * Added {DMARC::Record#rf?}.
10
+ * Added {DMARC::Record#ri?}.
11
+ * Added {DMARC::Record#rua?}.
12
+ * Added {DMARC::Record#ruf?}.
13
+ * Added {DMARC::Record#sp?}.
14
+
1
15
  ### 0.3.0 / 2015-07-01
2
16
 
3
17
  * Added {DMARC::Record.query}.
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014 Trail of Bits
3
+ Copyright (c) 2014-2016 Trail of Bits
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/lib/dmarc/record.rb CHANGED
@@ -61,67 +61,199 @@ module DMARC
61
61
  # @option attributes [:DMARC1] :v
62
62
  #
63
63
  def initialize(attributes={})
64
- @adkim, @aspf, @fo, @p, @pct, @rf, @ri, @rua, @ruf, @sp, @v = attributes.values_at(:adkim, :aspf, :fo, :p, :pct, :rf, :ri, :rua, :ruf, :sp, :v)
64
+ @v = attributes.fetch(:v)
65
+ @adkim = attributes[:adkim]
66
+ @aspf = attributes[:aspf]
67
+ @fo = attributes[:fo]
68
+ @p = attributes[:p]
69
+ @pct = attributes[:pct]
70
+ @rf = attributes[:rf]
71
+ @ri = attributes[:ri]
72
+ @rua = attributes[:rua]
73
+ @ruf = attributes[:ruf]
74
+ @sp = attributes[:sp]
65
75
  end
66
76
 
77
+ #
78
+ # Determines if the `sp=` field was specified?
79
+ #
80
+ # @return [Boolean]
81
+ #
82
+ # @since 0.4.0
83
+ #
84
+ def sp?
85
+ !@sp.nil?
86
+ end
87
+
88
+ #
89
+ # The `sp=` field.
90
+ #
91
+ # @return [:none, :quarantine, :reject]
92
+ # The value of the `sp=` field, or that of {#p} if the field was omitted.
93
+ #
67
94
  def sp
68
95
  @sp || @p
69
96
  end
70
97
 
98
+ #
99
+ # Determines whether the `adkim=` field was specified.
100
+ #
101
+ # @return [Boolean]
102
+ #
103
+ # @since 0.4.0
104
+ #
105
+ def adkim?
106
+ !@adkim.nil?
107
+ end
108
+
71
109
  #
72
110
  # `adkim=` field.
73
111
  #
74
112
  # @return [:r, :s]
113
+ # The value of the `adkim=` field, or `:r` if the field was omitted.
75
114
  #
76
115
  def adkim
77
116
  @adkim || :r
78
117
  end
79
118
 
119
+ #
120
+ # Determines whether the `aspf=` field was specified.
121
+ #
122
+ # @return [Boolean]
123
+ #
124
+ # @since 0.4.0
125
+ #
126
+ def aspf?
127
+ !@aspf.nil?
128
+ end
129
+
80
130
  #
81
131
  # `aspf` field.
82
132
  #
83
133
  # @return [:r, :s]
134
+ # The value of the `aspf=` field, or `:r` if the field was omitted.
84
135
  #
85
136
  def aspf
86
137
  @aspf || :r
87
138
  end
88
139
 
140
+ #
141
+ # Determines whether the `fo=` field was specified.
142
+ #
143
+ # @return [Boolean]
144
+ #
145
+ # @since 0.4.0
146
+ #
147
+ def fo?
148
+ !@fo.nil?
149
+ end
150
+
89
151
  #
90
152
  # `fo` field.
91
153
  #
92
154
  # @return [Array<'0', '1', 'd', 's'>]
155
+ # The value of the `fo=` field, or `["0"]` if the field was omitted.
93
156
  #
94
157
  def fo
95
158
  @fo || %w[0]
96
159
  end
97
160
 
161
+ #
162
+ # Determines if the `p=` field was specified?
163
+ #
164
+ # @return [Boolean]
165
+ #
166
+ # @since 0.4.0
167
+ #
168
+ def p?
169
+ !@p.nil?
170
+ end
171
+
172
+ #
173
+ # Determines whether the `pct=` field was specified.
174
+ #
175
+ # @return [Boolean]
176
+ #
177
+ # @since 0.4.0
178
+ #
179
+ def pct?
180
+ !@pct.nil?
181
+ end
182
+
98
183
  #
99
184
  # `pct` field.
100
185
  #
101
186
  # @return [Integer]
187
+ # The value of the `pct=` field, or `100` if the field was omitted.
102
188
  #
103
189
  def pct
104
190
  @pct || 100
105
191
  end
106
192
 
193
+ #
194
+ # Determines whether the `rf=` field was specified.
195
+ #
196
+ # @return [Boolean]
197
+ #
198
+ # @since 0.4.0
199
+ #
200
+ def rf?
201
+ !@rf.nil?
202
+ end
203
+
107
204
  #
108
205
  # `rf` field.
109
206
  #
110
207
  # @return [:afrf, :iodef]
208
+ # The value of the `rf=` field, or `:afrf` if the field was omitted.
111
209
  #
112
210
  def rf
113
211
  @rf || :afrf
114
212
  end
115
213
 
214
+ #
215
+ # Determines whether the `ri=` field was specified.
216
+ #
217
+ # @return [Boolean]
218
+ #
219
+ # @since 0.4.0
220
+ #
221
+ def ri?
222
+ !@ri.nil?
223
+ end
224
+
116
225
  #
117
226
  # `ri` field.
118
227
  #
119
228
  # @return [Integer]
229
+ # The value of the `ri=` field, or `86400` if the field was omitted.
120
230
  #
121
231
  def ri
122
232
  @ri || 86400
123
233
  end
124
234
 
235
+ #
236
+ # Determines if the `rua=` field was specified?
237
+ #
238
+ # @return [Boolean]
239
+ #
240
+ # @since 0.4.0
241
+ #
242
+ def rua?
243
+ !@rua.nil?
244
+ end
245
+
246
+ #
247
+ # Determines if the `ruf=` field was specified?
248
+ #
249
+ # @return [Boolean]
250
+ #
251
+ # @since 0.4.0
252
+ #
253
+ def ruf?
254
+ !@ruf.nil?
255
+ end
256
+
125
257
  #
126
258
  # Parses a DMARC record.
127
259
  #
@@ -177,6 +309,31 @@ module DMARC
177
309
  end
178
310
  end
179
311
 
312
+ #
313
+ # Converts the record to a Hash.
314
+ #
315
+ # @return [Hash{Symbol => Object}]
316
+ #
317
+ # @since 0.4.0
318
+ #
319
+ def to_h
320
+ hash = {}
321
+
322
+ hash[:v] = @v if @v
323
+ hash[:p] = @p if @p
324
+ hash[:sp] = @sp if @sp
325
+ hash[:rua] = @rua if @rua
326
+ hash[:ruf] = @ruf if @ruf
327
+ hash[:adkim] = @adkim if @adkim
328
+ hash[:aspf] = @aspf if @aspf
329
+ hash[:ri] = @ri if @ri
330
+ hash[:fo] = @fo if @fo
331
+ hash[:rf] = @rf if @rf
332
+ hash[:pct] = @pct if @pct
333
+
334
+ return hash
335
+ end
336
+
180
337
  #
181
338
  # Converts the record back to a DMARC String.
182
339
  #
@@ -185,17 +342,17 @@ module DMARC
185
342
  def to_s
186
343
  tags = []
187
344
 
188
- tags << "v=#{@v}" if @v
189
- tags << "p=#{@p}" if @p
190
- tags << "sp=#{@sp}" if @sp
345
+ tags << "v=#{@v}" if @v
346
+ tags << "p=#{@p}" if @p
347
+ tags << "sp=#{@sp}" if @sp
191
348
  tags << "rua=#{@rua.join(',')}" if @rua
192
349
  tags << "ruf=#{@ruf.join(',')}" if @ruf
193
- tags << "adkim=#{@adkim}" if @adkim
194
- tags << "aspf=#{@aspf}" if @aspf
195
- tags << "ri=#{@ri}" if @ri
196
- tags << "fo=#{@fo.join(':')}" if @fo
197
- tags << "rf=#{@rf}" if @rf
198
- tags << "pct=#{@pct}" if @pct
350
+ tags << "adkim=#{@adkim}" if @adkim
351
+ tags << "aspf=#{@aspf}" if @aspf
352
+ tags << "ri=#{@ri}" if @ri
353
+ tags << "fo=#{@fo.join(':')}" if @fo
354
+ tags << "rf=#{@rf}" if @rf
355
+ tags << "pct=#{@pct}" if @pct
199
356
 
200
357
  return tags.join('; ')
201
358
  end
data/lib/dmarc/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module DMARC
2
2
  # dmarc version
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
data/spec/dmarc_spec.rb CHANGED
@@ -11,7 +11,7 @@ describe DMARC do
11
11
  it "should query and parse the DMARC record" do
12
12
  record = subject.query(domain)
13
13
 
14
- expect(record).to be == 'v=DMARC1; p=quarantine; rua=mailto:mailauth-reports@google.com'
14
+ expect(record).to be == 'v=DMARC1; p=reject; rua=mailto:mailauth-reports@google.com'
15
15
  end
16
16
  end
17
17
 
data/spec/record_spec.rb CHANGED
@@ -25,6 +25,8 @@ describe Record do
25
25
  end
26
26
 
27
27
  context 'with default values' do
28
+ subject { described_class.new(v: :DMARC1) }
29
+
28
30
  describe "#adkim" do
29
31
  it "should return :r" do
30
32
  expect(subject.adkim).to be == :r
@@ -104,6 +106,72 @@ describe Record do
104
106
  end
105
107
  end
106
108
 
109
+ shared_examples "question mark method" do |field,value|
110
+ describe "#{field}?" do
111
+ context "when #{field} is set" do
112
+ subject do
113
+ described_class.new(v: :DMARC1, field => value)
114
+ end
115
+
116
+ it { expect(subject.send(:"#{field}?")).to be(true) }
117
+ end
118
+
119
+ context "when #{field} is omitted" do
120
+ subject { described_class.new(v: :DMARC1) }
121
+
122
+ it { expect(subject.send(:"#{field}?")).to be(false) }
123
+ end
124
+ end
125
+ end
126
+
127
+ include_examples "question mark method", :adkim, :r
128
+ include_examples "question mark method", :aspf, :r
129
+ include_examples "question mark method", :fo, %w[0 1 d]
130
+ include_examples "question mark method", :p, :reject
131
+ include_examples "question mark method", :pct, 100
132
+ include_examples "question mark method", :rf, :afrf
133
+ include_examples "question mark method", :ri, 86400
134
+ include_examples "question mark method", :rua, [URI("mailto:bob@example.com")]
135
+ include_examples "question mark method", :ruf, [URI("mailto:bob@example.com")]
136
+ include_examples "question mark method", :sp, :reject
137
+
138
+ describe "#sp?" do
139
+ context "when sp is set" do
140
+ end
141
+ end
142
+
143
+ describe "#to_h" do
144
+ let(:v) { :DMARC1 }
145
+ let(:p) { :reject }
146
+ let(:rua) { [URI.parse('mailto:d@rua.agari.com')] }
147
+ let(:ruf) { [URI.parse('mailto:d@rua.agari.com')] }
148
+ let(:fo) { %w[0 1 d] }
149
+
150
+ subject do
151
+ described_class.new(
152
+ v: v,
153
+ p: p,
154
+ rua: rua,
155
+ ruf: ruf,
156
+ fo: fo
157
+ )
158
+ end
159
+
160
+ it "should return a Hash" do
161
+ expect(subject.to_h).to be_kind_of(Hash)
162
+ end
163
+
164
+ it "should only include fields that have values" do
165
+ expect(subject.to_h).to be == {
166
+ v: v,
167
+ p: p,
168
+ rua: rua,
169
+ ruf: ruf,
170
+ fo: fo
171
+ }
172
+ end
173
+ end
174
+
107
175
  describe "#to_s" do
108
176
  let(:v) { :DMARC1 }
109
177
  let(:p) { :reject }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmarc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davis Gallinghouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-01 00:00:00.000000000 Z
11
+ date: 2016-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.4.7
91
+ rubygems_version: 2.4.5.1
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: DMARC Record Parser