Skip to content

Commit 3c72913

Browse files
chore: added test for TokenAuthStrategy.php
1 parent 2db7ef7 commit 3c72913

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Twilio/AuthStrategy/TokenAuthStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(TokenManager $tokenManager) {
2929
*/
3030
public function isTokenExpired(string $token): bool {
3131
// Decode the JWT token
32-
$decodedToken = JWT::decode($token);
32+
$decodedToken = JWT::decode($token, null, false);
3333

3434
// If the token doesn't have an expiration, consider it expired
3535
if($decodedToken === null || $decodedToken->exp === null) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
4+
namespace AuthStrategy;
5+
6+
use Twilio\AuthStrategy\TokenAuthStrategy;
7+
use Twilio\Http\BearerToken\ApiTokenManager;
8+
use Twilio\Jwt\ClientToken;
9+
use Twilio\Tests\Unit\UnitTest;
10+
11+
class TokenAuthStrategyTest extends UnitTest {
12+
private $tokenAuthStrategy;
13+
14+
public function setUp(): void {
15+
parent::setUp();
16+
$this->tokenAuthStrategy = new TokenAuthStrategy(new ApiTokenManager());
17+
}
18+
19+
public function testAuthType(): void {
20+
$this->assertEquals('token', $this->tokenAuthStrategy->getAuthType());
21+
}
22+
23+
public function testIsTokenExpired(): void {
24+
$token = new ClientToken('AC123', 'foo');
25+
$tokenString = $token->generateToken();
26+
$this->assertFalse($this->tokenAuthStrategy->isTokenExpired($tokenString));
27+
}
28+
29+
public function testRequiresAuthentication(): void {
30+
$this->assertTrue($this->tokenAuthStrategy->requiresAuthentication());
31+
}
32+
}

0 commit comments

Comments
 (0)