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

fix for invalid expires value #929

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Token/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public function __construct(array $options = [])
$expires = $options['expires'];

if (!$this->isExpirationTimestamp($expires)) {
if (!is_numeric($expires)) {
$expires = intval($expires);
Comment on lines +124 to +125
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this check is useful. If something is not numeric, it usually won't have an intval worth using.

For example: https://3v4l.org/9r3Wj

}

$expires += $this->getTimeNow();
}

Expand Down
22 changes: 22 additions & 0 deletions test/src/Token/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ public function testInvalidExpiresIn()
self::tearDownForBackwardsCompatibility();
}

public function testInvalidExpires()
{
$options = [
'access_token' => 'access_token',
'expires' => 'TEXT',
];

$token = $this->getAccessToken($options);

$this->assertSame($token->getExpires(), $token->getTimeNow());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you're trying to test here, but 'TEXT' can't be the same as the return value of getTimeNow(), which is the current time stamp, so the tests are failing.


$options = [
'access_token' => 'access_token',
'expires' => '3TEXT',
];

$token = $this->getAccessToken($options);

$this->assertFalse($token->hasExpired());

self::tearDownForBackwardsCompatibility();
}

public function testJsonSerializable()
{
Expand Down