-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/domain whitelist blacklist (#43)
* Error key in lower_snake_case * Add whitelist, blacklist check * Update reek config * Rename Skip to DomainListMatch * Add Configuration#validation_type_for= argument type validation * Add attr_accessors Configuration#whitelisted_domains, Configuration#blacklisted_domains * Update shared examples * Update core, Validator#run tests * Add DomainListMatch tests * Update Gemfile * Update gem version * Update readme
- Loading branch information
Showing
17 changed files
with
206 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
truemail (0.2.0) | ||
truemail (1.0.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
|
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ The Truemail gem helps you validate emails by regex pattern, presence of domain | |
|
||
- Configurable validator, validate only what you need | ||
- Zero runtime dependencies | ||
- Has whitelist/blacklist | ||
- Has simple SMTP debugger | ||
- 100% test coverage | ||
|
||
|
@@ -74,10 +75,18 @@ Truemail.configure do |config| | |
config.connection_attempts = 3 | ||
|
||
# Optional parameter. You can predefine which type of validation will be used for domains. | ||
# Also you can skip validation by domain. Available validation types: :regex, :mx, :smtp, :skip | ||
# Also you can skip validation by domain. Available validation types: :regex, :mx, :smtp | ||
# This configuration will be used over current or default validation type parameter | ||
# All of validations for 'somedomain.com' will be processed with mx validation only | ||
config.validation_type_for = { 'somedomain.com' => :mx, 'otherdomain.com' => :skip } | ||
config.validation_type_for = { 'somedomain.com' => :regex, 'otherdomain.com' => :mx } | ||
|
||
# Optional parameter. Validation of email which contains whitelisted domain always will | ||
# return true. Other validations will not processed even if it was defined in validation_type_for | ||
config.whitelisted_domains = ['somedomain1.com', 'somedomain2.com'] | ||
|
||
# Optional parameter. Validation of email which contains whitelisted domain always will | ||
# return false. Other validations will not processed even if it was defined in validation_type_for | ||
config.blacklisted_domains = ['somedomain1.com', 'somedomain2.com'] | ||
|
||
# Optional parameter. This option will be parse bodies of SMTP errors. It will be helpful | ||
# if SMTP server does not return an exact answer that the email does not exist | ||
|
@@ -100,6 +109,8 @@ Truemail.configuration | |
@response_timeout=1, | ||
@connection_attempts=3, | ||
@validation_type_by_domain={}, | ||
@whitelisted_domains=[], | ||
@blacklisted_domains=[], | ||
@verifier_domain="somedomain.com", | ||
@verifier_email="[email protected]" | ||
@smtp_safe_check=true> | ||
|
@@ -123,6 +134,8 @@ Truemail.configuration | |
@response_timeout=4, | ||
@connection_attempts=1, | ||
@validation_type_by_domain={}, | ||
@whitelisted_domains=[], | ||
@blacklisted_domains=[], | ||
@verifier_domain="somedomain.com", | ||
@verifier_email="[email protected]", | ||
@smtp_safe_check=true> | ||
|
@@ -281,6 +294,8 @@ Truemail.validate('[email protected]') | |
@connection_attempts=2, | ||
@smtp_safe_check=false, | ||
@validation_type_by_domain={}, | ||
@whitelisted_domains=[], | ||
@blacklisted_domains=[], | ||
@verifier_domain="example.com", | ||
@verifier_email="[email protected]">, | ||
@email="[email protected]", | ||
|
@@ -335,6 +350,8 @@ Truemail.validate('[email protected]') | |
@connection_attempts=2, | ||
@smtp_safe_check=true, | ||
@validation_type_by_domain={}, | ||
@whitelisted_domains=[], | ||
@blacklisted_domains=[], | ||
@verifier_domain="example.com", | ||
@verifier_email="[email protected]">, | ||
@email="[email protected]", | ||
|
@@ -373,6 +390,8 @@ Truemail.validate('[email protected]') | |
@connection_attempts=2, | ||
@smtp_safe_check=true, | ||
@validation_type_by_domain={}, | ||
@whitelisted_domains=[], | ||
@blacklisted_domains=[], | ||
@verifier_domain="example.com", | ||
@verifier_email="[email protected]">, | ||
@email="[email protected]", | ||
|
@@ -447,8 +466,7 @@ end | |
--- | ||
## ToDo | ||
|
||
1. Gem compatibility with Ruby 2.3 | ||
2. Fail validations logger | ||
Fail validations logger | ||
|
||
## Contributing | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
module Validate | ||
class DomainListMatch < Truemail::Validate::Base | ||
ERROR = 'blacklisted email' | ||
|
||
def run | ||
return success(true) if whitelisted_domain? | ||
return unless blacklisted_domain? | ||
success(false) | ||
add_error(Truemail::Validate::DomainListMatch::ERROR) | ||
end | ||
|
||
private | ||
|
||
def email_domain | ||
@email_domain ||= result.email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1] | ||
end | ||
|
||
def whitelisted_domain? | ||
configuration.whitelisted_domains.include?(email_domain) | ||
end | ||
|
||
def blacklisted_domain? | ||
configuration.blacklisted_domains.include?(email_domain) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
VERSION = '0.2.0' | ||
VERSION = '1.0.0' | ||
end |
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
Oops, something went wrong.