dmarc 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,58 +2,72 @@ require 'spec_helper'
2
2
  require 'dmarc/record'
3
3
 
4
4
  describe Record do
5
- context 'by default' do
6
- it 'has a relaxed DKIM alignment' do
7
- expect(subject.adkim).to eq('r')
5
+ describe '#initialize' do
6
+ let(:attributes) do
7
+ {
8
+ v: :DMARC1,
9
+ p: :none,
10
+ adkim: :r
11
+ }
8
12
  end
9
13
 
10
- it 'has a relaxed SPF alignment' do
11
- expect(subject.aspf).to eq('r')
14
+ subject { described_class.new(attributes) }
15
+
16
+ it 'assigns the fields to its properties' do
17
+ expect(subject.v).to be :DMARC1
18
+ expect(subject.p).to be :none
19
+ expect(subject.adkim).to be :r
12
20
  end
13
21
 
14
- it 'has failure reporting options of "0"' do
15
- expect(subject.fo).to eq('0')
22
+ it 'gives "sp" the same value as "p" if undefined' do
23
+ expect(subject.sp).to be :none
16
24
  end
25
+ end
17
26
 
18
- it 'has an application percentage of 100' do
19
- expect(subject.pct).to eq(100)
27
+ context 'with default values' do
28
+ describe "#adkim" do
29
+ it "should return :r" do
30
+ expect(subject.adkim).to be == :r
31
+ end
20
32
  end
21
33
 
22
- it 'has an afrf report format' do
23
- expect(subject.rf).to eq('afrf')
34
+ describe "#aspf" do
35
+ it "should return :r" do
36
+ expect(subject.aspf).to be == :r
37
+ end
24
38
  end
25
39
 
26
- it 'has a report interval of 1 day' do
27
- expect(subject.ri).to eq(86400)
40
+ describe "#fo" do
41
+ it "should return ['0']" do
42
+ expect(subject.fo).to be == ['0']
43
+ end
28
44
  end
29
- end
30
45
 
31
- describe '#initialize' do
32
- let(:parse_tree) do
33
- {
34
- v: 'DMARC1',
35
- p: 'none',
36
- adkim: 'r'
37
- }
46
+ describe "#pct" do
47
+ it "should return 100" do
48
+ expect(subject.pct).to be == 100
49
+ end
38
50
  end
39
51
 
40
- it 'assigns the fields to its properties' do
41
- rec = described_class.new parse_tree
42
- expect(rec.v).to eq('DMARC1')
43
- expect(rec.p).to eq('none')
44
- expect(rec.adkim).to eq('r')
52
+ describe "#rf" do
53
+ it "should return afrf" do
54
+ expect(subject.rf).to be == :afrf
55
+ end
45
56
  end
46
57
 
47
- it 'gives "sp" the same value as "p" if undefined' do
48
- rec = described_class.new parse_tree
49
- expect(rec.sp).to eq('none')
58
+ describe "#ri" do
59
+ it "should return 86400" do
60
+ expect(subject.ri).to be == 86400
61
+ end
50
62
  end
51
63
  end
52
64
 
53
- describe '.from_txt' do
65
+ describe '.parse' do
66
+ subject { described_class }
67
+
54
68
  context 'with a valid record' do
55
69
  it 'parse and returns a record' do
56
- rec = described_class.from_txt('v=DMARC1; p=quarantine')
70
+ rec = subject.parse('v=DMARC1; p=quarantine')
57
71
 
58
72
  expect(rec).to be_a Record
59
73
  expect(rec.p).to eq :quarantine
@@ -62,11 +76,53 @@ describe Record do
62
76
 
63
77
  context 'with an invalid record' do
64
78
  it 'raises an InvalidRecord error' do
