email_assessor 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/assets/data/blacklisted_domains/_prioritization.txt +1 -0
  3. data/assets/data/disposable_domains/0.txt +723 -0
  4. data/assets/data/disposable_domains/1.txt +1500 -0
  5. data/assets/data/disposable_domains/2.txt +1267 -0
  6. data/assets/data/disposable_domains/3.txt +1078 -0
  7. data/assets/data/disposable_domains/4.txt +854 -0
  8. data/assets/data/disposable_domains/5.txt +793 -0
  9. data/assets/data/disposable_domains/6.txt +900 -0
  10. data/assets/data/disposable_domains/7.txt +787 -0
  11. data/assets/data/disposable_domains/8.txt +979 -0
  12. data/assets/data/disposable_domains/9.txt +843 -0
  13. data/assets/data/disposable_domains/_prioritization.txt +1 -0
  14. data/assets/data/disposable_domains/a.txt +10167 -0
  15. data/assets/data/disposable_domains/b.txt +10443 -0
  16. data/assets/data/disposable_domains/c.txt +10152 -0
  17. data/assets/data/disposable_domains/d.txt +7619 -0
  18. data/assets/data/disposable_domains/e.txt +5689 -0
  19. data/assets/data/disposable_domains/f.txt +6375 -0
  20. data/assets/data/disposable_domains/g.txt +6309 -0
  21. data/assets/data/disposable_domains/h.txt +6204 -0
  22. data/assets/data/disposable_domains/i.txt +4814 -0
  23. data/assets/data/disposable_domains/j.txt +3163 -0
  24. data/assets/data/disposable_domains/k.txt +4308 -0
  25. data/assets/data/disposable_domains/l.txt +5903 -0
  26. data/assets/data/disposable_domains/m.txt +11177 -0
  27. data/assets/data/disposable_domains/n.txt +4895 -0
  28. data/assets/data/disposable_domains/o.txt +4161 -0
  29. data/assets/data/disposable_domains/p.txt +8264 -0
  30. data/assets/data/disposable_domains/q.txt +1493 -0
  31. data/assets/data/disposable_domains/r.txt +6199 -0
  32. data/assets/data/disposable_domains/s.txt +12775 -0
  33. data/assets/data/disposable_domains/t.txt +9496 -0
  34. data/assets/data/disposable_domains/u.txt +2662 -0
  35. data/assets/data/disposable_domains/v.txt +3766 -0
  36. data/assets/data/disposable_domains/w.txt +4633 -0
  37. data/assets/data/disposable_domains/x.txt +2449 -0
  38. data/assets/data/disposable_domains/y.txt +2278 -0
  39. data/assets/data/disposable_domains/z.txt +2035 -0
  40. data/assets/data/disposable_domains//351/231/270.txt +1 -0
  41. data/assets/data/disposable_domains//353/234/203.txt +1 -0
  42. data/assets/data/educational_domains/5.txt +1 -0
  43. data/assets/data/educational_domains/_prioritization.txt +1 -0
  44. data/assets/data/educational_domains/a.txt +232 -0
  45. data/assets/data/educational_domains/b.txt +112 -0
  46. data/assets/data/educational_domains/c.txt +126 -0
  47. data/assets/data/educational_domains/d.txt +90 -0
  48. data/assets/data/educational_domains/e.txt +331 -0
  49. data/assets/data/educational_domains/f.txt +156 -0
  50. data/assets/data/educational_domains/g.txt +75 -0
  51. data/assets/data/educational_domains/h.txt +147 -0
  52. data/assets/data/educational_domains/i.txt +179 -0
  53. data/assets/data/educational_domains/j.txt +26 -0
  54. data/assets/data/educational_domains/k.txt +142 -0
  55. data/assets/data/educational_domains/l.txt +88 -0
  56. data/assets/data/educational_domains/m.txt +155 -0
  57. data/assets/data/educational_domains/n.txt +98 -0
  58. data/assets/data/educational_domains/o.txt +39 -0
  59. data/assets/data/educational_domains/p.txt +128 -0
  60. data/assets/data/educational_domains/q.txt +4 -0
  61. data/assets/data/educational_domains/r.txt +69 -0
  62. data/assets/data/educational_domains/s.txt +251 -0
  63. data/assets/data/educational_domains/t.txt +146 -0
  64. data/assets/data/educational_domains/u.txt +975 -0
  65. data/assets/data/educational_domains/v.txt +78 -0
  66. data/assets/data/educational_domains/w.txt +59 -0
  67. data/assets/data/educational_domains/x.txt +1 -0
  68. data/assets/data/educational_domains/y.txt +17 -0
  69. data/assets/data/educational_domains/z.txt +13 -0
  70. data/assets/data/fastpass_domains/_prioritization.txt +1 -0
  71. data/assets/data/fastpass_domains/a.txt +2 -0
  72. data/assets/data/fastpass_domains/c.txt +3 -0
  73. data/assets/data/fastpass_domains/d.txt +1 -0
  74. data/assets/data/fastpass_domains/f.txt +1 -0
  75. data/assets/data/fastpass_domains/g.txt +5 -0
  76. data/assets/data/fastpass_domains/h.txt +33 -0
  77. data/assets/data/fastpass_domains/i.txt +1 -0
  78. data/assets/data/fastpass_domains/l.txt +6 -0
  79. data/assets/data/fastpass_domains/m.txt +4 -0
  80. data/assets/data/fastpass_domains/o.txt +28 -0
  81. data/assets/data/fastpass_domains/p.txt +3 -0
  82. data/assets/data/fastpass_domains/r.txt +1 -0
  83. data/assets/data/fastpass_domains/s.txt +3 -0
  84. data/assets/data/fastpass_domains/t.txt +1 -0
  85. data/assets/data/fastpass_domains/w.txt +2 -0
  86. data/assets/data/fastpass_domains/y.txt +42 -0
  87. data/lib/email_assessor/address.rb +8 -17
  88. data/lib/email_assessor/directory_domain_list.rb +51 -0
  89. data/lib/email_assessor/domain_token_set.rb +46 -0
  90. data/lib/email_assessor/email_validator.rb +0 -16
  91. data/lib/email_assessor/empty_domain_list.rb +23 -0
  92. data/lib/email_assessor/file_domain_list.rb +23 -0
  93. data/lib/email_assessor/version.rb +1 -1
  94. data/lib/email_assessor.rb +59 -25
  95. metadata +94 -22
  96. data/.gitignore +0 -18
  97. data/.travis.yml +0 -9
  98. data/CHANGELOG.md +0 -9
  99. data/Gemfile +0 -4
  100. data/LICENSE.txt +0 -22
  101. data/README.md +0 -132
  102. data/Rakefile +0 -10
  103. data/email_assessor.gemspec +0 -31
  104. data/gemfiles/activemodel4.gemfile +0 -5
  105. data/pull_mailchecker_emails.rb +0 -21
  106. data/spec/email_assessor_spec.rb +0 -209
  107. data/spec/spec_helper.rb +0 -19
  108. data/vendor/disposable_domains.txt +0 -56944
  109. data/vendor/educational_domains.txt +0 -3697
  110. data/vendor/fastpass_domains.txt +0 -136
  111. /data/{vendor/blacklisted_domains.txt → assets/data/blacklisted_domains/b.txt} +0 -0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_assessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Wolfe Millard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-09 00:00:00.000000000 Z
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,26 +87,100 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - ".gitignore"
91
- - ".travis.yml"
92
- - CHANGELOG.md
93
- - Gemfile
94
- - LICENSE.txt
95
- - README.md
96
- - Rakefile
97
- - email_assessor.gemspec
98
- - gemfiles/activemodel4.gemfile
90
+ - assets/data/blacklisted_domains/_prioritization.txt
91
+ - assets/data/blacklisted_domains/b.txt
92
+ - assets/data/disposable_domains/0.txt
93
+ - assets/data/disposable_domains/1.txt
94
+ - assets/data/disposable_domains/2.txt
95
+ - assets/data/disposable_domains/3.txt
96
+ - assets/data/disposable_domains/4.txt
97
+ - assets/data/disposable_domains/5.txt
98
+ - assets/data/disposable_domains/6.txt
99
+ - assets/data/disposable_domains/7.txt
100
+ - assets/data/disposable_domains/8.txt
101
+ - assets/data/disposable_domains/9.txt
102
+ - assets/data/disposable_domains/_prioritization.txt
103
+ - assets/data/disposable_domains/a.txt
104
+ - assets/data/disposable_domains/b.txt
105
+ - assets/data/disposable_domains/c.txt
106
+ - assets/data/disposable_domains/d.txt
107
+ - assets/data/disposable_domains/e.txt
108
+ - assets/data/disposable_domains/f.txt
109
+ - assets/data/disposable_domains/g.txt
110
+ - assets/data/disposable_domains/h.txt
111
+ - assets/data/disposable_domains/i.txt
112
+ - assets/data/disposable_domains/j.txt
113
+ - assets/data/disposable_domains/k.txt
114
+ - assets/data/disposable_domains/l.txt
115
+ - assets/data/disposable_domains/m.txt
116
+ - assets/data/disposable_domains/n.txt
117
+ - assets/data/disposable_domains/o.txt
118
+ - assets/data/disposable_domains/p.txt
119
+ - assets/data/disposable_domains/q.txt
120
+ - assets/data/disposable_domains/r.txt
121
+ - assets/data/disposable_domains/s.txt
122
+ - assets/data/disposable_domains/t.txt
123
+ - assets/data/disposable_domains/u.txt
124
+ - assets/data/disposable_domains/v.txt
125
+ - assets/data/disposable_domains/w.txt
126
+ - assets/data/disposable_domains/x.txt
127
+ - assets/data/disposable_domains/y.txt
128
+ - assets/data/disposable_domains/z.txt
129
+ - assets/data/disposable_domains/陸.txt
130
+ - assets/data/disposable_domains/뜃.txt
131
+ - assets/data/educational_domains/5.txt
132
+ - assets/data/educational_domains/_prioritization.txt
133
+ - assets/data/educational_domains/a.txt
134
+ - assets/data/educational_domains/b.txt
135
+ - assets/data/educational_domains/c.txt
136
+ - assets/data/educational_domains/d.txt
137
+ - assets/data/educational_domains/e.txt
138
+ - assets/data/educational_domains/f.txt
139
+ - assets/data/educational_domains/g.txt
140
+ - assets/data/educational_domains/h.txt
141
+ - assets/data/educational_domains/i.txt
142
+ - assets/data/educational_domains/j.txt
143
+ - assets/data/educational_domains/k.txt
144
+ - assets/data/educational_domains/l.txt
145
+ - assets/data/educational_domains/m.txt
146
+ - assets/data/educational_domains/n.txt
147
+ - assets/data/educational_domains/o.txt
148
+ - assets/data/educational_domains/p.txt
149
+ - assets/data/educational_domains/q.txt
150
+ - assets/data/educational_domains/r.txt
151
+ - assets/data/educational_domains/s.txt
152
+ - assets/data/educational_domains/t.txt
153
+ - assets/data/educational_domains/u.txt
154
+ - assets/data/educational_domains/v.txt
155
+ - assets/data/educational_domains/w.txt
156
+ - assets/data/educational_domains/x.txt
157
+ - assets/data/educational_domains/y.txt
158
+ - assets/data/educational_domains/z.txt
159
+ - assets/data/fastpass_domains/_prioritization.txt
160
+ - assets/data/fastpass_domains/a.txt
161
+ - assets/data/fastpass_domains/c.txt
162
+ - assets/data/fastpass_domains/d.txt
163
+ - assets/data/fastpass_domains/f.txt
164
+ - assets/data/fastpass_domains/g.txt
165
+ - assets/data/fastpass_domains/h.txt
166
+ - assets/data/fastpass_domains/i.txt
167
+ - assets/data/fastpass_domains/l.txt
168
+ - assets/data/fastpass_domains/m.txt
169
+ - assets/data/fastpass_domains/o.txt
170
+ - assets/data/fastpass_domains/p.txt
171
+ - assets/data/fastpass_domains/r.txt
172
+ - assets/data/fastpass_domains/s.txt
173
+ - assets/data/fastpass_domains/t.txt
174
+ - assets/data/fastpass_domains/w.txt
175
+ - assets/data/fastpass_domains/y.txt
99
176
  - lib/email_assessor.rb
