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

Function TestDeleteSessionForCookie

auth/session_test.go:181–220  ·  view source on GitHub ↗

Coverage for DeleteSessionForCookie. Mock a fake cookie with default cookie name, sessionID and expiration; Try to delete the session for the cookie. DocID for session must be deleted from the Couchbase bucket and a new cookie must be returned with no sessionID against SyncGatewaySession and Now as

(t *testing.T)

Source from the content-addressed store, hash-verified

179// sessionID against SyncGatewaySession and Now as the expiration value. If the cookie in
180// the request is unknown, Nil would be returned from DeleteSessionForCookie.
181func TestDeleteSessionForCookie(t *testing.T) {
182 const defaultEndpoint = "http://localhost/"
183 base.SetUpTestLogging(t, base.LevelDebug, base.KeyAuth)
184 ctx := base.TestCtx(t)
185 testBucket := base.GetTestBucket(t)
186 defer testBucket.Close(ctx)
187 dataStore := testBucket.GetSingleDataStore()
188 auth := NewTestAuthenticator(t, dataStore, nil, DefaultAuthenticatorOptions(ctx))
189
190 sessionID, err := base.GenerateRandomSecret()
191 require.NoError(t, err)
192 body := strings.NewReader("?")
193 request, _ := http.NewRequest(http.MethodPost, defaultEndpoint, body)
194
195 cookie := &http.Cookie{
196 Name: DefaultCookieName,
197 Value: sessionID,
198 Expires: time.Now().Add(time.Duration(10)),
199 }
200
201 request.AddCookie(cookie)
202 newCookie := auth.DeleteSessionForCookie(ctx, request)
203
204 assert.NotEmpty(t, newCookie.Name)
205 assert.Empty(t, newCookie.Value)
206 assert.NotEmpty(t, newCookie.Expires)
207
208 // Check delete session for cookie request with unknown cookie.
209 // No new cookie must be returned from DeleteSessionForCookie; Nil.
210 request, _ = http.NewRequest(http.MethodPost, defaultEndpoint, body)
211 cookie = &http.Cookie{
212 Name: "Unknown",
213 Value: sessionID,
214 Expires: time.Now().Add(time.Duration(10)),
215 }
216
217 request.AddCookie(cookie)
218 newCookie = auth.DeleteSessionForCookie(ctx, request)
219 assert.Nil(t, newCookie)
220}
221
222func TestCreateSessionChangePassword(t *testing.T) {
223 testCases := []struct {

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected