From cc2543c543d5eef4a585d94581f68b63de505e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20St=C3=B8ylen?= Date: Fri, 24 Feb 2023 11:46:05 +0100 Subject: [PATCH 1/2] hasExpired() should use self::getTimeNow() --- src/Token/AccessToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Token/AccessToken.php b/src/Token/AccessToken.php index 81533c30..fb0d5263 100644 --- a/src/Token/AccessToken.php +++ b/src/Token/AccessToken.php @@ -196,7 +196,7 @@ public function hasExpired() throw new RuntimeException('"expires" is not set on the token'); } - return $expires < time(); + return $expires < self::getTimeNow(); } /** From cc35fb1121701cd48b9852ad6b090b42513a9080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20St=C3=B8ylen?= Date: Sat, 25 Feb 2023 09:02:22 +0100 Subject: [PATCH 2/2] Add test for hasExpired when using setTimeNow. --- test/src/Token/AccessTokenTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/src/Token/AccessTokenTest.php b/test/src/Token/AccessTokenTest.php index 23ad105f..c2244d3c 100644 --- a/test/src/Token/AccessTokenTest.php +++ b/test/src/Token/AccessTokenTest.php @@ -161,6 +161,22 @@ public function testHasExpiredWhenPropertySetInPast() self::tearDownForBackwardsCompatibility(); } + public function testHasExpiredWhenTimeNowIsInFuture() + { + $options = [ + 'access_token' => 'mock_access_token', + 'expires' => time(), + ]; + + $token = $this->getAccessToken($options); + + $token->setTimeNow(time() + 60); + + $this->assertTrue($token->hasExpired()); + + self::tearDownForBackwardsCompatibility(); + } + public function testCannotReportExpiredWhenNoExpirationSet() { $options = [