Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token must expire the exact time of "exp" claim #635

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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