mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-01 10:00:19 +08:00
Improve error handling in AutoSigninFilter
This commit is contained in:
@ -58,8 +58,10 @@ func Time2String(timestamp time.Time) string {
|
||||
return timestamp.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
func IsTokenExpired(createdTime string, expiresIn int) bool {
|
||||
func IsTokenExpired(createdTime string, expiresIn int) (bool, string) {
|
||||
createdTimeObj, _ := time.Parse(time.RFC3339, createdTime)
|
||||
expiresAtObj := createdTimeObj.Add(time.Duration(expiresIn) * time.Second)
|
||||
return time.Now().After(expiresAtObj)
|
||||
isExpired := time.Now().After(expiresAtObj)
|
||||
expireTime := expiresAtObj.Local().Format(time.RFC3339)
|
||||
return isExpired, expireTime
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ func Test_IsTokenExpired(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(scenario.description, func(t *testing.T) {
|
||||
result := IsTokenExpired(scenario.input.createdTime, scenario.input.expiresIn)
|
||||
result, _ := IsTokenExpired(scenario.input.createdTime, scenario.input.expiresIn)
|
||||
assert.Equal(t, scenario.expected, result, fmt.Sprintf("Expected %t, but was founded %t", scenario.expected, result))
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user