mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: setting time forward for expiration math (#22687)
It was set backwards, which allowed invalid refresh tokens. Making things worse.
This commit is contained in:
@@ -36,18 +36,51 @@ func TestShouldRefreshOIDCToken(t *testing.T) {
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "ExpiredBeyondAssumedWindow",
|
||||
name: "LongExpired",
|
||||
link: database.UserLink{
|
||||
OAuthRefreshToken: "refresh",
|
||||
OAuthExpiry: now.Add(-20 * time.Minute),
|
||||
OAuthExpiry: now.Add(-1 * time.Hour),
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "ExpiredWithinAssumedWindow",
|
||||
// Edge being "+/- 10 minutes"
|
||||
name: "EdgeExpired",
|
||||
link: database.UserLink{
|
||||
OAuthRefreshToken: "refresh",
|
||||
OAuthExpiry: now.Add(-5 * time.Minute),
|
||||
OAuthExpiry: now.Add(-1 * time.Minute * 10),
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Expired",
|
||||
link: database.UserLink{
|
||||
OAuthRefreshToken: "refresh",
|
||||
OAuthExpiry: now.Add(-1 * time.Minute),
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "SoonToBeExpired",
|
||||
link: database.UserLink{
|
||||
OAuthRefreshToken: "refresh",
|
||||
OAuthExpiry: now.Add(5 * time.Minute),
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "SoonToBeExpiredEdge",
|
||||
link: database.UserLink{
|
||||
OAuthRefreshToken: "refresh",
|
||||
OAuthExpiry: now.Add(9 * time.Minute),
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "AfterEdge",
|
||||
link: database.UserLink{
|
||||
OAuthRefreshToken: "refresh",
|
||||
OAuthExpiry: now.Add(11 * time.Minute),
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
@@ -59,6 +92,14 @@ func TestShouldRefreshOIDCToken(t *testing.T) {
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "NotEvenCloseExpired",
|
||||
link: database.UserLink{
|
||||
OAuthRefreshToken: "refresh",
|
||||
OAuthExpiry: now.Add(time.Hour * 24),
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
||||
Reference in New Issue
Block a user