MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / TestBuildSessionCookies

Function TestBuildSessionCookies

internal/cookie/cookie_test.go:13–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestBuildSessionCookies(t *testing.T) {
14 tests := []struct {
15 name string
16 hostname string
17 secure bool
18 sameSite http.SameSite
19 wantDomain string // expected `.example.com`-style domain on the domain-scoped cookie
20 }{
21 {"production https", "https://auth.example.com", true, http.SameSiteNoneMode, ".example.com"},
22 {"localhost dev", "http://localhost:8080", false, http.SameSiteLaxMode, "localhost"},
23 {"subdomain", "https://auth.svc.example.com", true, http.SameSiteStrictMode, ".example.com"},
24 }
25 for _, tt := range tests {
26 t.Run(tt.name, func(t *testing.T) {
27 cookies := BuildSessionCookies(tt.hostname, "session-id", tt.secure, tt.sameSite)
28 require.Len(t, cookies, 2, "BuildSessionCookies must return exactly the host-scoped and domain-scoped pair")
29
30 for _, c := range cookies {
31 assert.Equal(t, "session-id", c.Value)
32 assert.Equal(t, tt.secure, c.Secure)
33 assert.True(t, c.HttpOnly, "session cookies must be HttpOnly")
34 assert.Equal(t, "/", c.Path)
35 assert.Equal(t, tt.sameSite, c.SameSite)
36 assert.Equal(t, 24*60*60, c.MaxAge, "session cookie MaxAge must be 1 day")
37 }
38
39 // Sanity-check cookie names.
40 assert.Equal(t, constants.AppCookieName+"_session", cookies[0].Name)
41 assert.Equal(t, constants.AppCookieName+"_session_domain", cookies[1].Name)
42 // Domain-scoped cookie picks up the apex.
43 assert.Equal(t, tt.wantDomain, cookies[1].Domain)
44 })
45 }
46}
47
48func TestBuildMfaSessionCookies(t *testing.T) {
49 cookies := BuildMfaSessionCookies("https://auth.example.com", "mfa-id", true)

Callers

nothing calls this directly

Calls 2

BuildSessionCookiesFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected