diff --git a/src/Token.php b/src/Token.php index dfb259d9..52d6abfa 100644 --- a/src/Token.php +++ b/src/Token.php @@ -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); } /** diff --git a/test/unit/TokenTest.php b/test/unit/TokenTest.php index 9cb9294e..50939502 100644 --- a/test/unit/TokenTest.php +++ b/test/unit/TokenTest.php @@ -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 * diff --git a/test/unit/Validation/Constraint/ValidAtTest.php b/test/unit/Validation/Constraint/ValidAtTest.php index 8ba6fc46..e8cac97f 100644 --- a/test/unit/Validation/Constraint/ValidAtTest.php +++ b/test/unit/Validation/Constraint/ValidAtTest.php @@ -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);