65
- expect { described_class.from_txt('v=DMARC1; foo=bar') }.to raise_error do |error|
66
- expect(error).to be_a InvalidRecord
67
- expect(error.ascii_tree).to_not be_nil
68
- end
79
+ expect {
80
+ subject.parse('v=XXXXXXXXXX')
81
+ }.to raise_error(InvalidRecord)
82
+ end
83
+ end
84
+ end
85
+
86
+ describe ".query" do
87
+ subject { described_class }
88
+
89
+ context "when given a domain" do
90
+ let(:domain) { 'google.com' }
91
+
92
+ it "should query and parse the DMARC record" do
93
+ record = subject.query(domain)
94
+
95
+ expect(record).to be_kind_of(Record)
96
+ expect(record.v).to be == :DMARC1
69
97
  end
70
98
  end
99
+
100
+ context "when given a bad domain" do
101
+ it "should raise a DNS error" do
102
+ expect(subject.query('foobar.com')).to be_nil
103
+ end
104
+ end
105
+ end
106
+
107
+ describe "#to_s" do
108
+ let(:v) { :DMARC1 }
109
+ let(:p) { :reject }
110
+ let(:rua) { [URI.parse('mailto:d@rua.agari.com')] }
111
+ let(:ruf) { [URI.parse('mailto:d@rua.agari.com')] }
112
+ let(:fo) { %w[0 1 d] }
113
+
114
+ subject do
115
+ described_class.new(
116
+ v: v,
117
+ p: p,
118
+ rua: rua,
119
+ ruf: ruf,
120
+ fo: fo
121
+ )
122
+ end
123
+
124
+ it "should convert the record to a String" do
125
+ expect(subject.to_s).to be == "v=#{v}; p=#{p}; rua=#{rua[0]}; ruf=#{ruf[0]}; fo=#{fo[0]}:#{fo[1]}:#{fo[2]}"
126
+ end
71
127
  end
72
128
  end
@@ -1,3 +1,6 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  require 'rspec'
2
5
  require 'dmarc'
3
6
 
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmarc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2014-10-21 00:00:00.000000000 Z
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  description: DMARC Record Parser
@@ -45,11 +45,11 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .document
49
- - .gitignore
50
- - .rspec
51
- - .travis.yml
52
- - .yardopts
48
+ - ".document"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - ".yardopts"
53
53
  - ChangeLog.md
54
54
  - Gemfile
55
55
  - LICENSE.txt
@@ -57,11 +57,13 @@ files:
57
57
  - Rakefile
58
58
  - dmarc.gemspec
59
59
  - lib/dmarc.rb
60
+ - lib/dmarc/dmarc.rb
60
61
  - lib/dmarc/exceptions.rb
61
62
  - lib/dmarc/parser.rb
62
63
  - lib/dmarc/record.rb
63
64
  - lib/dmarc/version.rb
64
65
  - spec/data/alexa.csv
66
+ - spec/dmarc_spec.rb
65
67
  - spec/parser_spec.rb
66
68
  - spec/record_spec.rb
67
69
  - spec/spec_helper.rb
@@ -76,22 +78,23 @@ require_paths:
76
78
  - lib
77
79
  required_ruby_version: !ruby/object:Gem::Requirement
78
80
  requirements:
79
- - - '>='
81
+ - - ">="
80
82
  - !ruby/object:Gem::Version
81
- version: '0'
83
+ version: 1.9.1
82
84
  required_rubygems_version: !ruby/object:Gem::Requirement
83
85
  requirements:
84
- - - '>='
86
+ - - ">="
85
87
  - !ruby/object:Gem::Version
86
88
  version: '0'
87
89
  requirements: []
88
90
  rubyforge_project:
89
- rubygems_version: 2.1.11
91
+ rubygems_version: 2.4.7
90
92
  signing_key:
91
93
  specification_version: 4
92
94
  summary: DMARC Record Parser
93
95
  test_files:
94
96
  - spec/data/alexa.csv
97
+ - spec/dmarc_spec.rb
95
98
  - spec/parser_spec.rb
96
99
  - spec/record_spec.rb
97
100
  - spec/spec_helper.rb