hstspreload icon indicating copy to clipboard operation
hstspreload copied to clipboard

Fix tests that rely on behavior of external domains

Open nharper opened this issue 6 years ago • 4 comments
trafficstars

Some of the test cases in redirects_test.go and domain_test.go rely on the behavior of external domains. For some of these tests, that behavior has changed and the tests are no longer passing.

Preferably, the tests would be hermetic and not connect to any external sites. If that's not possible, I'd prefer restricting it to domains where we have some reasonable assurance that it will keep behaving the way we expect for a test (e.g. badssl.com).

nharper avatar Jul 03 '19 22:07 nharper

(See also issue #75)

nharper avatar Jul 03 '19 23:07 nharper

I drafted a fix for this a while back! I'll go dust it off.

lgarron avatar Jul 03 '19 23:07 lgarron

That sounds incredibly useful, even if it's only partially complete.

nharper avatar Jul 08 '19 21:07 nharper

Here's the part I was able to dig up: https://github.com/chromium/hstspreload/commit/d4e2a716118657f22f6efc64420fc5202d39e4d2

The idea was to have a JSON file mapping URLs to http.DumpResponse() values, and ideally a "record" mode to add missing URLs to the cache while running the test. It's not super-idiomatic Go, bu I was unable to find an idiomatic Go testing mechanism for this (at the time) and this idea seemed simplest to implement and understand.

I have to apologize for the state of the code, though. It's even more incomplete than I remember, and I don't have time to work on it right now. It should give you a rough idea how how to hook up a custom transport for testing, though.

lgarron avatar Jul 09 '19 04:07 lgarron