aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVolker Dobler <dr.volker.dobler@gmail.com>2017-03-22 09:14:41 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2017-05-22 19:29:49 +0000
commitc5e8ec5b6dc63de087d93d96dc06cb3de6842ec4 (patch)
tree250d6ad8b9a0d641ed6d7827e1d665cd53f71c93 /src
parentd79bb78a71c6f2084497c1291041aa1fa2325835 (diff)
downloadgo-c5e8ec5b6dc63de087d93d96dc06cb3de6842ec4.tar.xz
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 <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/net/http/cookiejar/jar.go3
-rw-r--r--src/net/http/cookiejar/jar_test.go11
2 files changed, 14 insertions, 0 deletions
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).
"": "",