Skip to content

Commit

Permalink
When exp indicates the present, make it invalid. (#86)
Browse files Browse the repository at this point in the history
* When exp indicates the present, make it invalid.

* Update map_claims_test.go

Co-authored-by: Christian Banse <oxisto@aybaze.com>
  • Loading branch information
soranoba and oxisto committed Sep 10, 2021
1 parent d2c5d5a commit 02bc1ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions map_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package jwt

import (
"testing"
"time"
)

func TestVerifyAud(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 02bc1ac

Please sign in to comment.