Skip to content

Commit

Permalink
Le shadow master (#139)
Browse files Browse the repository at this point in the history
* Compatibility with RFC 2181

According to RFC2181, every DNS query needs to have a . at the end of
the name record you are requesting.

This will show that that name record is the root of the domain you are
asking
In some cases, when the . is missing, the hostname of the server the
code is running on will be appended to the name record when
checkdnsrr() is being executed and this will in turn return a false
positive when there is a wildcard DNS record for the root domain of the
hostname of the server.

* Test deprecation warnings removed
  • Loading branch information
egulias authored Jan 30, 2017
1 parent c0c888a commit bc31baa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
report/
vendor/
.idea
2 changes: 2 additions & 0 deletions EmailValidator/Validation/DNSCheckValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function getWarnings()

protected function checkDNS($host)
{
$host = rtrim($host, '.') . '.';

$Aresult = true;
$MXresult = checkdnsrr($host, 'MX');

Expand Down
4 changes: 2 additions & 2 deletions Tests/EmailValidator/EmailValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
public function testValidationIsUsed()
{
$validator = new EmailValidator();
$validation = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation->expects($this->once())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]);
$validation->expects($this->once())->method("getError")->willReturn(null);
Expand All @@ -21,7 +21,7 @@ public function testValidationIsUsed()
public function testMultipleValidation()
{
$validator = new EmailValidator();
$validation = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation->expects($this->once())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]);
$validation->expects($this->once())->method("getError")->willReturn(null);
Expand Down
29 changes: 15 additions & 14 deletions Tests/EmailValidator/Validation/MultipleValidationWitAndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class MultipleValidationWitAndTest extends \PHPUnit_Framework_TestCase
{
public function testUsesAndLogicalOperation()
{
$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$validationTrue = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
$validationTrue = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validationTrue->expects($this->any())->method("isValid")->willReturn(true);
$validationTrue->expects($this->any())->method("getWarnings")->willReturn([]);
$validationFalse = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validationFalse = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validationFalse->expects($this->any())->method("isValid")->willReturn(false);
$validationFalse->expects($this->any())->method("getWarnings")->willReturn([]);
$multipleValidation = new MultipleValidationWithAnd([$validationTrue, $validationFalse]);
Expand All @@ -34,9 +34,9 @@ public function testEmptyListIsNotAllowed()

public function testValidationIsValid()
{
$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();

$validation = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation->expects($this->any())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]);

Expand All @@ -55,12 +55,13 @@ public function testAccumulatesWarnings()
];
$expectedResult = array_merge($warnings1, $warnings2);

$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$validation1 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(true);
$validation1->expects($this->once())->method("getWarnings")->willReturn($warnings1);

$validation2 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();

$validation2->expects($this->any())->method("isValid")->willReturn(false);
$validation2->expects($this->once())->method("getWarnings")->willReturn($warnings2);

Expand All @@ -76,14 +77,14 @@ public function testGathersAllTheErrors()

$expectedResult = new MultipleErrors([$error1, $error2]);

$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();

$validation1 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(true);
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
$validation1->expects($this->once())->method("getError")->willReturn($error1);

$validation2 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation2->expects($this->any())->method("isValid")->willReturn(false);
$validation2->expects($this->once())->method("getWarnings")->willReturn([]);
$validation2->expects($this->once())->method("getError")->willReturn($error2);
Expand All @@ -99,14 +100,14 @@ public function testBreakOutOfLoopWhenError()

$expectedResult = new MultipleErrors([$error]);

$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();

$validation1 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(false);
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
$validation1->expects($this->once())->method("getError")->willReturn($error);

$validation2 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation2->expects($this->never())->method("isValid");
$validation2->expects($this->never())->method("getWarnings");
$validation2->expects($this->never())->method("getError");
Expand Down

0 comments on commit bc31baa

Please sign in to comment.