Skip to content

Commit 84d2581

Browse files
committed
Fix #2 by checking for TLD during NXDOMAIN error
1 parent dfef594 commit 84d2581

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

pyisemail/validators/dns_validator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def is_valid(self, domain, diagnose=False):
4141
except (dns.resolver.NXDOMAIN, dns.name.NameTooLong):
4242
# Domain can't be found in DNS
4343
return_status.append(DNSDiagnosis('NO_RECORD'))
44+
45+
# Since dns.resolver gives more information than the PHP analog, we
46+
# can say that TLDs that throw an NXDOMAIN or NameTooLong error
47+
# have been checked
48+
if len(domain.split('.')) == 1:
49+
dns_checked = True
4450
except dns.resolver.NoAnswer:
4551
# MX-record for domain can't be found
4652
return_status.append(DNSDiagnosis('NO_MX_RECORD'))

tests/data/dns-tests.xml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@
6565
</test>
6666
<test id="167">
6767
<address>test@test.com</address>
68-
<comment>test.com has an A-record but not an MX-record</comment>
68+
<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>
6969
<category>ISEMAIL_DNSWARN</category>
7070
<diagnosis>ISEMAIL_DNSWARN_NO_MX_RECORD</diagnosis>
7171
<source>Dominic Sayers</source>
7272
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink>
73+
<flaky>True</flaky>
7374
</test>
7475
<test id="168">
7576
<address>test@nic.no</address>
@@ -88,4 +89,20 @@
8889
<source>Michael Herold</source>
8990
<sourcelink>http://github.com/michaelherold/pyIsEmail</sourcelink>
9091
</test>
91-
</tests>
92+
<test id="170">
93+
<address>08.00.27.d1.8c.d2@virtualbox</address>
94+
<comment>This example was not giving the correct diagnosis, as it was falling back to an RFC5321 TLD diagnosis.</comment>
95+
<category>ISEMAIL_DNSWARN</category>
96+
<diagnosis>ISEMAIL_DNSWARN_NO_RECORD</diagnosis>
97+
<source>Nguyễn Hồng Quân</source>
98+
<sourcelink>https://github.com/michaelherold/pyIsEmail/issues/2</sourcelink>
99+
</test>
100+
<test id="171">
101+
<address>test@example.com</address>
102+
<comment>example.com has an A-record but not an MX-record</comment>
103+
<category>ISEMAIL_DNSWARN</category>
104+
<diagnosis>ISEMAIL_DNSWARN_NO_MX_RECORD</diagnosis>
105+
<source>Michael Herold</source>
106+
<sourcelink>http://github.com/michaelherold/pyIsEmail</sourcelink>
107+
</test>
108+
</tests>

tests/validators/test_dns_validator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class DNSValidatorFlakyTest(TestWithScenarios):
5454

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

57+
@expectedFailure
5758
def test_without_diagnosis(self):
5859

5960
v = DNSValidator()

0 commit comments

Comments
 (0)