From: Volker Dobler Date: Wed, 22 Mar 2017 08:14:41 +0000 (+0100) Subject: net/http/cookiejar: increase test coverage X-Git-Tag: go1.9beta1~195 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c5e8ec5b6dc63de087d93d96dc06cb3de6842ec4;p=gostls13.git net/http/cookiejar: increase test coverage The jarKey function handles broken PublicSuffixList implementations but no test verified it. Change-Id: Ifb76de9e8c3941f3b08d3e43970056e023013457 Reviewed-on: https://go-review.googlesource.com/38357 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/net/http/cookiejar/jar.go b/src/net/http/cookiejar/jar.go index 37694a24f1..ef8c35bf0a 100644 --- a/src/net/http/cookiejar/jar.go +++ b/src/net/http/cookiejar/jar.go @@ -345,6 +345,9 @@ func jarKey(host string, psl PublicSuffixList) string { // Storing cookies under host is a safe stopgap. return host } + // Only len(suffix) is used to determine the jar key from + // here on, so it is okay if psl.PublicSuffix("www.buggy.psl") + // returns "com" as the jar key is generated from host. } prevDot := strings.LastIndex(host[:i-1], ".") return host[prevDot+1:] diff --git a/src/net/http/cookiejar/jar_test.go b/src/net/http/cookiejar/jar_test.go index f7682e698a..47fb1abdaa 100644 --- a/src/net/http/cookiejar/jar_test.go +++ b/src/net/http/cookiejar/jar_test.go @@ -19,6 +19,9 @@ var tNow = time.Date(2013, 1, 1, 12, 0, 0, 0, time.UTC) // testPSL implements PublicSuffixList with just two rules: "co.uk" // and the default rule "*". +// The implementation has two intentional bugs: +// PublicSuffix("www.buggy.psl") == "xy" +// PublicSuffix("www2.buggy.psl") == "com" type testPSL struct{} func (testPSL) String() string { @@ -28,6 +31,12 @@ func (testPSL) PublicSuffix(d string) string { if d == "co.uk" || strings.HasSuffix(d, ".co.uk") { return "co.uk" } + if d == "www.buggy.psl" { + return "xy" + } + if d == "www2.buggy.psl" { + return "com" + } return d[strings.LastIndex(d, ".")+1:] } @@ -187,6 +196,8 @@ var jarKeyTests = map[string]string{ "co.uk": "co.uk", "uk": "uk", "192.168.0.5": "192.168.0.5", + "www.buggy.psl": "www.buggy.psl", + "www2.buggy.psl": "buggy.psl", // The following are actual outputs of canonicalHost for // malformed inputs to canonicalHost (see above). "": "",