Skip to content

Commit

Permalink
Merge pull request #635 from Slamdunk/fix_34_exp_claim_RFC7519
Browse files Browse the repository at this point in the history
[v3.4] Token must expire the exact time of "exp" claim
  • Loading branch information
lcobucci authored Jan 27, 2021
2 parents 3a98e23 + 9e12304 commit cd83b54
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function isExpired(DateTimeInterface $now = null)

$now = $now ?: new DateTimeImmutable();

return $now > $this->claims->get(RegisteredClaims::EXPIRATION_TIME);
return $now >= $this->claims->get(RegisteredClaims::EXPIRATION_TIME);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions test/unit/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,29 @@ public function isExpiredShouldReturnTrueAfterTokenExpires()
$this->assertTrue($token->isExpired(new DateTime('+10 days')));
}

/**
* @test
*
* @covers ::isExpired
*
* @uses \Lcobucci\JWT\Token::__construct
* @uses \Lcobucci\JWT\Token::convertToDataSet
* @uses \Lcobucci\JWT\Token::getClaim
* @uses \Lcobucci\JWT\Token::hasClaim
* @uses Lcobucci\JWT\Claim\Basic
* @uses Lcobucci\JWT\Claim\GreaterOrEqualsTo
*/
public function isExpiredShouldReturnTrueAtTheSameTimeTheTokenExpires()
{
$now = new DateTimeImmutable();
$token = new Token(
['alg' => 'none'],
['exp' => $now]
);

$this->assertTrue($token->isExpired($now));
}

/**
* @test
*
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Validation/Constraint/ValidAtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function assertShouldNotRaiseExceptionWhenLeewayIsUsed()
RegisteredClaims::EXPIRATION_TIME => $now->modify('-5 seconds'),
];

$constraint = new ValidAt($this->clock, new DateInterval('PT5S'));
$constraint = new ValidAt($this->clock, new DateInterval('PT6S'));
$constraint->assert($this->buildToken($claims));

$this->addToAssertionCount(1);
Expand Down

0 comments on commit cd83b54

Please sign in to comment.