mirror of https://github.com/golang-jwt/jwt.git
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:
parent
d2c5d5ab01
commit
02bc1ac506
|
@ -238,7 +238,7 @@ func verifyExp(exp *time.Time, now time.Time, required bool) bool {
|
||||||
if exp == nil {
|
if exp == nil {
|
||||||
return !required
|
return !required
|
||||||
}
|
}
|
||||||
return now.Before(*exp) || now.Equal(*exp)
|
return now.Before(*exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyIat(iat *time.Time, now time.Time, required bool) bool {
|
func verifyIat(iat *time.Time, now time.Time, required bool) bool {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package jwt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVerifyAud(t *testing.T) {
|
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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue