diff --git a/test/Client/Credentials/KeypairTest.php b/test/Client/Credentials/KeypairTest.php index d028dfc9..9187b4c7 100644 --- a/test/Client/Credentials/KeypairTest.php +++ b/test/Client/Credentials/KeypairTest.php @@ -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; @@ -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); @@ -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) {