email_assessor 0.1 → 0.2
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.
- checksums.yaml +4 -4
- data/email_assessor.gemspec +1 -1
- data/lib/email_assessor.rb +22 -8
- data/lib/email_assessor/version.rb +1 -1
- data/pull_mailchecker_emails.rb +0 -2
- data/spec/email_assessor_spec.rb +73 -31
- data/spec/fixtures/blacklisted_domains.txt +1 -0
- data/spec/fixtures/disposable_domains.txt +1 -0
- data/spec/spec_helper.rb +4 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e86b0145f0a1eadce4c8df87b7c1172974e284
|
4
|
+
data.tar.gz: b226714891f60a08facb4c93f4185ad723d3d9be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0e0af20e1ec8ae109b88120c97cdb754a453771d6eecb90e88bff09897ffd2f1354ee4564353c4034923ad6ddc6b66e3db39d6d0d4f04f13df6fab689bcf93c
|
7
|
+
data.tar.gz: 459aa3cb6b2234535c5470930f08549064fab9eb079cf590b287cb38df26027a32df16b16771f4e73c30ea5e327da5b1302a08962e611c524912cd144db52061
|
data/email_assessor.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
26
26
|
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rspec", "~>
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
28
28
|
spec.add_runtime_dependency "mail", "~> 2.5"
|
29
29
|
spec.add_runtime_dependency "activemodel", ">= 3.2"
|
30
30
|
end
|
data/lib/email_assessor.rb
CHANGED
@@ -1,26 +1,40 @@
|
|
1
1
|
require "email_assessor/email_validator"
|
2
2
|
|
3
3
|
module EmailAssessor
|
4
|
-
DISPOSABLE_DOMAINS_FILE = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
|
5
|
-
BLACKLISTED_DOMAINS_FILE = File.expand_path("../../vendor/blacklisted_domains.txt", __FILE__)
|
6
|
-
|
7
4
|
def self.domain_is_disposable?(domain)
|
8
|
-
domain_in_file?(domain,
|
5
|
+
domain_in_file?(domain, configuration.disposable_domains_file_name)
|
9
6
|
end
|
10
7
|
|
11
8
|
def self.domain_is_blacklisted?(domain)
|
12
|
-
domain_in_file?(domain,
|
9
|
+
domain_in_file?(domain, configuration.blacklisted_domains_file_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
@@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
yield(configuration) if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
class Configuration
|
21
|
+
attr_accessor :disposable_domains_file_name, :blacklisted_domains_file_name
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@disposable_domains_file_name = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
|
25
|
+
@blacklisted_domains_file_name = File.expand_path("vendor/blacklisted_domains.txt")
|
26
|
+
end
|
13
27
|
end
|
14
28
|
|
15
29
|
protected
|
16
30
|
|
17
|
-
def self.domain_in_file?(domain,
|
18
|
-
return false unless File.exists?(
|
31
|
+
def self.domain_in_file?(domain, file_name)
|
32
|
+
return false unless file_name.present? && File.exists?(file_name)
|
19
33
|
|
20
34
|
domain = domain.downcase
|
21
35
|
domain_matched = false
|
22
36
|
|
23
|
-
File.open(
|
37
|
+
File.open(file_name).each do |line|
|
24
38
|
if domain.end_with?(line.chomp)
|
25
39
|
domain_matched = true
|
26
40
|
break
|
data/pull_mailchecker_emails.rb
CHANGED
@@ -14,8 +14,6 @@ resp = Net::HTTP.get_response(URI.parse(url))
|
|
14
14
|
|
15
15
|
remote_domains = JSON.parse(resp.body).flatten - whitelisted_domains
|
16
16
|
|
17
|
-
puts "New domains found: #{(remote_domains - existing_domains).join(', ')}"
|
18
|
-
|
19
17
|
result_domains = (existing_domains + remote_domains).map { |domain| domain.strip.downcase }.uniq.sort
|
20
18
|
|
21
19
|
File.open("vendor/disposable_domains.txt", "w") { |f| f.write result_domains.join("\n") }
|
data/spec/email_assessor_spec.rb
CHANGED
@@ -17,86 +17,128 @@ class TestUserDisallowBlacklisted < TestModel
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe EmailAssessor do
|
20
|
+
let(:plain_user) { TestUser.new(email: "") }
|
21
|
+
let(:disposable_user) { TestUserDisallowDisposable.new(email: "foo@gmail.com") }
|
22
|
+
let(:blacklist_user) { TestUserDisallowBlacklisted.new(email: "foo@gmail.com") }
|
23
|
+
let(:mx_user) { TestUserMX.new(email: "foo@gmail.com") }
|
24
|
+
|
25
|
+
let(:blacklisted_domains_file_name) { described_class.configuration.blacklisted_domains_file_name }
|
26
|
+
let(:blacklisted_domain) { File.open(blacklisted_domains_file_name, &:readline) }
|
27
|
+
|
28
|
+
let(:disposable_domains_file_name) { described_class.configuration.disposable_domains_file_name }
|
29
|
+
let(:disposable_domain) { File.open(disposable_domains_file_name, &:readline) }
|
30
|
+
|
20
31
|
describe "basic validation" do
|
21
|
-
subject(:user) {
|
32
|
+
subject(:user) { plain_user }
|
22
33
|
|
23
34
|
it "should be valid when email is empty" do
|
24
|
-
|
35
|
+
is_expected.to be_valid
|
25
36
|
end
|
26
37
|
|
27
38
|
it "should not be valid when domain is missing" do
|
28
|
-
user =
|
29
|
-
|
39
|
+
user.email = "foo"
|
40
|
+
is_expected.to be_invalid
|
30
41
|
end
|
31
42
|
|
32
43
|
it "should be invalid when email is malformed" do
|
33
|
-
user =
|
34
|
-
|
44
|
+
user.email = "foo@bar"
|
45
|
+
is_expected.to be_invalid
|
35
46
|
end
|
36
47
|
|
37
48
|
it "should be invalid when email contains a trailing symbol" do
|
38
|
-
user =
|
39
|
-
|
49
|
+
user.email = "foo@bar.com/"
|
50
|
+
is_expected.to be_invalid
|
40
51
|
end
|
41
52
|
|
42
53
|
it "should be invalid if Mail::AddressListsParser raises exception" do
|
43
|
-
|
44
|
-
|
45
|
-
|
54
|
+
allow(Mail::Address).to receive(:new).and_raise(Mail::Field::ParseError.new(nil, nil, nil))
|
55
|
+
user.email = "foo@gmail.com"
|
56
|
+
is_expected.to be_invalid
|
46
57
|
end
|
47
58
|
|
48
59
|
it "shouldn't be valid if the domain constains consecutives dots" do
|
49
|
-
user =
|
50
|
-
|
60
|
+
user.email = "foo@bar..com"
|
61
|
+
is_expected.to be_invalid
|
51
62
|
end
|
52
63
|
end
|
53
64
|
|
54
65
|
describe "disposable domains" do
|
55
|
-
|
66
|
+
subject(:user) { disposable_user }
|
56
67
|
|
57
68
|
it "should be valid when email is not in the list of disposable domains" do
|
58
|
-
|
59
|
-
user.valid?.should be_true
|
69
|
+
is_expected.to be_valid
|
60
70
|
end
|
61
71
|
|
62
72
|
it "should be invalid when email is in the list of disposable domains" do
|
63
|
-
user =
|
64
|
-
|
73
|
+
user.email = "foo@#{disposable_domain}"
|
74
|
+
is_expected.to be_invalid
|
65
75
|
end
|
66
76
|
|
67
77
|
it "should be invalid when email is in the list of disposable domains regardless of subdomain" do
|
68
|
-
user =
|
69
|
-
|
78
|
+
user.email = "foo@abc123.#{disposable_domain}"
|
79
|
+
is_expected.to be_invalid
|
70
80
|
end
|
71
81
|
end
|
72
82
|
|
73
83
|
describe "blacklisted domains" do
|
74
|
-
|
84
|
+
subject(:user) { blacklist_user }
|
85
|
+
|
75
86
|
it "should be valid when email domain is not in the blacklist" do
|
76
|
-
|
77
|
-
user.valid?.should be_true
|
87
|
+
is_expected.to be_valid
|
78
88
|
end
|
79
89
|
|
80
90
|
it "should be invalid when email domain is in the blacklist" do
|
81
|
-
user =
|
82
|
-
|
91
|
+
user.email = "foo@#{blacklisted_domain}"
|
92
|
+
is_expected.to be_invalid
|
83
93
|
end
|
84
94
|
|
85
95
|
it "should be invalid when email domain is in the blacklist regardless of subdomain" do
|
86
|
-
user =
|
87
|
-
|
96
|
+
user.email = "foo@abc123.#{blacklisted_domain}"
|
97
|
+
is_expected.to be_invalid
|
88
98
|
end
|
89
99
|
end
|
90
100
|
|
91
101
|
describe "mx lookup" do
|
102
|
+
subject(:user) { mx_user }
|
103
|
+
|
92
104
|
it "should be valid if mx records are found" do
|
93
|
-
|
94
|
-
user.valid?.should be_true
|
105
|
+
is_expected.to be_valid
|
95
106
|
end
|
96
107
|
|
97
108
|
it "should be invalid if no mx records are found" do
|
98
|
-
user =
|
99
|
-
|
109
|
+
user.email = "foo@subdomain.gmail.com"
|
110
|
+
is_expected.to be_invalid
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "configuration" do
|
115
|
+
subject(:configuration) { described_class.configuration }
|
116
|
+
let(:disposable_domains_file_name) { File.expand_path("../fixtures/disposable_domains.txt", __FILE__) }
|
117
|
+
let(:blacklisted_domains_file_name) { File.expand_path("../fixtures/blacklisted_domains.txt", __FILE__) }
|
118
|
+
|
119
|
+
before do
|
120
|
+
described_class.configure do |config|
|
121
|
+
config.disposable_domains_file_name = disposable_domains_file_name
|
122
|
+
config.blacklisted_domains_file_name = blacklisted_domains_file_name
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "sets the disposable domains file" do
|
127
|
+
is_expected.to have_attributes disposable_domains_file_name: disposable_domains_file_name
|
128
|
+
end
|
129
|
+
|
130
|
+
it "sets the blacklisted domains file" do
|
131
|
+
is_expected.to have_attributes blacklisted_domains_file_name: blacklisted_domains_file_name
|
132
|
+
end
|
133
|
+
|
134
|
+
it "uses the configured disposable domains file" do
|
135
|
+
disposable_user.email = disposable_domain
|
136
|
+
expect(disposable_user).to be_invalid
|
137
|
+
end
|
138
|
+
|
139
|
+
it "uses the configured blacklisted domains file" do
|
140
|
+
blacklist_user.email = blacklisted_domain
|
141
|
+
expect(blacklist_user).to be_invalid
|
100
142
|
end
|
101
143
|
end
|
102
144
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
rspec-blacklisted.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
rspec-disposable.txt
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_assessor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Wolfe Millard
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '3.4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '3.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mail
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +103,8 @@ files:
|
|
103
103
|
- lib/email_assessor/version.rb
|
104
104
|
- pull_mailchecker_emails.rb
|
105
105
|
- spec/email_assessor_spec.rb
|
106
|
+
- spec/fixtures/blacklisted_domains.txt
|
107
|
+
- spec/fixtures/disposable_domains.txt
|
106
108
|
- spec/spec_helper.rb
|
107
109
|
- vendor/blacklisted_domains.txt
|
108
110
|
- vendor/disposable_domains.txt
|
@@ -132,4 +134,6 @@ specification_version: 4
|
|
132
134
|
summary: Advanced ActiveModel email validation
|
133
135
|
test_files:
|
134
136
|
- spec/email_assessor_spec.rb
|
137
|
+
- spec/fixtures/blacklisted_domains.txt
|
138
|
+
- spec/fixtures/disposable_domains.txt
|
135
139
|
- spec/spec_helper.rb
|