-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic checking of mx records for mailto links #57
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #57 +/- ##
==========================================
- Coverage 95.67% 93.45% -2.22%
==========================================
Files 17 17
Lines 902 917 +15
==========================================
- Hits 863 857 -6
- Misses 34 49 +15
- Partials 5 11 +6
Continue to review full report at Codecov.
|
Coverage has decreased as I can't think of a way to trigger the errors to execute those lines of code. In theory they should never execute, but it is a bit of catch all error handling in a default and else statement. |
Does this pass for the case that a domain has no MX records, but has a valid A/CNAME record? (I believe it should) |
I believe you are correct according to this RFC 5321 Section 5 but that doesn't current exist. |
Looking at the changes coverage is fine. Re. the RFC my understanding is as follows: Checking items off as I read them
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guessing you're not finished yet, but have some comments 😄
continue | ||
|
||
} else if dnserr, ok = err.(*net.DNSError); !ok || dnserr.Err != "no such host" { | ||
// this isn't an error we are expecting to see here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exact error on Linux for the loop CNAME test is server misbehaving
(value of dnserr.Err
) which seems in-line-ish with nslookup:
~ ❯ nslookup loop1.dtaylor.uk
Server: 127.0.1.1
Address: 127.0.1.1#53
** server can't find loop1.dtaylor.uk: SERVFAIL
Likely an error discrepancy between Linux and OSX. You may need to restructure a bit to handle this cleanly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is infact an issue, no such host is an isolated case where we want to proceed to checking A records. Should a CNAME loop not produce an warning of some variety?
I accept that this may be inconsistent between platforms, but I feel the Linux way is actually better in this case and the OS X way is an acceptable fallback?
|
||
domain := strings.Split(ref.URL.Opaque, "@")[1] | ||
|
||
for domain != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment here would be nice: we're going to loop until we find a valid record or error
func TestMailtoInvalidCname(t *testing.T) { | ||
// fails for invalid mailto links | ||
hT := tTestFile("fixtures/links/invalid_mailto_cname.html") | ||
tExpectIssueCount(t, hT, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guessing this isn't done yet. In general write the tests with expected result and add t.Skip("Not yet dealt with")
at the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test was complete, it was checking that just a CNAME pointing to another domain that was valid would work as expected, comments should hopefully clear that up.
func TestMailtoInvalidAFallback(t *testing.T) { | ||
// fails for invalid mailto links | ||
hT := tTestFile("fixtures/links/invalid_mailto_fallback.html") | ||
tExpectIssueCount(t, hT, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
htmltest/check-link_test.go
Outdated
// fails for invalid mailto links | ||
hT := tTestFile("fixtures/links/invalid_mailto_link.html") | ||
tExpectIssueCount(t, hT, 1) | ||
tExpectIssue(t, hT, "contains an invalid email address", 1) | ||
} | ||
|
||
func TestMailtoInvalidCname(t *testing.T) { | ||
// fails for invalid mailto links |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write these comments so we can get an idea of what's actually being tested
Helps ensure that the domain is registered and at least partially configured to recieve email.
As per https://tools.ietf.org/html/rfc5321#section-5 this should fallback to the hostname for that domain.
LookupMX will perform this if the CNAME result has an MX record as well, but the spec states we should "start again" so we will do just that. This allows fallback to A/AAAA records in a CNAME -> A configuration. Loops are handled by the LookupCNAME method.
c10c559
to
7d0f854
Compare
Rebased and made the changes requested. |
7d0f854
to
75fff69
Compare
Helps ensure that the domain is registered and at least partially configured to recieve email.