coppertone 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.travis.yml +7 -0
- data/Gemfile +7 -0
- data/LICENSE +201 -0
- data/README.md +58 -0
- data/Rakefile +140 -0
- data/coppertone.gemspec +27 -0
- data/lib/coppertone/class_builder.rb +20 -0
- data/lib/coppertone/directive.rb +38 -0
- data/lib/coppertone/dns/error.rb +9 -0
- data/lib/coppertone/dns/mock_client.rb +106 -0
- data/lib/coppertone/dns/resolv_client.rb +110 -0
- data/lib/coppertone/dns.rb +3 -0
- data/lib/coppertone/domain_spec.rb +45 -0
- data/lib/coppertone/error.rb +29 -0
- data/lib/coppertone/ip_address_wrapper.rb +75 -0
- data/lib/coppertone/macro_context.rb +67 -0
- data/lib/coppertone/macro_string/macro_expand.rb +84 -0
- data/lib/coppertone/macro_string/macro_literal.rb +24 -0
- data/lib/coppertone/macro_string/macro_parser.rb +62 -0
- data/lib/coppertone/macro_string/macro_static_expand.rb +52 -0
- data/lib/coppertone/macro_string.rb +31 -0
- data/lib/coppertone/mechanism/a.rb +16 -0
- data/lib/coppertone/mechanism/all.rb +24 -0
- data/lib/coppertone/mechanism/cidr_parser.rb +14 -0
- data/lib/coppertone/mechanism/domain_spec_mechanism.rb +18 -0
- data/lib/coppertone/mechanism/domain_spec_optional.rb +46 -0
- data/lib/coppertone/mechanism/domain_spec_required.rb +37 -0
- data/lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb +114 -0
- data/lib/coppertone/mechanism/exists.rb +14 -0
- data/lib/coppertone/mechanism/include.rb +18 -0
- data/lib/coppertone/mechanism/include_matcher.rb +34 -0
- data/lib/coppertone/mechanism/ip4.rb +13 -0
- data/lib/coppertone/mechanism/ip6.rb +13 -0
- data/lib/coppertone/mechanism/ip_mechanism.rb +48 -0
- data/lib/coppertone/mechanism/mx.rb +40 -0
- data/lib/coppertone/mechanism/ptr.rb +17 -0
- data/lib/coppertone/mechanism.rb +32 -0
- data/lib/coppertone/modifier/base.rb +24 -0
- data/lib/coppertone/modifier/exp.rb +34 -0
- data/lib/coppertone/modifier/redirect.rb +17 -0
- data/lib/coppertone/modifier/unknown.rb +16 -0
- data/lib/coppertone/modifier.rb +30 -0
- data/lib/coppertone/qualifier.rb +45 -0
- data/lib/coppertone/record.rb +86 -0
- data/lib/coppertone/record_evaluator.rb +63 -0
- data/lib/coppertone/record_finder.rb +34 -0
- data/lib/coppertone/request.rb +68 -0
- data/lib/coppertone/request_context.rb +67 -0
- data/lib/coppertone/request_count_limiter.rb +36 -0
- data/lib/coppertone/result.rb +50 -0
- data/lib/coppertone/sender_identity.rb +39 -0
- data/lib/coppertone/spf_service.rb +9 -0
- data/lib/coppertone/term.rb +13 -0
- data/lib/coppertone/utils/domain_utils.rb +59 -0
- data/lib/coppertone/utils/host_utils.rb +22 -0
- data/lib/coppertone/utils/ip_in_domain_checker.rb +53 -0
- data/lib/coppertone/utils/validated_domain_finder.rb +40 -0
- data/lib/coppertone/utils.rb +4 -0
- data/lib/coppertone/version.rb +3 -0
- data/lib/coppertone.rb +48 -0
- data/lib/resolv/dns/resource/in/spf.rb +15 -0
- data/spec/directive_spec.rb +41 -0
- data/spec/dns/resolv_client_spec.rb +307 -0
- data/spec/domain_spec_spec.rb +35 -0
- data/spec/ip_address_wrapper_spec.rb +67 -0
- data/spec/macro_context_spec.rb +69 -0
- data/spec/macro_string/macro_expand_spec.rb +79 -0
- data/spec/macro_string/macro_literal_spec.rb +27 -0
- data/spec/macro_string/macro_static_expand_spec.rb +67 -0
- data/spec/macro_string_spec.rb +20 -0
- data/spec/mechanism/a_spec.rb +198 -0
- data/spec/mechanism/all_spec.rb +22 -0
- data/spec/mechanism/exists_spec.rb +91 -0
- data/spec/mechanism/include_spec.rb +43 -0
- data/spec/mechanism/ip4_spec.rb +110 -0
- data/spec/mechanism/ip6_spec.rb +104 -0
- data/spec/mechanism/mx_spec.rb +51 -0
- data/spec/mechanism/ptr_spec.rb +43 -0
- data/spec/mechanism_spec.rb +4 -0
- data/spec/modifier_spec.rb +4 -0
- data/spec/open_spf/ALL_mechanism_syntax_spec.rb +38 -0
- data/spec/open_spf/A_mechanism_syntax_spec.rb +159 -0
- data/spec/open_spf/EXISTS_mechanism_syntax_spec.rb +46 -0
- data/spec/open_spf/IP4_mechanism_syntax_spec.rb +59 -0
- data/spec/open_spf/IP6_mechanism_syntax_spec.rb +60 -0
- data/spec/open_spf/Include_mechanism_semantics_and_syntax_spec.rb +56 -0
- data/spec/open_spf/Initial_processing_spec.rb +77 -0
- data/spec/open_spf/MX_mechanism_syntax_spec.rb +119 -0
- data/spec/open_spf/Macro_expansion_rules_spec.rb +154 -0
- data/spec/open_spf/PTR_mechanism_syntax_spec.rb +42 -0
- data/spec/open_spf/Processing_limits_spec.rb +72 -0
- data/spec/open_spf/Record_evaluation_spec.rb +75 -0
- data/spec/open_spf/Record_lookup_spec.rb +48 -0
- data/spec/open_spf/Selecting_records_spec.rb +61 -0
- data/spec/open_spf/Semantics_of_exp_and_other_modifiers_spec.rb +167 -0
- data/spec/open_spf/Test_cases_from_implementation_bugs_spec.rb +17 -0
- data/spec/qualifier_spec.rb +54 -0
- data/spec/record_evaluator_spec.rb +4 -0
- data/spec/record_finder_spec.rb +4 -0
- data/spec/record_spec.rb +100 -0
- data/spec/request_context_spec.rb +43 -0
- data/spec/request_count_limiter_spec.rb +28 -0
- data/spec/result_spec.rb +4 -0
- data/spec/rfc7208-tests.yml +2548 -0
- data/spec/sender_identity_spec.rb +69 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/term_spec.rb +38 -0
- data/spec/utils/domain_utils_spec.rb +60 -0
- data/spec/utils/host_utils_spec.rb +32 -0
- data/spec/utils/ip_in_domain_checker_spec.rb +4 -0
- data/spec/utils/validated_domain_finder_spec.rb +4 -0
- metadata +306 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3bcbc913e28d44152b2f68d954533ec5ece2d454
|
4
|
+
data.tar.gz: f2d0f7ab141c086ceb8476e7e7c091185d3fd67a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 128de64f9739785af238106d2ed7b8297a3bc98a41e58193833f8c4ec07dcfa402d847de56a4fccc0d4347a437fbbcd1f00f2d276ae93a06fde290dbf4e9746a
|
7
|
+
data.tar.gz: 5e8e211d963dc5f1135a8e870e3b176f9349a220c1d0eac4822c5c0884ed8f91353728b71d8169e17a44352ec7bfb052a11cc8a18b6033402cd247ac42283954
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Coppertone
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/petergoldstein/coppertone.svg?branch=master)](https://travis-ci.org/petergoldstein/coppertone)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/petergoldstein/coppertone/badges/coverage.svg)](https://codeclimate.com/github/petergoldstein/coppertone)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/petergoldstein/coppertone/badges/gpa.svg)](https://codeclimate.com/github/petergoldstein/coppertone)
|
6
|
+
|
7
|
+
A Sender Policy Framework (SPF) toolkit for Ruby.
|
8
|
+
|
9
|
+
Coppertone includes tools for parsing SPF DNS records, evaluating the result of SPF checks for received emails, and creating appropriate email headers from the SPF result. In the future the gem will build on these capabilities to allow deeper analysis of SPF configuration for hosts, senders, and domains.
|
10
|
+
|
11
|
+
## Specification Compliance
|
12
|
+
|
13
|
+
One of the challenges of writing a gem that is intended to implement a specification - especially one with as long a history as SPF - is determining exactly which version(s) and extensions to the specification the library will support. Coppertone uses the following guidelines:
|
14
|
+
|
15
|
+
1. By default Coppertone follows [RFC 7208](http://tools.ietf.org/html/rfc7208), which is the latest revision of the SPF v1 definition and obsoletes the earlier [RFC 4408](http://tools.ietf.org/html/rfc4408)
|
16
|
+
2. The gem explicitly does not support [RFC 4406](http://tools.ietf.org/html/rfc4406), which defines an experimental SPF v2 (Sender ID). PR requests to add support for this functionality will be rejected.
|
17
|
+
3. Coppertone defaults to using the DNS term and lookup limits defined in [RFC 7208](http://tools.ietf.org/html/rfc7208#section-4.6.4), but makes these limits configurable.
|
18
|
+
4. Coppertone does not do TLD validation on domains encountered in SPF processing. Domains are syntactically validated, but the TLD value is not checked against the public access list.
|
19
|
+
|
20
|
+
If you'd like to suggest amending these guidelines, please open an issue for discussion. Suggestions driven by real world behavior - divergences implemented by major mail server vendors or MTAs will be prioritized.
|
21
|
+
|
22
|
+
## Requirements
|
23
|
+
|
24
|
+
Coppertone supports MRI 2.0 and up - earlier MRI rubies are not supported. JRuby and Rubinius support is planned, but these VMs are not currently supported.
|
25
|
+
|
26
|
+
Coppertone does not require Rails.
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'coppertone'
|
34
|
+
```
|
35
|
+
|
36
|
+
And then execute:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
Or install it yourself as:
|
41
|
+
|
42
|
+
$ gem install coppertone
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
TODO: Write usage instructions here
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
We actively seek contributions from the Coppertone community to make this the best possible gem. Users can contribute by creating a pull request with the requested changes.
|
51
|
+
|
52
|
+
Some guidelines:
|
53
|
+
|
54
|
+
1. The scope of this gem is limited to the Sender Policy Framework. New functionality should be restricted to features directly relevant to SPF.
|
55
|
+
2. PRs that add functionality or fix bugs must include test coverage for the new functionality or fixed bug. PRs that don't include such test coverage will not be merged.
|
56
|
+
3. PRs should not break existing specs unintentionally. Only PRs that run green will be merged to master.
|
57
|
+
4. Similarly, PRs should not introduce new Rubocop violations.
|
58
|
+
5. Please run `bundle exec rake` before submitting your PR and ensure it runs clean. This will help ensure against inadvertent spec breakage or Rubocop violations.
|
data/Rakefile
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
task default: :spec
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new do |t|
|
7
|
+
t.rspec_opts = ['--color', '--format doc']
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rubocop/rake_task'
|
11
|
+
|
12
|
+
desc 'Run RuboCop on the lib directory'
|
13
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
14
|
+
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
|
15
|
+
# don't abort rake on failure
|
16
|
+
task.fail_on_error = false
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'json'
|
20
|
+
require 'yaml'
|
21
|
+
require 'fileutils'
|
22
|
+
desc 'Parse OpenSPF tests'
|
23
|
+
|
24
|
+
def spec_file_name(doc, output_path)
|
25
|
+
description = doc['description']
|
26
|
+
file_name = description.gsub(/[^\w\s_-]+/, '')
|
27
|
+
.gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
|
28
|
+
.gsub(/\s+/, '_') + '_spec.rb'
|
29
|
+
File.join(output_path, file_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
INDENT_STRING = ' '
|
33
|
+
def indented_string(num_indents = 1)
|
34
|
+
num_indents.times.map { INDENT_STRING }.join('')
|
35
|
+
end
|
36
|
+
|
37
|
+
def puts_prefixed_string(f, s, indent = 0)
|
38
|
+
f.write indented_string(indent) unless indent == 0
|
39
|
+
f.puts s
|
40
|
+
end
|
41
|
+
|
42
|
+
def empty_line(f)
|
43
|
+
puts_prefixed_string(f, '', 0)
|
44
|
+
end
|
45
|
+
|
46
|
+
def write_zonedata(f, zonedata, indent = 1)
|
47
|
+
puts_prefixed_string(f, 'let(:zonefile) do', indent)
|
48
|
+
puts_prefixed_string(f, zonedata, indent + 1)
|
49
|
+
puts_prefixed_string(f, 'end', indent)
|
50
|
+
empty_line(f)
|
51
|
+
dns_line = 'let(:dns_client) { Coppertone::DNS::MockClient.new(zonefile) }'
|
52
|
+
puts_prefixed_string(f, dns_line, indent)
|
53
|
+
puts_prefixed_string(f, 'let(:options) { { dns_client: dns_client } }',
|
54
|
+
indent)
|
55
|
+
empty_line(f)
|
56
|
+
end
|
57
|
+
|
58
|
+
def escape_quote(val)
|
59
|
+
return unless val
|
60
|
+
val.gsub(/'/) { |_s| "\\'" }
|
61
|
+
end
|
62
|
+
|
63
|
+
def clean_description(description)
|
64
|
+
return unless description
|
65
|
+
description.gsub("\n", ' ').gsub("'", '')
|
66
|
+
end
|
67
|
+
|
68
|
+
def as_array(val)
|
69
|
+
return [] unless val
|
70
|
+
val.is_a?(Array) ? val : [val]
|
71
|
+
end
|
72
|
+
|
73
|
+
def write_comment(f, comment, indent)
|
74
|
+
return unless comment
|
75
|
+
comment.lines do |comment_line|
|
76
|
+
puts_prefixed_string(f, "# #{comment_line}", indent)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def write_result(f, host, mailfrom, helo, indent)
|
81
|
+
spf_result =
|
82
|
+
"Coppertone::SpfService.authenticate_email('#{host}', '#{mailfrom}'," \
|
83
|
+
" '#{helo}', options)"
|
84
|
+
puts_prefixed_string(f, "result = #{spf_result}", indent)
|
85
|
+
end
|
86
|
+
|
87
|
+
def write_expects(f, results, explanation, indent)
|
88
|
+
results_array = "%i(#{results.join(' ')})"
|
89
|
+
code_expect = "expect(#{results_array}).to include(result.code)"
|
90
|
+
puts_prefixed_string(f, code_expect, indent)
|
91
|
+
return unless explanation
|
92
|
+
exp_expect = "expect(result.explanation).to eq('#{explanation}')"
|
93
|
+
puts_prefixed_string(f, exp_expect, indent)
|
94
|
+
end
|
95
|
+
|
96
|
+
def normalize_spec_args(spec)
|
97
|
+
helo = escape_quote(spec['helo'])
|
98
|
+
host = escape_quote(spec['host'])
|
99
|
+
mailfrom = escape_quote(spec['mailfrom'])
|
100
|
+
comment = escape_quote(spec['comment'])
|
101
|
+
description = clean_description(spec['description'])
|
102
|
+
results = as_array(spec['result'])
|
103
|
+
explanation = escape_quote(spec['explanation'])
|
104
|
+
[helo, host, mailfrom, comment, description, results, explanation]
|
105
|
+
end
|
106
|
+
|
107
|
+
def write_spec(f, spec, indent = 1)
|
108
|
+
helo, host, mailfrom, comment, description, results, explanation =
|
109
|
+
normalize_spec_args(spec)
|
110
|
+
puts_prefixed_string(f, "it '#{description}' do", indent)
|
111
|
+
write_comment(f, comment, indent + 1)
|
112
|
+
write_result(f, host, mailfrom, helo, indent + 1)
|
113
|
+
write_expects(f, results, explanation, indent + 1)
|
114
|
+
puts_prefixed_string(f, 'end', indent)
|
115
|
+
empty_line(f)
|
116
|
+
end
|
117
|
+
|
118
|
+
def write_doc(doc, output_path)
|
119
|
+
open(spec_file_name(doc, output_path), 'w') do |f|
|
120
|
+
puts_prefixed_string(f, "require 'spec_helper'")
|
121
|
+
empty_line(f)
|
122
|
+
description = doc['description']
|
123
|
+
puts_prefixed_string(f, "describe '#{description}' do")
|
124
|
+
write_zonedata(f, doc['zonedata'], 1)
|
125
|
+
doc['tests'].each do |k, spec|
|
126
|
+
spec['description'] ||= k
|
127
|
+
write_spec(f, spec)
|
128
|
+
end
|
129
|
+
puts_prefixed_string(f, 'end')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
task :build_open_spf_test_suite do
|
134
|
+
yml_file_name = 'rfc7208-tests.yml'
|
135
|
+
yml_file_path = File.join(File.dirname(__FILE__), 'spec', yml_file_name)
|
136
|
+
output_path = File.join(File.dirname(__FILE__), 'spec', 'open_spf')
|
137
|
+
FileUtils.mkdir_p(output_path)
|
138
|
+
documents = YAML.load_stream(File.open(yml_file_path).read)
|
139
|
+
documents.each { |doc| write_doc(doc, output_path) }
|
140
|
+
end
|
data/coppertone.gemspec
ADDED
@@ -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 'coppertone/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'coppertone'
|
8
|
+
spec.version = Coppertone::VERSION
|
9
|
+
spec.authors = ['Peter M. Goldstein']
|
10
|
+
spec.email = ['peter.m.goldstein@gmail.com']
|
11
|
+
spec.summary = 'A Sender Policy Framework (SPF) toolkit'
|
12
|
+
spec.description = 'Coppertone includes tools for parsing SPF DNS records, evaluating the result of SPF checks for received emails, and creating appropriate email headers from SPF results.'
|
13
|
+
spec.homepage = 'https://github.com/petergoldstein/coppertone'
|
14
|
+
spec.license = 'Apache'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'i18n'
|
21
|
+
spec.add_runtime_dependency 'addressable'
|
22
|
+
spec.add_runtime_dependency 'activesupport', '>= 3.0'
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
26
|
+
spec.add_development_dependency 'rubocop'
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coppertone
|
2
|
+
# Utility class for building class instances out of a set of
|
3
|
+
# registered types (e.g. mechanisms, modifiers)
|
4
|
+
class ClassBuilder
|
5
|
+
def map
|
6
|
+
@map ||= {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def register(type, klass)
|
10
|
+
map[type] = klass
|
11
|
+
end
|
12
|
+
|
13
|
+
def build(type, attributes)
|
14
|
+
return nil unless type
|
15
|
+
klass = map[type]
|
16
|
+
return nil unless klass
|
17
|
+
klass.create(attributes)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'coppertone/mechanism'
|
2
|
+
require 'coppertone/qualifier'
|
3
|
+
|
4
|
+
module Coppertone
|
5
|
+
# Instances of this class represent directive terms, as defined by the
|
6
|
+
# SPF specification (see section 4.6.1).
|
7
|
+
class Directive
|
8
|
+
attr_reader :qualifier, :mechanism
|
9
|
+
def initialize(qualifier, mechanism)
|
10
|
+
@qualifier = qualifier
|
11
|
+
@mechanism = mechanism
|
12
|
+
end
|
13
|
+
|
14
|
+
def evaluate(context, options)
|
15
|
+
code =
|
16
|
+
if mechanism.match?(context, options)
|
17
|
+
qualifier.result_code
|
18
|
+
else
|
19
|
+
Result::NONE
|
20
|
+
end
|
21
|
+
Coppertone::Result.from_directive(self, code)
|
22
|
+
end
|
23
|
+
|
24
|
+
DIRECTIVE_REGEXP = /\A([\+\-\~\?]?)([a-zA-Z0-9]*)((:?)\S*)\z/
|
25
|
+
def self.matching_term(text)
|
26
|
+
return nil if text.include?('=')
|
27
|
+
matches = DIRECTIVE_REGEXP.match(text)
|
28
|
+
return nil unless matches
|
29
|
+
qualifier_txt = matches[1]
|
30
|
+
mechanism_type = matches[2].downcase
|
31
|
+
attributes = matches[3]
|
32
|
+
qualifier = Qualifier.find_by_text(qualifier_txt)
|
33
|
+
mechanism = Mechanism.build(mechanism_type, attributes)
|
34
|
+
return nil unless qualifier && mechanism
|
35
|
+
new(qualifier, mechanism)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'coppertone/error'
|
2
|
+
|
3
|
+
module Coppertone
|
4
|
+
module DNS
|
5
|
+
# A mock client for use in tests.
|
6
|
+
class MockClient
|
7
|
+
def initialize(zone_data)
|
8
|
+
@zone_data = {}
|
9
|
+
zone_data.each do |k, v|
|
10
|
+
@zone_data[k.downcase] = v.dup
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch_a_records(domain)
|
15
|
+
fetch_records(domain, 'A')
|
16
|
+
end
|
17
|
+
|
18
|
+
def fetch_aaaa_records(domain)
|
19
|
+
fetch_records(domain, 'AAAA')
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_mx_records(domain)
|
23
|
+
fetch_records(domain, 'MX')
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch_ptr_records(arpa_address)
|
27
|
+
fetch_records(arpa_address, 'PTR')
|
28
|
+
end
|
29
|
+
|
30
|
+
def fetch_txt_records(domain)
|
31
|
+
fetch_records(domain, 'TXT')
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch_spf_records(domain)
|
35
|
+
fetch_records(domain, 'SPF')
|
36
|
+
end
|
37
|
+
|
38
|
+
def fetch_records(domain, type)
|
39
|
+
record_set = find_records_for_domain(domain)
|
40
|
+
return [] if record_set.empty?
|
41
|
+
records = records_for_type(record_set, type)
|
42
|
+
if records.empty?
|
43
|
+
check_for_timeout(record_set)
|
44
|
+
else
|
45
|
+
formatted_records(records, type)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def normalize_domain(domain)
|
52
|
+
return if domain.blank?
|
53
|
+
domain = domain[0...-1] if domain[domain.length - 1] == '.'
|
54
|
+
domain.downcase
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_records_for_domain(domain)
|
58
|
+
return [] if domain.blank?
|
59
|
+
@zone_data[normalize_domain(domain)] || []
|
60
|
+
end
|
61
|
+
|
62
|
+
def records_for_type(record_set, type)
|
63
|
+
record_set.select do |r|
|
64
|
+
r.is_a?(Hash) && r[type] && r[type] != 'NONE'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
TIMEOUT = 'TIMEOUT'
|
69
|
+
def check_for_timeout(record_set)
|
70
|
+
return [] if record_set.select { |r| r == TIMEOUT }.empty?
|
71
|
+
fail Coppertone::DNS::TimeoutError
|
72
|
+
end
|
73
|
+
|
74
|
+
RECORD_TYPE_TO_ATTR_NAME_MAP = {
|
75
|
+
'A' => :address,
|
76
|
+
'AAAA' => :address,
|
77
|
+
'MX' => :exchange,
|
78
|
+
'PTR' => :name,
|
79
|
+
'SPF' => :text,
|
80
|
+
'TXT' => :text
|
81
|
+
}
|
82
|
+
|
83
|
+
def formatted_records(records, type)
|
84
|
+
records.map do |r|
|
85
|
+
val = r[type]
|
86
|
+
fail Coppertone::DNS::TimeoutError if val == TIMEOUT
|
87
|
+
val = normalize_value(val, type)
|
88
|
+
{
|
89
|
+
type: type,
|
90
|
+
RECORD_TYPE_TO_ATTR_NAME_MAP[type] => val
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def normalize_value(value, type)
|
96
|
+
if type == 'MX' && value.is_a?(Array)
|
97
|
+
value.last
|
98
|
+
elsif (type == 'TXT' || type == 'SPF') && value.is_a?(Array)
|
99
|
+
value.join('')
|
100
|
+
else
|
101
|
+
value
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|