Skip to content

Commit

Permalink
Fix #2 by checking for TLD during NXDOMAIN error
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelherold committed Jun 24, 2014
1 parent dfef594 commit 84d2581
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pyisemail/validators/dns_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def is_valid(self, domain, diagnose=False):
except (dns.resolver.NXDOMAIN, dns.name.NameTooLong):
# Domain can't be found in DNS
return_status.append(DNSDiagnosis('NO_RECORD'))

# Since dns.resolver gives more information than the PHP analog, we
# can say that TLDs that throw an NXDOMAIN or NameTooLong error
# have been checked
if len(domain.split('.')) == 1:
dns_checked = True
except dns.resolver.NoAnswer:
# MX-record for domain can't be found
return_status.append(DNSDiagnosis('NO_MX_RECORD'))
Expand Down
21 changes: 19 additions & 2 deletions tests/data/dns-tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@
</test>
<test id="167">
<address>test@test.com</address>
<comment>test.com has an A-record but not an MX-record</comment>
<comment>When the test suite was originally constructed, test.com had an A-record but not an MX-record. However, now (June 2014) test.com has started to respond with an MX-record as well. The test has since been marked flaky.</comment>
<category>ISEMAIL_DNSWARN</category>
<diagnosis>ISEMAIL_DNSWARN_NO_MX_RECORD</diagnosis>
<source>Dominic Sayers</source>
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink>
<flaky>True</flaky>
</test>
<test id="168">
<address>test@nic.no</address>
Expand All @@ -88,4 +89,20 @@
<source>Michael Herold</source>
<sourcelink>http://github.com/michaelherold/pyIsEmail</sourcelink>
</test>
</tests>
<test id="170">
<address>08.00.27.d1.8c.d2@virtualbox</address>
<comment>This example was not giving the correct diagnosis, as it was falling back to an RFC5321 TLD diagnosis.</comment>
<category>ISEMAIL_DNSWARN</category>
<diagnosis>ISEMAIL_DNSWARN_NO_RECORD</diagnosis>
<source>Nguyễn Hồng Quân</source>
<sourcelink>https://github.com/michaelherold/pyIsEmail/issues/2</sourcelink>
</test>
<test id="171">
<address>test@example.com</address>
<comment>example.com has an A-record but not an MX-record</comment>
<category>ISEMAIL_DNSWARN</category>
<diagnosis>ISEMAIL_DNSWARN_NO_MX_RECORD</diagnosis>
<source>Michael Herold</source>
<sourcelink>http://github.com/michaelherold/pyIsEmail</sourcelink>
</test>
</tests>
1 change: 1 addition & 0 deletions tests/validators/test_dns_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DNSValidatorFlakyTest(TestWithScenarios):

scenarios = get_scenarios("dns-tests.xml", flaky=True)

@expectedFailure
def test_without_diagnosis(self):

v = DNSValidator()
Expand Down

0 comments on commit 84d2581

Please sign in to comment.