(t *testing.T)
| 87 | } |
| 88 | |
| 89 | func TestDeleteSession(t *testing.T) { |
| 90 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAuth) |
| 91 | ctx := base.TestCtx(t) |
| 92 | const username = "Alice" |
| 93 | testBucket := base.GetTestBucket(t) |
| 94 | defer testBucket.Close(ctx) |
| 95 | dataStore := testBucket.GetSingleDataStore() |
| 96 | auth := NewTestAuthenticator(t, dataStore, nil, DefaultAuthenticatorOptions(ctx)) |
| 97 | |
| 98 | id, err := base.GenerateRandomSecret() |
| 99 | require.NoError(t, err) |
| 100 | |
| 101 | mockSession := &LoginSession{ |
| 102 | ID: id, |
| 103 | Username: username, |
| 104 | Expiration: time.Now().Add(2 * time.Hour), |
| 105 | Ttl: 24 * time.Hour, |
| 106 | } |
| 107 | const noSessionExpiry = 0 |
| 108 | assert.NoError(t, dataStore.Set(auth.DocIDForSession(mockSession.ID), noSessionExpiry, nil, mockSession)) |
| 109 | assert.NoError(t, auth.DeleteSession(ctx, mockSession.ID, "")) |
| 110 | |
| 111 | session, _, err := auth.GetSession(mockSession.ID) |
| 112 | assert.Nil(t, session) |
| 113 | base.RequireDocNotFoundError(t, err) |
| 114 | } |
| 115 | |
| 116 | // Coverage for MakeSessionCookie. The MakeSessionCookie should create a cookie |
| 117 | // using the sessionID, username, expiration and TTL from LoginSession provided. |
nothing calls this directly
no test coverage detected