valid_email2 2.2.3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25558db10878c68df0f39fbcdfe498f8d07d8c70730b268e2ef702e4f8533449
4
- data.tar.gz: e1834303a708a8ed08821bf3d1e5e5539b9fe200450f174ab5cfc33530868779
3
+ metadata.gz: c276bf084cb4c9815f285bea9a4e3074ef7e6f60751517e006421d4dff33d21d
4
+ data.tar.gz: 950da4a70ea385e7acab48193168a91874acd54520f295cba9c8d28f7fa3d875
5
5
  SHA512:
6
- metadata.gz: 3ec00e12a9f657e1ef25e5caed08d893f20036b35b02f8a8b8d69c694377e5ab6c5255345ff68dec61e4ab1e5f78fdb6a5f931255837cba43173055adabe79e0
7
- data.tar.gz: 3f3b6508a61121802b957e3a31d3032d2eab37776dda9586bf4dd43d3a9d21207b4c952b4c0dbbe0b63b1f1c19959b445472b2e89003f8e1ef54a2129b52380c
6
+ metadata.gz: bfd46b264bd9ded9820c279a62e02fb61bada67a7d62555a80cf094e6abd6d94d488f754a7837a67103476cfad3fd82f5f6443e49b9cdb29b1864a04fb381910
7
+ data.tar.gz: f31d60651d05f90e7ce63f8f2feab0f24eb37752dca65e63b29bd9d14782779b5ee6b824e77de12c590da6aa118aa73536ff4cdcad9be062576818ef9d99af86
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## Version 2.3.0
2
+ Add whitelist feature (https://github.com/lisinge/valid_email2/pull/119)
3
+ Update disposable emails (https://github.com/lisinge/valid_email2/pull/116)
4
+
1
5
  ## Version 2.2.3
2
6
  Update disposable emails #113
3
7
  Remove false positives (yandex.com, naver.com, com.ar)
data/README.md CHANGED
@@ -53,6 +53,11 @@ To validate that the domain is not a disposable email:
53
53
  validates :email, 'valid_email_2/email': { disposable: true }
54
54
  ```
55
55
 
56
+ To validate that the domain is not a disposable email or a disposable email but whitelisted (under vendor/whitelist.yml):
57
+ ```ruby
58
+ validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
59
+ ```
60
+
56
61
  To validate that the domain is not blacklisted (under vendor/blacklist.yml):
57
62
  ```ruby
58
63
  validates :email, 'valid_email_2/email': { blacklist: true }
@@ -48,6 +48,10 @@ module ValidEmail2
48
48
  valid? && domain_is_in?(ValidEmail2.disposable_emails)
49
49
  end
50
50
 
51
+ def whitelisted?
52
+ domain_is_in?(ValidEmail2.whitelist)
53
+ end
54
+
51
55
  def blacklisted?
52
56
  valid? && domain_is_in?(ValidEmail2.blacklist)
53
57
  end
@@ -24,6 +24,10 @@ module ValidEmail2
24
24
  error(record, attribute) && return if address.disposable?
25
25
  end
26
26
 
27
+ if options[:disposable_with_whitelist]
28
+ error(record, attribute) && return if address.disposable? && !address.whitelisted?
29
+ end
30
+
27
31
  if options[:blacklist]
28
32
  error(record, attribute) && return if address.blacklisted?
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module ValidEmail2
2
- VERSION = "2.2.3"
2
+ VERSION = "2.3.0"
3
3
  end
data/lib/valid_email2.rb CHANGED
@@ -9,4 +9,9 @@ module ValidEmail2
9
9
  blacklist_file = "vendor/blacklist.yml"
10
10
  @@blacklist ||= File.exists?(blacklist_file) ? YAML.load_file(File.expand_path(blacklist_file)) : []
11
11
  end
12
+
13
+ def self.whitelist
14
+ whitelist_file = "vendor/whitelist.yml"
15
+ @@whitelist ||= File.exists?(whitelist_file) ? YAML.load_file(File.expand_path(whitelist_file)) : []
16
+ end
12
17
  end
@@ -16,6 +16,10 @@ class TestUserDisallowDisposable < TestModel
16
16
  validates :email, 'valid_email_2/email': { disposable: true }
17
17
  end
18
18
 
19
+ class TestUserDisallowDisposableWithWhitelist < TestModel
20
+ validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
21
+ end
22
+
19
23
  class TestUserDisallowBlacklisted < TestModel
20
24
  validates :email, 'valid_email_2/email': { blacklist: true }
21
25
  end
@@ -82,6 +86,22 @@ describe ValidEmail2 do
82
86
  user = TestUserDisallowDisposable.new(email: "foo@example.com")
83
87
  expect(user.valid?).to be_truthy
84
88
  end
89
+
90
+ describe "with whitelisted emails" do
91
+ it "should be invalid when the domain is in the list of disposable and there is no whitelist" do
92
+ user = TestUserDisallowDisposableWithWhitelist.new(email: "foo@#{ValidEmail2.disposable_emails.first}")
93
+ expect(user.valid?).to be_falsey
94
+ end
95
+
96
+ it "should be valid when the domain is in the list of disposable but it is in the whitelist" do
97
+ whitelist_domain = ValidEmail2.disposable_emails.first
98
+ whitelist_file_path = "vendor/whitelist.yml"
99
+ File.open(whitelist_file_path, "w") {|f| f.write whitelist_domain.to_yaml }
100
+ user = TestUserDisallowDisposableWithWhitelist.new(email: "foo@#{whitelist_domain}")
101
+ expect(user.valid?).to be_falsey
102
+ File.delete(whitelist_file_path)
103
+ end
104
+ end
85
105
  end
86
106
 
87
107
  describe "blacklisted emails" do
@@ -3576,6 +3576,7 @@
3576
3576
  - nutpa.net
3577
3577
  - nuts2trade.com
3578
3578
  - nwldx.com
3579
+ - nwytg.com
3579
3580
  - ny7.me
3580
3581
  - nypato.com
3581
3582
  - o.cfo2go.ro
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid_email2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micke Lisinge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-14 00:00:00.000000000 Z
11
+ date: 2018-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.7.3
131
+ rubygems_version: 2.7.6
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: ActiveModel validation for email. Including MX lookup and disposable email