mirror of
https://github.com/golang/go
synced 2024-11-18 09:54:57 -07:00
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>
This commit is contained in:
parent
d79bb78a71
commit
c5e8ec5b6d
@ -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:]
|
||||
|
@ -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).
|
||||
"": "",
|
||||
|
Loading…
Reference in New Issue
Block a user