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)
| 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. |
| 119 | func 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 | |
| 147 | func TestMakeSessionCookieProperties(t *testing.T) { |
| 148 | ctx := base.TestCtx(t) |
nothing calls this directly
no test coverage detected