-
Notifications
You must be signed in to change notification settings - Fork 2
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
Perform test locally instead of using a live dns resolution #13
Conversation
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.
Using a mock resolver makes sense to me. It's always good to not depend on an active internet connection and a DNS configuration that we don't control here.
I found a few stylistic nits, see comments.
resolver.go
Outdated
@@ -32,7 +32,7 @@ type txtEntry struct { | |||
} | |||
|
|||
func NewResolver(url string) *Resolver { | |||
if !strings.HasPrefix(url, "https://") { | |||
if !(strings.HasPrefix(url, "https:") || strings.HasPrefix(url, "http:")) { |
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.
If I understand RFC 8484 correctly, DoH is only defined for HTTPS, not for HTTP. Or am I mistaken 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.
You are right. I have changed the test to modify the url
field directly.
resolver_test.go
Outdated
|
||
func mockDoHResolver(msgs map[uint16]*dns.Msg) *httptest.Server { | ||
return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { | ||
body, _ := ioutil.ReadAll(req.Body) |
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.
Don't ignore error
values. If this fails at some point in the future, this would be quite hard to debug.
Better: pass testing.T
to mockDoHResolver
, and check the returned error.
In the latest commit:
|
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.
LGTM, just need to check for one more error return value, then this is ready for merging.
resolver_test.go
Outdated
r.Unpack(body) | ||
m := msgs[r.Question[0].Qtype] | ||
|
||
b, _ := m.Pack() |
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.
There's another error return value here.
resolver_test.go
Outdated
dns.TypeA: mockDNSAnswerA(dns.Fqdn(domain), net.IPv4(127, 0, 0, 1)), | ||
dns.TypeAAAA: mockDNSAnswerAAAA(dns.Fqdn(domain), net.IPv6loopback), | ||
}) | ||
defer func() { resolver.Close() }() |
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.
defer func() { resolver.Close() }() | |
defer resolver.Close() |
resolver_test.go
Outdated
resolver := mockDoHResolver(t, map[uint16]*dns.Msg{ | ||
dns.TypeTXT: mockDNSAnswerTXT(dns.Fqdn(domain), []string{"dnslink=/ipns/example.com"}), | ||
}) | ||
defer func() { resolver.Close() }() |
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.
defer func() { resolver.Close() }() | |
defer resolver.Close() |
Tests were relying on an external domain to be configured properly. Especially, it needed to have both an A and AAAA record configured. It turns out this domain has changed and no longer has an AAAA record, making the tests to fail. This commit updates the tests to use a local DoH resolver, which can be configured to return deterministic answers. This way, the resolution does not depend on an external configuration.
Fixes #11.
Tests were relying on an external domain to be configured properly.
Especially, it needed to have both an A and AAAA record configured. It
turns out this domain has changed and no longer has an AAAA record,
making the tests to fail.
This commit updates the tests to use a local DoH resolver, which can be
configured to return deterministic answers. This way, the resolution
does not depend on an external configuration.