diff --git a/weed/iam/sts/session_claims_test.go b/weed/iam/sts/session_claims_test.go index fffe54a64e..6ea5e3da58 100644 --- a/weed/iam/sts/session_claims_test.go +++ b/weed/iam/sts/session_claims_test.go @@ -179,11 +179,13 @@ func TestSTSSessionClaimsToSessionInfoCredentialExpiration(t *testing.T) { assert.True(t, sessionInfo.Credentials.Expiration.Sub(tc.expiresAt) < time.Second) // We set tc.expiresAt to past/future values to exercise expiration handling. - // Assert the credentials' expiration relative to now to exercise code behavior + // Use helper methods to assert expiration behavior on both SessionInfo and Credentials. if tc.expectNotExpired { - assert.True(t, time.Now().Before(sessionInfo.Credentials.Expiration), tc.description) + assert.False(t, sessionInfo.IsExpired(), tc.description) + assert.False(t, sessionInfo.Credentials.IsExpired(), tc.description) } else { - assert.True(t, time.Now().After(sessionInfo.Credentials.Expiration), tc.description) + assert.True(t, sessionInfo.IsExpired(), tc.description) + assert.True(t, sessionInfo.Credentials.IsExpired(), tc.description) } }) } diff --git a/weed/iam/sts/session_helpers.go b/weed/iam/sts/session_helpers.go new file mode 100644 index 0000000000..e13d1297d9 --- /dev/null +++ b/weed/iam/sts/session_helpers.go @@ -0,0 +1,20 @@ +package sts + +import "time" + +// IsExpired returns true if the credentials have expired +func (c *Credentials) IsExpired() bool { + if c == nil { + return true + } + return time.Now().After(c.Expiration) +} + +// IsExpired returns true if the session has expired +func (s *SessionInfo) IsExpired() bool { + // If SessionInfo is nil, consider it expired + if s == nil { + return true + } + return time.Now().After(s.ExpiresAt) +}