fix(19.3-06): zero CookieConfig writes SameSite=Lax and Secure (WR-09)

- withDefaults gives the zero config Secure and every unset SameSite Lax;
  a config with any field set keeps its Secure value
This commit is contained in:
Jakub Zych
2026-10-15 22:27:31 +02:00
parent 4dae8331c5
commit 85d8b6a85a
4 changed files with 30 additions and 8 deletions

View File

@@ -147,11 +147,20 @@ func TestTokenCookieAttributes(t *testing.T) {
}
}
// A zero config writes the default cookie on "/" and host-only.
// A zero config writes the default cookie on "/", host-only, with
// SameSite=Lax and Secure.
z := CookieConfig{}.TokenCookie("v", time.Minute)
if z.Name != DefaultCookieName || z.Path != "/" || z.Domain != "" || !z.HttpOnly {
t.Fatalf("zero config cookie = %+v", z)
}
if z.SameSite != http.SameSiteLaxMode || !z.Secure {
t.Fatalf("zero config cookie SameSite %v Secure %t, want Lax and Secure", z.SameSite, z.Secure)
}
// A partial config gets SameSite=Lax and keeps its Secure value.
p := CookieConfig{Name: "sid"}.TokenCookie("v", time.Minute)
if p.SameSite != http.SameSiteLaxMode || p.Secure {
t.Fatalf("partial config cookie SameSite %v Secure %t, want Lax and not Secure", p.SameSite, p.Secure)
}
if strings.Contains(z.String(), "Domain=") {
t.Fatalf("host-only cookie carries a domain: %s", z.String())
}