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

Function TestMakeSessionCookie

auth/session_test.go:119–145  ·  view source on GitHub ↗

Coverage for MakeSessionCookie. The MakeSessionCookie should create a cookie using the sessionID, username, expiration and TTL from LoginSession provided. If nil is provided instead of valid login session, nil must be returned.

(t *testing.T)

Source from the content-addressed store, hash-verified

117// using the sessionID, username, expiration and TTL from LoginSession provided.
118// If nil is provided instead of valid login session, nil must be returned.
119func TestMakeSessionCookie(t *testing.T) {
120 base.SetUpTestLogging(t, base.LevelDebug, base.KeyAuth)
121 ctx := base.TestCtx(t)
122 testBucket := base.GetTestBucket(t)
123 defer testBucket.Close(ctx)
124 dataStore := testBucket.GetSingleDataStore()
125 auth := NewTestAuthenticator(t, dataStore, nil, DefaultAuthenticatorOptions(ctx))
126
127 sessionID, err := base.GenerateRandomSecret()
128 require.NoError(t, err)
129 mockSession := &LoginSession{
130 ID: sessionID,
131 Username: "Alice",
132 Expiration: time.Now().Add(2 * time.Hour),
133 Ttl: 24 * time.Hour,
134 }
135
136 cookie := auth.MakeSessionCookie(mockSession, false, false, http.SameSiteDefaultMode)
137 assert.Equal(t, DefaultCookieName, cookie.Name)
138 assert.Equal(t, sessionID, cookie.Value)
139 assert.NotEmpty(t, cookie.Expires)
140
141 // Cookies should not be created with uninitialized session
142 mockSession = nil
143 cookie = auth.MakeSessionCookie(mockSession, false, false, http.SameSiteDefaultMode)
144 assert.Empty(t, cookie)
145}
146
147func TestMakeSessionCookieProperties(t *testing.T) {
148 ctx := base.TestCtx(t)

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected