dmarc_inspector 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 680a45fb6295300f496488217bbd4b77462b9750
4
+ data.tar.gz: f56f1396f91cee448a9a1acd837410d4dc4ba4a3
5
+ SHA512:
6
+ metadata.gz: cdb18b991d57c24590121d75f6f40ea3f6f5076e400a33608ebbe8f02ea2c036693aa14dd33e99d1e5b63e55f95f6bcbf0dd1db6b1d4dec0045589ec798f2be5
7
+ data.tar.gz: df4fd1a41a9efbfc31572aca53f22b8c85892e8aa3976db18c7a42050b2c0d897ce5ef8c3e385eb82e18eef64890c9ec2915b2d77872589eca87bf3538142258
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .rspec
@@ -0,0 +1,4 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
4
+ --require pry
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'parslet'
4
+
5
+ # Specify your gem's dependencies in dmarc_inspector.gemspec
6
+ gemspec
7
+
8
+ gem 'rspec-core'
9
+ gem 'rspec-expectations'
10
+ gem 'rspec-mocks'
11
+ gem 'pry'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Nisanth Chunduru
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # dmarc_inspector
2
+
3
+ Looks up DMARC policy of a domain
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dmarc_inspector'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dmarc_inspector
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/dmarc_inspector/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dmarc_inspector/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dmarc_inspector"
8
+ spec.version = DMARCInspector::VERSION
9
+ spec.authors = ["Nisanth Chunduru"]
10
+ spec.email = ["nisanth074@gmail.com"]
11
+ spec.summary = "Looks up DMARC policy of a domain"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency 'parslet', '~> 1.6'
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency 'rspec-core', '~> 3.0'
23
+ spec.add_development_dependency 'rspec-expectations', '~> 3.0'
24
+ spec.add_development_dependency 'rspec-mocks', '~> 3.0'
25
+ spec.add_development_dependency 'pry', '~> 0.10'
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'resolv'
2
+ require 'dmarc_inspector/dmarc/record'
3
+
4
+ class DMARCInspector
5
+ def initialize(domain)
6
+ @domain = domain
7
+ end
8
+
9
+ def receiver_policy
10
+ dmarc_subdomain = "_dmarc.#{@domain}"
11
+ dns = Resolv::DNS.new
12
+ dns_resource_data = dns.getresource(dmarc_subdomain, Resolv::DNS::Resource::IN::TXT).data
13
+
14
+ record = DMARC::Record.parse(dns_resource_data)
15
+ record[:p]
16
+ rescue
17
+ :none
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ class DMARCInspector
2
+ module DMARC
3
+ class Error < StandardError; end
4
+ class InvalidRecord < Error; end
5
+ end
6
+ end
@@ -0,0 +1,49 @@
1
+ require 'parslet'
2
+
3
+ class DMARCInspector
4
+ module DMARC
5
+ # Borrowed from 'dmarc' gem
6
+ class Parser < Parslet::Parser
7
+ def self.parse(raw)
8
+ new.parse(raw)
9
+ end
10
+
11
+ def tag_value_pair(tag_definition, value_definition)
12
+ tag_definition >>
13
+ wsp? >> str('=') >> wsp? >>
14
+ value_definition
15
+ end
16
+
17
+ root(:dmarc_record)
18
+ rule(:dmarc_record) do
19
+ dmarc_version >>
20
+ dmarc_sep >> dmarc_request >>
21
+ # Not bothering about other tags, just need policy tag for now
22
+ any.repeat
23
+ end
24
+
25
+ rule(:dmarc_version) do
26
+ tag_value_pair(
27
+ str('v'),
28
+ str('DMARC1').as(:v)
29
+ )
30
+ end
31
+
32
+ rule(:dmarc_sep) { wsp? >> str(';') >> wsp? }
33
+
34
+ rule(:dmarc_request) do
35
+ tag_value_pair(
36
+ str('p'),
37
+ (
38
+ str('none') |
39
+ str('quarantine') |
40
+ str('reject')
41
+ ).as(:p)
42
+ )
43
+ end
44
+
45
+ rule(:wsp) { str(' ') | str("\t") }
46
+ rule(:wsp?) { wsp.repeat }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,19 @@
1
+ require 'dmarc_inspector/dmarc/parser'
2
+ require 'dmarc_inspector/dmarc/errors'
3
+
4
+ class DMARCInspector
5
+ module DMARC
6
+ class Record
7
+ def self.parse(raw)
8
+ begin
9
+ tree = Parser.parse(raw)
10
+ rescue Parslet::ParseFailed
11
+ raise InvalidRecord
12
+ end
13
+
14
+ tree[:p] = tree[:p].to_sym
15
+ tree
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ class DMARCInspector
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,55 @@
1
+ require 'dmarc_inspector/dmarc/parser'
2
+
3
+ describe DMARCInspector::DMARC::Parser do
4
+ describe '#dmarc_record' do
5
+ subject { described_class.new.dmarc_record }
6
+
7
+ it 'parses version' do
8
+ record = 'v=DMARC1; p=reject; sp=none; pct=100; rua=mailto:dmarc-yahoo-rua@yahoo-inc.com, mailto:dmarc_y_rua@yahoo.com;'
9
+ expect(subject.parse record).to include(v: 'DMARC1')
10
+ end
11
+
12
+ it 'parses policy' do
13
+ record = 'v=DMARC1; p=none; rua=mailto:mailauth-reports@google.com'
14
+ expect(subject.parse record).to include(p: 'none')
15
+ end
16
+
17
+ it 'ignores spacing' do
18
+ record1 = 'v=DMARC1; p=reject; sp=none; pct=100; rua=mailto:dmarc-yahoo-rua@yahoo-inc.com, mailto:dmarc_y_rua@yahoo.com;'
19
+ record2 = 'v=DMARC1;p=reject;sp=none;pct=100;rua=mailto:dmarc-yahoo-rua@yahoo-inc.com, mailto:dmarc_y_rua@yahoo.com;'
20
+ expect(subject.parse record1).to include(subject.parse record2)
21
+ end
22
+
23
+ it 'ignores trailing separator' do
24
+ record1 = 'v=DMARC1; p=none;'
25
+ record2 = 'v=DMARC1; p=none'
26
+ expect(subject.parse record1).to eq(v: 'DMARC1', p: 'none')
27
+ expect(subject.parse record1).to include(subject.parse record2)
28
+ end
29
+
30
+ it 'ignores remaining tags' do
31
+ record = 'v=DMARC1; p=reject; sp=none; pct=100; rua=mailto:dmarc-yahoo-rua@yahoo-inc.com, mailto:dmarc_y_rua@yahoo.com;'
32
+ expect(subject.parse record).to eq(v: 'DMARC1', p: 'reject')
33
+ end
34
+ end
35
+
36
+ describe '#dmarc_request' do
37
+ subject { described_class.new.dmarc_request }
38
+
39
+ it "parses policy 'none'" do
40
+ expect(subject.parse 'p=none').to eq(p: 'none')
41
+ end
42
+
43
+ it "parses policy 'reject'" do
44
+ expect(subject.parse 'p=reject').to eq(p: 'reject')
45
+ end
46
+
47
+ it "parses policy 'quarantine'" do
48
+ expect(subject.parse 'p=quarantine').to eq(p: 'quarantine')
49
+ end
50
+
51
+ it 'ignores spacing' do
52
+ expect(subject.parse 'p = reject').to eq(p: 'reject')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,34 @@
1
+ require 'dmarc_inspector/dmarc/record'
2
+
3
+ describe DMARCInspector::DMARC::Record do
4
+ describe '.parse' do
5
+ it 'parses a dmarc record' do
6
+ data = 'v=DMARC1; p=reject; sp=none; pct=100; rua=mailto:dmarc-yahoo-rua@yahoo-inc.com, mailto:dmarc_y_rua@yahoo.com;'
7
+ record = DMARCInspector::DMARC::Record.parse(data)
8
+ expect(record[:p]).to eq(:reject)
9
+ end
10
+
11
+ context "receiver policy is 'none'" do
12
+ it 'returns :none' do
13
+ data = 'v=DMARC1; p=none; rua=mailto:mailauth-reports@google.com'
14
+ record = DMARCInspector::DMARC::Record.parse(data)
15
+ expect(record[:p]).to eq(:none)
16
+ end
17
+ end
18
+
19
+ context "receiver policy is 'quarantine'" do
20
+ it 'returns :none' do
21
+ data = 'v=DMARC1; p=quarantine; rua=mailto:mailauth-reports@google.com'
22
+ record = DMARCInspector::DMARC::Record.parse(data)
23
+ expect(record[:p]).to eq(:quarantine)
24
+ end
25
+ end
26
+
27
+ context 'invalid record' do
28
+ it 'throws an error' do
29
+ data = 'v=spf1 redirect=_spf.mail.yahoo.com'
30
+ expect { DMARCInspector::DMARC::Record.parse(data) }.to raise_error(DMARCInspector::DMARC::InvalidRecord)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ describe DMARCInspector do
2
+ describe '#receiver_policy' do
3
+ it 'returns receiver policy of a domain' do
4
+ # TODO: Mock DNS query
5
+ # "v=DMARC1\; p=none\; rua=mailto:mailauth-reports@google.com"
6
+ dmarc_inspector = DMARCInspector.new('gmail.com')
7
+ expect(dmarc_inspector.receiver_policy).to eq(:none)
8
+ end
9
+
10
+ context "receiver policy is 'reject'" do
11
+ it 'returns :reject' do
12
+ # TODO: Mock DNS query
13
+ # "v=DMARC1\; p=reject\; sp=none\; pct=100\; rua=mailto:dmarc-yahoo-rua@yahoo-inc.com, mailto:dmarc_y_rua@yahoo.com\;"
14
+ dmarc_inspector = DMARCInspector.new('yahoo.com')
15
+ expect(dmarc_inspector.receiver_policy).to eq(:reject)
16
+ end
17
+ end
18
+
19
+ context "dns information isn't available" do
20
+ it 'returns :none' do
21
+ # TODO: Mock DNS query
22
+ dmarc_inspector = DMARCInspector.new('supportbee.com')
23
+ expect(dmarc_inspector.receiver_policy).to eq(:none)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,60 @@
1
+ require 'dmarc_inspector'
2
+
3
+ RSpec.configure do |config|
4
+ # These two settings work together to allow you to limit a spec run
5
+ # to individual examples or groups you care about by tagging them with
6
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
7
+ # get run.
8
+ config.filter_run :focus
9
+ config.run_all_when_everything_filtered = true
10
+
11
+ # Many RSpec users commonly either run the entire suite or an individual
12
+ # file, and it's useful to allow more verbose output when running an
13
+ # individual spec file.
14
+ if config.files_to_run.one?
15
+ # Use the documentation formatter for detailed output,
16
+ # unless a formatter has already been configured
17
+ # (e.g. via a command-line flag).
18
+ config.default_formatter = 'doc'
19
+ end
20
+
21
+ # Print the 10 slowest examples and example groups at the
22
+ # end of the spec run, to help surface which specs are running
23
+ # particularly slow.
24
+ config.profile_examples = 10
25
+
26
+ # Run specs in random order to surface order dependencies. If you find an
27
+ # order dependency and want to debug it, you can fix the order by providing
28
+ # the seed, which is printed after each run.
29
+ # --seed 1234
30
+ config.order = :random
31
+
32
+ # Seed global randomization in this process using the `--seed` CLI option.
33
+ # Setting this allows you to use `--seed` to deterministically reproduce
34
+ # test failures related to randomization by passing the same `--seed` value
35
+ # as the one that triggered the failure.
36
+ Kernel.srand config.seed
37
+
38
+ # rspec-expectations config goes here. You can use an alternate
39
+ # assertion/expectation library such as wrong or the stdlib/minitest
40
+ # assertions if you prefer.
41
+ config.expect_with :rspec do |expectations|
42
+ # Enable only the newer, non-monkey-patching expect syntax.
43
+ # For more details, see:
44
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
45
+ expectations.syntax = :expect
46
+ end
47
+
48
+ # rspec-mocks config goes here. You can use an alternate test double
49
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
50
+ config.mock_with :rspec do |mocks|
51
+ # Enable only the newer, non-monkey-patching expect syntax.
52
+ # For more details, see:
53
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
54
+ mocks.syntax = :expect
55
+
56
+ # Prevents you from mocking or stubbing a method that does not exist on
57
+ # a real object. This is generally recommended.
58
+ mocks.verify_partial_doubles = true
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmarc_inspector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Nisanth Chunduru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parslet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-core
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-expectations
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-mocks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ description:
112
+ email:
113
+ - nisanth074@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec.example"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - dmarc_inspector.gemspec
125
+ - lib/dmarc_inspector.rb
126
+ - lib/dmarc_inspector/dmarc/errors.rb
127
+ - lib/dmarc_inspector/dmarc/parser.rb
128
+ - lib/dmarc_inspector/dmarc/record.rb
129
+ - lib/dmarc_inspector/version.rb
130
+ - spec/dmarc_inspector/dmarc/parser_spec.rb
131
+ - spec/dmarc_inspector/dmarc/record_spec.rb
132
+ - spec/dmarc_inspector_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage:
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Looks up DMARC policy of a domain
158
+ test_files:
159
+ - spec/dmarc_inspector/dmarc/parser_spec.rb
160
+ - spec/dmarc_inspector/dmarc/record_spec.rb
161
+ - spec/dmarc_inspector_spec.rb
162
+ - spec/spec_helper.rb
163
+ has_rdoc: