-
Notifications
You must be signed in to change notification settings - Fork 107
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 #230 from InfuseGroup/add-dns-nameserver-option
Add `dns_nameserver` option for mx checking
- Loading branch information
Showing
4 changed files
with
120 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,22 @@ class TestUserStrictMX < TestModel | |
validates :email, 'valid_email_2/email': { strict_mx: true } | ||
end | ||
|
||
class TestUserMXDnsTimeout < TestModel | ||
validates :email, 'valid_email_2/email': { mx: true, dns_timeout: 10 } | ||
end | ||
|
||
class TestUserMXDnsFailingTimeout < TestModel | ||
validates :email, 'valid_email_2/email': { mx: true, dns_timeout: Float::MIN } | ||
end | ||
|
||
class TestUserMXDnsNameserver < TestModel | ||
validates :email, 'valid_email_2/email': { mx: true, dns_nameserver: ['8.8.8.8', '8.8.4.4'] } | ||
end | ||
|
||
class TestUserMXDnsFailingNameserver < TestModel | ||
validates :email, 'valid_email_2/email': { mx: true, dns_timeout: 0.1, dns_nameserver: '1.0.0.0' } | ||
end | ||
|
||
class TestUserDisallowDisposable < TestModel | ||
validates :email, 'valid_email_2/email': { disposable: true } | ||
end | ||
|
@@ -292,6 +308,94 @@ def set_whitelist | |
end | ||
end | ||
|
||
describe "with mx validation and dns not hitting timeout" do | ||
it "is valid if mx records are found" do | ||
user = TestUserMXDnsTimeout.new(email: "[email protected]") | ||
expect(user.valid?).to be_truthy | ||
end | ||
|
||
it "is valid if A records are found" do | ||
user = TestUserMXDnsTimeout.new(email: "[email protected]") | ||
expect(user.valid?).to be_truthy | ||
end | ||
|
||
it "is invalid if no mx records are found" do | ||
user = TestUserMXDnsTimeout.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "is invalid if a null mx is found" do | ||
user = TestUserMXDnsTimeout.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
end | ||
|
||
describe "with mx validation and dns hitting timeout" do | ||
it "is never valid even if mx records exist" do | ||
user = TestUserMXDnsFailingTimeout.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "is never valid even A records exist" do | ||
user = TestUserMXDnsFailingTimeout.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "is invalid if no mx records exist" do | ||
user = TestUserMXDnsFailingTimeout.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "is invalid if a null mx exists" do | ||
user = TestUserMXDnsFailingTimeout.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
end | ||
|
||
describe "with mx validation and dns nameserver" do | ||
it "is valid if mx records are found" do | ||
user = TestUserMXDnsNameserver.new(email: "[email protected]") | ||
expect(user.valid?).to be_truthy | ||
end | ||
|
||
it "is valid if A records are found" do | ||
user = TestUserMXDnsNameserver.new(email: "[email protected]") | ||
expect(user.valid?).to be_truthy | ||
end | ||
|
||
it "is invalid if no mx records are found" do | ||
user = TestUserMXDnsNameserver.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "is invalid if a null mx is found" do | ||
user = TestUserMXDnsNameserver.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
end | ||
|
||
describe "with mx validation and failing dns nameserver" do | ||
it "is never valid even if mx records exist" do | ||
user = TestUserMXDnsFailingNameserver.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "is never valid even A records exist" do | ||
user = TestUserMXDnsFailingNameserver.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "is invalid if no mx records exist" do | ||
user = TestUserMXDnsFailingNameserver.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
|
||
it "is invalid if a null mx exists" do | ||
user = TestUserMXDnsFailingNameserver.new(email: "[email protected]") | ||
expect(user.valid?).to be_falsey | ||
end | ||
end | ||
|
||
describe "with dotted validation" do | ||
it "is valid when address does not contain dots" do | ||
user = TestUserDotted.new(email: "[email protected]") | ||
|