Skip to content

Commit

Permalink
bug #787 fix day saving transition php (flaugere)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.x-dev branch.

Discussion
----------

fix day saving transition php

Bug fix related to https://bugs.php.net/bug.php?id=74274
DateTime format('U') doesn't handle correctly DST. time should be
prefered

Commits
-------

7bb2f70 fix day saving transition php
  • Loading branch information
chalasr committed Oct 27, 2020
2 parents 3e541e8 + 7bb2f70 commit 57105a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Signature/LoadedJWS.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function checkExpiration()
return $this->state = self::INVALID;
}

if ($this->clockSkew <= (new \DateTime())->format('U') - $this->payload['exp']) {
if ($this->clockSkew <= time() - $this->payload['exp']) {
$this->state = self::EXPIRED;
}
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/Signature/LoadedJWSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use Lexik\Bundle\JWTAuthenticationBundle\Signature\LoadedJWS;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ClockMock;

/**
* Tests the CreatedJWS model class.
* @group time-sensitive
*/
final class LoadedJWSTest extends TestCase
{
Expand Down Expand Up @@ -96,4 +98,22 @@ public function testIsInvalidReturnsFalseWithIssuedAtSetInTheFutureButAccountedF
$this->assertFalse($jws->isExpired());
$this->assertFalse($jws->isInvalid());
}

public function testIsNotExpiredDaySavingTransition()
{
// 2020-10-25 00:16:13 UTC+0
$timestamp = 1603584973;
ClockMock::withClockMock($timestamp);

$dstPayload = [
'username' => 'test',
'exp' => $timestamp + 3600,
'iat' => $timestamp,
];

$jws = new LoadedJWS($dstPayload, true);

$this->assertFalse($jws->isExpired());
$this->assertTrue($jws->isVerified());
}
}

0 comments on commit 57105a5

Please sign in to comment.