MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestMakeSessionCookieProperties

Function TestMakeSessionCookieProperties

auth/session_test.go:147–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestMakeSessionCookieProperties(t *testing.T) {
148 ctx := base.TestCtx(t)
149 testBucket := base.GetTestBucket(t)
150 defer testBucket.Close(ctx)
151 dataStore := testBucket.GetSingleDataStore()
152 auth := NewTestAuthenticator(t, dataStore, nil, DefaultAuthenticatorOptions(ctx))
153
154 sessionID, err := base.GenerateRandomSecret()
155 require.NoError(t, err)
156 mockSession := &LoginSession{
157 ID: sessionID,
158 Username: "jrascagneres",
159 Expiration: time.Now().Add(2 * time.Hour),
160 Ttl: 24 * time.Hour,
161 }
162
163 unsecuredCookie := auth.MakeSessionCookie(mockSession, false, false, http.SameSiteDefaultMode)
164 assert.False(t, unsecuredCookie.Secure)
165
166 securedCookie := auth.MakeSessionCookie(mockSession, true, false, http.SameSiteDefaultMode)
167 assert.True(t, securedCookie.Secure)
168
169 httpOnlyFalseCookie := auth.MakeSessionCookie(mockSession, false, false, http.SameSiteDefaultMode)
170 assert.False(t, httpOnlyFalseCookie.HttpOnly)
171
172 httpOnlyCookie := auth.MakeSessionCookie(mockSession, false, true, http.SameSiteDefaultMode)
173 assert.True(t, httpOnlyCookie.HttpOnly)
174}
175
176// Coverage for DeleteSessionForCookie. Mock a fake cookie with default cookie name,
177// sessionID and expiration; Try to delete the session for the cookie. DocID for session

Callers

nothing calls this directly

Calls 9

TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
GenerateRandomSecretFunction · 0.92
NewTestAuthenticatorFunction · 0.85
MakeSessionCookieMethod · 0.80
CloseMethod · 0.65
GetSingleDataStoreMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected