Skip to content

Commit 02bc1ac

Browse files
soranobaoxisto
andauthored
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 <[email protected]>
1 parent d2c5d5a commit 02bc1ac

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

claims.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func verifyExp(exp *time.Time, now time.Time, required bool) bool {
238238
if exp == nil {
239239
return !required
240240
}
241-
return now.Before(*exp) || now.Equal(*exp)
241+
return now.Before(*exp)
242242
}
243243

244244
func verifyIat(iat *time.Time, now time.Time, required bool) bool {

map_claims_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package jwt
22

33
import (
44
"testing"
5+
"time"
56
)
67

78
func TestVerifyAud(t *testing.T) {
@@ -97,3 +98,26 @@ func TestMapclaimsVerifyExpiresAtInvalidTypeString(t *testing.T) {
9798
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got)
9899
}
99100
}
101+
102+
func TestMapClaimsVerifyExpiresAtExpire(t *testing.T) {
103+
exp := time.Now().Unix()
104+
mapClaims := MapClaims{
105+
"exp": float64(exp),
106+
}
107+
want := false
108+
got := mapClaims.VerifyExpiresAt(exp, true)
109+
if want != got {
110+
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got)
111+
}
112+
113+
got = mapClaims.VerifyExpiresAt(exp + 1, true)
114+
if want != got {
115+
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got)
116+
}
117+
118+
want = true
119+
got = mapClaims.VerifyExpiresAt(exp - 1, true)
120+
if want != got {
121+
t.Fatalf("Failed to verify claims, wanted: %v got %v", want, got)
122+
}
123+
}

0 commit comments

Comments
 (0)