100
177
  - lib/email_assessor/address.rb
178
+ - lib/email_assessor/directory_domain_list.rb
179
+ - lib/email_assessor/domain_token_set.rb
101
180
  - lib/email_assessor/email_validator.rb
181
+ - lib/email_assessor/empty_domain_list.rb
182
+ - lib/email_assessor/file_domain_list.rb
102
183
  - lib/email_assessor/version.rb
103
- - pull_mailchecker_emails.rb
104
- - spec/email_assessor_spec.rb
105
- - spec/spec_helper.rb
106
- - vendor/blacklisted_domains.txt
107
- - vendor/disposable_domains.txt
108
- - vendor/educational_domains.txt
109
- - vendor/fastpass_domains.txt
110
184
  homepage: https://github.com/wolfemm/email_assessor
111
185
  licenses:
112
186
  - MIT
@@ -126,10 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
200
  - !ruby/object:Gem::Version
127
201
  version: '0'
128
202
  requirements: []
129
- rubygems_version: 3.1.6
203
+ rubygems_version: 3.3.7
130
204
  signing_key:
131
205
  specification_version: 4
132
206
  summary: Advanced ActiveModel email validation
133
- test_files:
134
- - spec/email_assessor_spec.rb
135
- - spec/spec_helper.rb
207
+ test_files: []
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- .DS_STORE
2
- *.gem
3
- *.rbc
4
- .bundle
5
- .config
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
-
3
- sudo: false
4
-
5
- rvm:
6
- - 2.4.0
7
-
8
- gemfile:
9
- - gemfiles/activemodel4.gemfile
data/CHANGELOG.md DELETED
@@ -1,9 +0,0 @@
1
- ## Version 0.3.8 (November 8th, 2016)
2
- - Add more disposable domains
3
-
4
- ## Version 0.3
5
- - Refactored the logic in `EmailAssessor.domain_in_file?` to be simpler
6
- - Removed configurability in favor of convention over configuration
7
-
8
- ## Version 0.1
9
- Gave this fork its very own name: EmailAssessor
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in email_assessor.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright for portions of this project are held by Micke Lisinge, 2013, as part of valid_email2. All other copyright are held by Michael Wolfe Millard, 2016.
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.
data/README.md DELETED
@@ -1,132 +0,0 @@
1
- # EmailAssessor
2
- [![Build Status](https://travis-ci.org/wolfemm/email_assessor.png?branch=master)](https://travis-ci.org/wolfemm/email_assessor)
3
- [![Gem Version](https://badge.fury.io/rb/email_assessor.png)](http://badge.fury.io/rb/email_assessor)
4
-
5
- A fork of [Micke Lisinge](https://github.com/lisinge)'s [ValidEmail2](https://github.com/lisinge/valid_email2).
6
-
7
- ValidEmail2:
8
-
9
- * Validates emails with the help of the `mail` gem instead of some clunky regexp.
10
- * Aditionally validates that the domain has a MX record.
11
- * Optionally validates against a static [list of disposable email services](vendor/disposable_domains.txt).
12
-
13
-
14
- ### Why?
15
-
16
- ValidEmail2 offers very comprehensive email validation, but it has a few pitfalls.
17
-
18
- For starters, it loads the entire list of blacklisted/disposable email domains into memory from a YAML file. In a never ending battle against spam, loading such an extremely large (and ever-growing) array into memory is far from ideal. Instead, EmailAssessor reads a text file line-by-line.
19
-
20
- Another pitfall is that subdomains are able to bypass the disposable and blacklist checks in ValidEmail2. EmailAssessor checks if a given domain *ends* with a blacklisted/disposable domain, preventing subdomains from masking an email that would otherwise be considered invalid.
21
-
22
-
23
- ## Installation
24
-
25
- Add this line to your application's Gemfile:
26
-
27
- ```ruby
28
- gem "email_assessor"
29
- ```
30
-
31
- And then execute:
32
-
33
- $ bundle
34
-
35
- Or install it yourself as:
36
-
37
- $ gem install email_assessor
38
-
39
- ## Domain List Files
40
-
41
- Domain list files, used for blacklisting and blocking disposable emails, are plain-text files with one **lower case** domain per line.
42
-
43
- Valid domain list file:
44
- ```
45
- example.com
46
- subdomain.example.org
47
- ```
48
-
49
- Invalid domain list file:
50
- ```
51
- http://example.com
52
- example.com/mail
53
- ```
54
-
55
- Be careful with subdomains. Given the following domain list file:
56
-
57
- ```
58
- sub.example.com
59
- ```
60
-
61
- A user would be able to register with the email `jake@example.com` but not `tom@sub.example.com` or `jerry@deep.sub.example.com`.
62
-
63
- ## Usage
64
-
65
- ### Use with ActiveModel
66
-
67
- If you just want to validate that it is a valid email address:
68
- ```ruby
69
- class User < ActiveRecord::Base
70
- validates :email, presence: true, email: true
71
- end
72
- ```
73
-
74
- To validate that the domain has a MX record:
75
- ```ruby
76
- validates :email, email: { mx: true }
77
- ```
78
-
79
- To validate that the domain is not a disposable email:
80
- ```ruby
81
- validates :email, email: { disposable: true }
82
- ```
83
-
84
- To validate that the domain is not blacklisted (via `vendor/blacklisted_domains.txt`):
85
- ```ruby
86
- validates :email, email: { blacklist: true }
87
- ```
88
-
89
- All together:
90
- ```ruby
91
- validates :email, email: { mx: true, disposable: true, blacklist: true }
92
- ```
93
-
94
- > Note that this gem will let an empty email pass through so you will need to
95
- > add `presence: true` if you require an email
96
-
97
- ### Use without ActiveModel
98
-
99
- ```ruby
100
- address = EmailAssessor::Address.new("lisinge@gmail.com")
101
- address.valid? => true
102
- address.disposable? => false
103
- address.valid_mx? => true
104
- ```
105
-
106
- ### Test environment
107
-
108
- If you are validating `mx` then your specs will fail without an internet connection.
109
- It is a good idea to stub out that validation in your test environment.
110
- Do so by adding this in your `spec_helper`:
111
- ```ruby
112
- config.before(:each) do
113
- allow_any_instance_of(EmailAssessor::Address).to receive(:valid_mx?) { true }
114
- end
115
- ```
116
-
117
- ## Requirements
118
-
119
- This gem requires Rails 3.2 or 4.0. It is tested against both versions using:
120
- * Ruby-1.9
121
- * Ruby-2.0
122
- * Ruby-2.1
123
- * Ruby-2.2
124
- * JRuby-1.9
125
-
126
- ## Contributing
127
-
128
- 1. Fork it
129
- 2. Create your feature branch (`git checkout -b my-new-feature`)
130
- 3. Commit your changes (`git commit -am 'Add some feature'`)
131
- 4. Push to the branch (`git push origin my-new-feature`)
132
- 5. Create new Pull Request
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- desc "Run specs"
5
- RSpec::Core::RakeTask.new do |t|
6
- t.pattern = "spec/**/*_spec.rb"
7
- end
8
-
9
- task :default => [:spec]
10
- task :build => [:spec]
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
- # encoding: UTF-8
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "email_assessor/version"
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = "email_assessor"
9
- spec.version = EmailAssessor::VERSION
10
- spec.summary = "Advanced ActiveModel email validation"
11
- spec.description = "Advanced ActiveModel email validation with MX lookups, domain blacklisting and disposable email blocking"
12
-
13
- spec.license = "MIT"
14
-
15
- spec.author = "Michael Wolfe Millard"
16
- spec.email = "wolfemm.development@gmail.com"
17
- spec.homepage = "https://github.com/wolfemm/email_assessor"
18
-
19
- spec.files = `git ls-files`.split($/)
20
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
- spec.require_paths = ["lib"]
23
-
24
- spec.required_ruby_version = ">= 2.4.0"
25
-
26
- spec.add_development_dependency "bundler", "~> 2.0"
27
- spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec", "~> 3.4"
29
- spec.add_runtime_dependency "mail", "~> 2.5"
30
- spec.add_runtime_dependency "activemodel", ">= 5.0.2"
31
- end
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activemodel", "~> 5.0.2"
4
-
5
- gemspec path: "../"
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "yaml"
5
-
6
- require "json"
7
- require "net/http"
8
- require "set"
9
-
10
- whitelisted_domains = %w(poczta.onet.pl fastmail.fm hushmail.com naver.com qq.com nus.edu.sg)
11
-
12
- existing_domains = File.readlines("vendor/disposable_domains.txt")
13
-
14
- url = "https://raw.githubusercontent.com/FGRibreau/mailchecker/master/list.txt"
15
- resp = Net::HTTP.get_response(URI.parse(url))
16
-
17
- remote_domains = (resp.body.split("\n")) - whitelisted_domains
18
-
19
- result_domains = SortedSet.new((existing_domains + remote_domains).map! { |domain| domain.strip.downcase })
20
-
21
- File.open("vendor/disposable_domains.txt", "w") { |f| f.write result_domains.to_a.join("\n") }
@@ -1,209 +0,0 @@
1
- # frozen_string_literal: true
2
- require "spec_helper"
3
-
4
- class TestUser < TestModel
5
- validates :email, email: true
6
- end
7
-
8
- class TestUserMX < TestModel
9
- validates :email, email: { mx: true }
10
- end
11
-
12
- class TestUserDisallowDisposable < TestModel
13
- validates :email, email: { disposable: true }
14
- end
15
-
16
- class TestUserDisallowBlacklisted < TestModel
17
- validates :email, email: { blacklist: true }
18
- end
19
-
20
- class TestUserDisallowEducational < TestModel
21
- validates :email, email: { educational: :no_educational }
22
- end
23
-
24
- describe EmailAssessor do
25
- let(:plain_user) { TestUser.new(email: "") }
26
- let(:disposable_user) { TestUserDisallowDisposable.new(email: "foo@gmail.com") }
27
- let(:blacklist_user) { TestUserDisallowBlacklisted.new(email: "foo@gmail.com") }
28
- let(:educational_user) { TestUserDisallowEducational.new(email: "foo@gmail.com") }
29
- let(:mx_user) { TestUserMX.new(email: "foo@gmail.com") }
30
-
31
- let(:blacklisted_domains_file_name) { described_class::BLACKLISTED_DOMAINS_FILE_NAME }
32
- let(:blacklisted_domain) { File.open(blacklisted_domains_file_name, &:readline).chomp }
33
-
34
- let(:disposable_domains_file_name) { described_class::DISPOSABLE_DOMAINS_FILE_NAME }
35
- let(:disposable_domain) { File.open(disposable_domains_file_name, &:readline).chomp }
36
-
37
- let(:educational_domains_file_name) { described_class::EDUCATIONAL_DOMAINS_FILE_NAME }
38
- let(:educational_domain) { File.open(educational_domains_file_name, &:readline).chomp }
39
-
40
- describe "basic validation" do
41
- subject(:user) { plain_user }
42
-
43
- it "is valid when email is empty" do
44
- is_expected.to be_valid
45
- end
46
-
47
- it "is invalid if the address starts with a dot" do
48
- user = TestUser.new(email: ".foo@bar.com")
49
- expect(user.valid?).to be_falsey
50
- end
51
-
52
- it "is invalid if the address contains consecutive dots" do
53
- user = TestUser.new(email: "foo..bar@gmail.com")
54
- expect(user.valid?).to be_falsey
55
- end
56
-
57
- it "is invalid if the address ends with a dot" do
58
- user = TestUser.new(email: "foo.@bar.com")
59
- expect(user.valid?).to be_falsey
60
- end
61
-
62
- it "is invalid when domain is missing" do
63
- user.email = "foo@.com"
64
- is_expected.to be_invalid
65
- end
66
-
67
- it "is invalid when domain starts with a dot" do
68
- user.email = "foo@.example.com"
69
- is_expected.to be_invalid
70
- end
71
-
72
- it "is invalid when email is malformed" do
73
- user.email = "foo@bar"
74
- is_expected.to be_invalid
75
- end
76
-
77
- it "is invalid when email contains a trailing symbol" do
78
- user.email = "foo@bar.com/"
79
- is_expected.to be_invalid
80
- end
81
-
82
- it "is invalid if Mail::AddressListsParser raises exception" do
83
- allow(Mail::Address).to receive(:new).and_raise(Mail::Field::ParseError.new(nil, nil, nil))
84
- user.email = "foo@gmail.com"
85
- is_expected.to be_invalid
86
- end
87
-
88
- it "is invalid if the domain constains consecutives dots" do
89
- user.email = "foo@bar..com"
90
- is_expected.to be_invalid
91
- end
92
-
93
- it "is invalid if the domain contains emoticons" do
94
- user.email = "foo🙈@gmail.com"
95
- is_expected.to be_invalid
96
- end
97
-
98
- it "is invalid if the domain contains spaces" do
99
- user.email = "user@gmail .com"
100
- is_expected.to be_invalid
101
- end
102
-
103
- it "is invalid if the domain contains '.@'" do
104
- user.email = "foo.@gmail.com"
105
- expect(user.valid?).to be_falsy
106
- end
107
-
108
- it "is invalid if the domain begins with a hyphen" do
109
- user.email = "foo@-gmail.com"
110
- expect(user.valid?).to be_falsy
111
- end
112
-
113
- it "is invalid if the domain name ends with a hyphen" do
114
- user.email = "foo@gmail-.com"
115
- expect(user.valid?).to be_falsy
116
- end
117
-
118
- %w[+ _ ! / \ '].each do |invalid_character|
119
- it "is invalid if domain contains a \"#{invalid_character}\" character" do
120
- user.email = "foo@google#{invalid_character}yahoo.com"
121
- is_expected.to be_invalid
122
- end
123
- end
124
- end
125
-
126
- describe "disposable domains" do
127
- subject(:user) { disposable_user }
128
-
129
- it "is valid when email is not in the list of disposable domains" do
130
- is_expected.to be_valid
131
- end
132
-
133
- it "is invalid when email is in the list of disposable domains" do
134
- user.email = "foo@#{disposable_domain}"
135
- is_expected.to be_invalid
136
- end
137
-
138
- it "is invalid when email is in the list of disposable domains regardless of case" do
139
- user.email = "foo@#{disposable_domain.upcase}"
140
- is_expected.to be_invalid
141
- end
142
-
143
- it "is invalid when email is in the list of disposable domains regardless of subdomain" do
144
- user.email = "foo@abc123.#{disposable_domain}"
145
- is_expected.to be_invalid
146
- end
147
- end
148
-
149
- describe "blacklisted domains" do
150
- subject(:user) { blacklist_user }
151
-
152
- it "is valid when email domain is not in the blacklist" do
153
- is_expected.to be_valid
154
- end
155
-
156
- it "is invalid when email domain is in the blacklist" do
157
- user.email = "foo@#{blacklisted_domain}"
158
- is_expected.to be_invalid
159
- end
160
-
161
- it "is invalid when email is in the blacklist regardless of case" do
162
- user.email = "foo@#{blacklisted_domain.upcase}"
163
- is_expected.to be_invalid
164
- end
165
-
166
- it "is invalid when email domain is in the blacklist regardless of subdomain" do
167
- user.email = "foo@abc123.#{blacklisted_domain}"
168
- is_expected.to be_invalid
169
- end
170
- end
171
-
172
- describe "educational domains" do
173
- subject(:user) { educational_user }
174
-
175
- it "is valid when email domain is not in the educational blocklist" do
176
- is_expected.to be_valid
177
- end
178
-
179
- it "is invalid when email domain is in the educational blocklist" do
180
- user.email = "foo@#{educational_domain}"
181
- is_expected.to be_invalid
182
- end
183
-
184
- it "is invalid when email is in the educational blocklist regardless of case" do
185
- user.email = "foo@#{educational_domain.upcase}"
186
- is_expected.to be_invalid
187
- end
188
-
189
- it "is invalid when email domain is in the educational blocklist regardless of subdomain" do
190
- user.email = "foo@abc123.#{educational_domain}"
191
- is_expected.to be_invalid
192
- expect(user.errors.added?(:email, :no_educational)).to be_truthy
193
- end
194
- end
195
-
196
-
197
- describe "mx lookup" do
198
- subject(:user) { mx_user }
199
-
200
- it "is valid if mx records are found" do
201
- is_expected.to be_valid
202
- end
203
-
204
- it "is invalid if no mx records are found" do
205
- user.email = "foo@subdomain.gmail.com"
206
- is_expected.to be_invalid
207
- end
208
- end
209
- end
data/spec/spec_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
- $:.unshift File.expand_path("../lib",__FILE__)
3
- require "email_assessor"
4
-
5
- class TestModel
6
- include ActiveModel::Validations
7
-
8
- def initialize(attributes = {})
9
- @attributes = attributes
10
- end
11
-
12
- def email=(email)
13
- @attributes[:email] = email
14
- end
15
-
16
- def read_attribute_for_validation(key)
17
- @attributes[key]
18
- end
19
- end