feat(sts): Add IsExpired helpers and use them in expiration tests

- Add Credentials.IsExpired() and SessionInfo.IsExpired() in new file session_helpers.go.
- Update TestSTSSessionClaimsToSessionInfoCredentialExpiration to use helpers for clearer intent.
This commit is contained in:
Chris Lu committed 2026-01-02 20:32:32 -08:00
1 parent ac824d4094
commit 68505d3fd3
2 files changed
+25 -3

No files matched your search

+5 -3
View File
@@ -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)
}
})
}
+20
View File
@@ -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)
}