]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/cookiejar: increase test coverage
authorVolker Dobler <dr.volker.dobler@gmail.com>
Wed, 22 Mar 2017 08:14:41 +0000 (09:14 +0100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 22 May 2017 19:29:49 +0000 (19:29 +0000)
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>

src/net/http/cookiejar/jar.go
src/net/http/cookiejar/jar_test.go

index 37694a24f14166cc839621fbdb353027e98080bb..ef8c35bf0a167700e5fc41f2e66df2978923783f 100644 (file)
@@ -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:]
index f7682e698abf400b85c6179e51f484555b71beca..47fb1abdaafa4a24dd1335b9ce242ba3cf63dc64 100644 (file)
@@ -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).
        "":              "",