mirror of
https://github.com/grafana/grafana.git
synced 2025-01-26 08:16:59 -06:00
382b24742a
* FeatureToggle: Add toggle to use a new way of rotating tokens * API: Add endpoints to perform token rotation, one endpoint for api request and one endpoint for redirectsd * Auth: Aling not authorized handling between auth middleware and access control middleware * API: add utility function to get redirect for login * API: Handle token rotation redirect for login page * Frontend: Add job scheduling for token rotation and make call to token rotation as fallback in retry request * ContextHandler: Prevent in-request rotation if feature flag is enabled and check if token needs to be rotated * AuthN: Prevent in-request rotation if feature flag is enabled and check if token needs to be rotated * Cookies: Add option NotHttpOnly * AuthToken: Add helper function to get next rotation time and another function to check if token need to be rotated * AuthN: Add function to delete session cookie and set expiry cookie Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
26 lines
778 B
Go
26 lines
778 B
Go
package usertoken
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestUserToken_NeedsRotation(t *testing.T) {
|
|
t.Run("should return true", func(t *testing.T) {
|
|
token := &UserToken{AuthTokenSeen: true, RotatedAt: time.Now().Add(-11 * time.Minute).Unix()}
|
|
assert.True(t, token.NeedsRotation(10*time.Minute))
|
|
})
|
|
|
|
t.Run("should return true when token is not seen", func(t *testing.T) {
|
|
token := &UserToken{AuthTokenSeen: false, RotatedAt: time.Now().Add(-2 * time.Minute).Unix()}
|
|
assert.True(t, token.NeedsRotation(10*time.Minute))
|
|
})
|
|
|
|
t.Run("should return false", func(t *testing.T) {
|
|
token := &UserToken{AuthTokenSeen: true, RotatedAt: time.Now().Add(-9 * time.Minute).Unix()}
|
|
assert.False(t, token.NeedsRotation(10*time.Minute))
|
|
})
|
|
}
|