-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from keiko713/whitelist
Add feature to whitelist disposable domains with vendor/whitelist.yml
- Loading branch information
Showing
5 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,10 @@ class TestUserDisallowDisposable < TestModel | |
validates :email, 'valid_email_2/email': { disposable: true } | ||
end | ||
|
||
class TestUserDisallowDisposableWithWhitelist < TestModel | ||
validates :email, 'valid_email_2/email': { disposable_with_whitelist: true } | ||
end | ||
|
||
class TestUserDisallowBlacklisted < TestModel | ||
validates :email, 'valid_email_2/email': { blacklist: true } | ||
end | ||
|
@@ -82,6 +86,22 @@ class TestUserDisallowBlacklisted < TestModel | |
user = TestUserDisallowDisposable.new(email: "[email protected]") | ||
expect(user.valid?).to be_truthy | ||
end | ||
|
||
describe "with whitelisted emails" do | ||
it "should be invalid when the domain is in the list of disposable and there is no whitelist" do | ||
user = TestUserDisallowDisposableWithWhitelist.new(email: "foo@#{ValidEmail2.disposable_emails.first}") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "should be valid when the domain is in the list of disposable but it is in the whitelist" do | ||
whitelist_domain = ValidEmail2.disposable_emails.first | ||
whitelist_file_path = "vendor/whitelist.yml" | ||
File.open(whitelist_file_path, "w") {|f| f.write whitelist_domain.to_yaml } | ||
user = TestUserDisallowDisposableWithWhitelist.new(email: "foo@#{whitelist_domain}") | ||
expect(user.valid?).to be_falsey | ||
File.delete(whitelist_file_path) | ||
end | ||
end | ||
end | ||
|
||
describe "blacklisted emails" do | ||
|