Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tomtom5152
Copy link
Contributor

Helps ensure that the domain is registered and at least partially configured to recieve email.

@codecov-io
Copy link

codecov-io commented Aug 20, 2017

Codecov Report

Merging #57 into master will decrease coverage by 2.21%.
The diff coverage is 60.97%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
htmltest/check-link.go 91.6% <60.97%> (-3.5%) ⬇️
htmltest/htmltest.go 89.18% <0%> (-8.63%) ⬇️
htmltest/options.go 89.06% <0%> (-0.17%) ⬇️
htmldoc/document.go 88.37% <0%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d42cbee...75fff69. Read the comment docs.

@tomtom5152
Copy link
Contributor Author

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.

@davidtaylorhq
Copy link

davidtaylorhq commented Aug 20, 2017

Does this pass for the case that a domain has no MX records, but has a valid A/CNAME record? (I believe it should)

@tomtom5152
Copy link
Contributor Author

tomtom5152 commented Aug 20, 2017

I believe you are correct according to this RFC 5321 Section 5 but that doesn't current exist.

@wjdp
Copy link
Owner

wjdp commented Aug 23, 2017

Looking at the changes coverage is fine.

Re. the RFC my understanding is as follows:

Checking items off as I read them

  • DNS lookup must be performed
  • First check for MX
  • If CNAME present restart from beginning
  • If neither, fallback to A or AAAA
  • If NXDOMAIN then error
  • If haven't found a valid record then error

Copy link
Owner

@wjdp wjdp left a 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
Copy link
Owner

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.

Copy link
Contributor Author

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 != "" {
Copy link
Owner

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)
Copy link
Owner

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.

Copy link
Contributor Author

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

// 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
Copy link
Owner

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.
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.
@tomtom5152
Copy link
Contributor Author

Rebased and made the changes requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants