mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-10 22:08:48 +01:00
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:
1 parent
ac824d4094
commit
68505d3fd3
2 files changed
+25
-3
No files matched your search
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in new issue
Block a user