You are here

public function JWKFetcherTest::testThatGetFormattedReturnsKeys in Auth0 Single Sign On 8.2

File

vendor/auth0/auth0-php/tests/Helpers/JWKFetcherTest.php, line 17

Class

JWKFetcherTest
Class JWKFetcherTest.

Namespace

Auth0\Tests\Helpers

Code

public function testThatGetFormattedReturnsKeys() {
  $test_jwks = file_get_contents(AUTH0_PHP_TEST_JSON_DIR . 'localhost--well-known-jwks-json.json');
  $jwks = new MockJwks([
    new Response(200, [
      'Content-Type' => 'application/json',
    ], $test_jwks),
  ]);
  $jwks_formatted = $jwks
    ->call()
    ->getKeys(uniqid());
  $this
    ->assertCount(2, $jwks_formatted);
  $this
    ->assertArrayHasKey('__test_kid_1__', $jwks_formatted);
  $pem_parts_1 = explode(PHP_EOL, $jwks_formatted['__test_kid_1__']);
  $this
    ->assertCount(4, $pem_parts_1);
  $this
    ->assertEquals('-----BEGIN CERTIFICATE-----', $pem_parts_1[0]);
  $this
    ->assertEquals('__test_x5c_1__', $pem_parts_1[1]);
  $this
    ->assertEquals('-----END CERTIFICATE-----', $pem_parts_1[2]);
  $pem_parts_2 = explode(PHP_EOL, $jwks_formatted['__test_kid_2__']);
  $this
    ->assertCount(4, $pem_parts_2);
  $this
    ->assertEquals('-----BEGIN CERTIFICATE-----', $pem_parts_2[0]);
  $this
    ->assertEquals('__test_x5c_2__', $pem_parts_2[1]);
  $this
    ->assertEquals('-----END CERTIFICATE-----', $pem_parts_2[2]);
}