Skip to content

Commit e451572

Browse files
committed
Fix cutoff not considering time being equal
1 parent d61f609 commit e451572

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pkg/platform/authentication/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (s *Auth) MaybeRenew() error {
148148
// cutoffReached checks whether the JWT will expire before the provided cutoff time
149149
func (s *Auth) cutoffReached(cutoff time.Time) bool {
150150
expires := s.lastRenewal.Add(s.jwtLifetime)
151-
return expires.Before(cutoff)
151+
return expires.Equal(cutoff) || expires.Before(cutoff)
152152
}
153153

154154
func (s *Auth) Close() error {

pkg/platform/authentication/auth_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
)
99

1010
func TestAuth_cutoffReached(t *testing.T) {
11+
now := time.Now()
12+
1113
tests := []struct {
1214
name string
1315
auth *Auth
@@ -17,28 +19,28 @@ func TestAuth_cutoffReached(t *testing.T) {
1719
{
1820
"Cutoff one second beyond keepalive",
1921
&Auth{
20-
lastRenewal: ptr.To(time.Now()),
22+
lastRenewal: ptr.To(now),
2123
jwtLifetime: time.Second,
2224
},
23-
time.Now().Add(2 * time.Second),
25+
now.Add(2 * time.Second),
2426
true,
2527
},
2628
{
2729
"Cutoff one second before keepalive",
2830
&Auth{
29-
lastRenewal: ptr.To(time.Now()),
31+
lastRenewal: ptr.To(now),
3032
jwtLifetime: 2 * time.Second,
3133
},
32-
time.Now().Add(time.Second),
34+
now.Add(time.Second),
3335
false,
3436
},
3537
{
3638
"Cutoff equal to keepalive",
3739
&Auth{
38-
lastRenewal: ptr.To(time.Now()),
40+
lastRenewal: ptr.To(now),
3941
jwtLifetime: time.Second,
4042
},
41-
time.Now().Add(time.Second),
43+
now.Add(time.Second),
4244
true,
4345
},
4446
}

0 commit comments

Comments
 (0)