Skip to content

Commit

Permalink
test ttl and jti behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Oct 9, 2023
1 parent 7439793 commit fdd9215
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/Client/Credentials/KeypairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace VonageTest\Client\Credentials;

use Lcobucci\JWT\Signer\Key\InMemory;
use Vonage\Client\Exception\Validation;
use VonageTest\VonageTestCase;
use Vonage\Client\Credentials\Keypair;
Expand Down Expand Up @@ -37,6 +38,14 @@ public function testAsArray(): void
$this->assertEquals($this->application, $array['application']);
}

public function testGetKey(): void
{
$credentials = new Keypair($this->key, $this->application);

$key = $credentials->getKey();
$this->assertInstanceOf(InMemory::class, $key);
}

public function testProperties(): void
{
$credentials = new Keypair($this->key, $this->application);
Expand Down Expand Up @@ -81,6 +90,36 @@ public function testAdditionalClaims(): void
$this->assertEquals($claims['arbitrary'], $payload['arbitrary']);
}

public function testJtiClaim(): void
{
$credentials = new Keypair($this->key, $this->application);

$claims = [
'jti' => '9a1b8ca6-4406-4530-9940-3cde9d41de3f'
];

$jwt = $credentials->generateJwt($claims);
[, $payload] = $this->decodeJWT($jwt->toString());

$this->assertArrayHasKey('jti', $payload);
$this->assertEquals($claims['jti'], $payload['jti']);
}

public function testTtlClaim(): void
{
$credentials = new Keypair($this->key, $this->application);

$claims = [
'ttl' => 900
];

$jwt = $credentials->generateJwt($claims);
[, $payload] = $this->decodeJWT($jwt->toString());

$this->assertArrayHasKey('exp', $payload);
$this->assertEquals(time() + 900, $payload['exp']);
}

public function testNbfNotSupported(): void
{
set_error_handler(static function (int $errno, string $errstr) {
Expand Down

0 comments on commit fdd9215

Please sign in to comment.