Commit c5e8ec5b authored by Volker Dobler's avatar Volker Dobler Committed by Brad Fitzpatrick

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/38357Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent d79bb78a
...@@ -345,6 +345,9 @@ func jarKey(host string, psl PublicSuffixList) string { ...@@ -345,6 +345,9 @@ func jarKey(host string, psl PublicSuffixList) string {
// Storing cookies under host is a safe stopgap. // Storing cookies under host is a safe stopgap.
return host 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], ".") prevDot := strings.LastIndex(host[:i-1], ".")
return host[prevDot+1:] return host[prevDot+1:]
......
...@@ -19,6 +19,9 @@ var tNow = time.Date(2013, 1, 1, 12, 0, 0, 0, time.UTC) ...@@ -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" // testPSL implements PublicSuffixList with just two rules: "co.uk"
// and the default rule "*". // and the default rule "*".
// The implementation has two intentional bugs:
// PublicSuffix("www.buggy.psl") == "xy"
// PublicSuffix("www2.buggy.psl") == "com"
type testPSL struct{} type testPSL struct{}
func (testPSL) String() string { func (testPSL) String() string {
...@@ -28,6 +31,12 @@ func (testPSL) PublicSuffix(d string) string { ...@@ -28,6 +31,12 @@ func (testPSL) PublicSuffix(d string) string {
if d == "co.uk" || strings.HasSuffix(d, ".co.uk") { if d == "co.uk" || strings.HasSuffix(d, ".co.uk") {
return "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:] return d[strings.LastIndex(d, ".")+1:]
} }
...@@ -187,6 +196,8 @@ var jarKeyTests = map[string]string{ ...@@ -187,6 +196,8 @@ var jarKeyTests = map[string]string{
"co.uk": "co.uk", "co.uk": "co.uk",
"uk": "uk", "uk": "uk",
"192.168.0.5": "192.168.0.5", "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 // The following are actual outputs of canonicalHost for
// malformed inputs to canonicalHost (see above). // malformed inputs to canonicalHost (see above).
"": "", "": "",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment