When exp indicates the present, make it invalid. (#86)

* When exp indicates the present, make it invalid.

* Update map_claims_test.go

Co-authored-by: Christian Banse <oxisto@aybaze.com>
This commit is contained in:
Hinagiku Soranoba 2021-09-11 06:44:55 +09:00 committed by GitHub
parent d2c5d5ab01
commit 02bc1ac506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -238,7 +238,7 @@ func verifyExp(exp *time.Time, now time.Time, required bool) bool {
if exp == nil {
return !required
}
return now.Before(*exp) || now.Equal(*exp)
return now.Before(*exp)
}
func verifyIat(iat *time.Time, now time.Time, required bool) bool {

View File

@ -2,6 +2,7 @@ package jwt
import (
"testing"
"time"
)
func TestVerifyAud(t *testing.T) {
@ -97,3 +98,26 @@ func TestMapclaimsVerifyExpiresAtInvalidTypeString(t *testing.T) {
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got)
}
}
func TestMapClaimsVerifyExpiresAtExpire(t *testing.T) {
exp := time.Now().Unix()
mapClaims := MapClaims{
"exp": float64(exp),
}
want := false
got := mapClaims.VerifyExpiresAt(exp, true)
if want != got {
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got)
}
got = mapClaims.VerifyExpiresAt(exp + 1, true)
if want != got {
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got)
}
want = true
got = mapClaims.VerifyExpiresAt(exp - 1, true)
if want != got {
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got)
}
}