|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Facile\OpenIDClientTest\Client; |
| 6 | + |
| 7 | +use Facile\JoseVerifier\JWK\MemoryJwksProvider; |
| 8 | +use Facile\OpenIDClient\Client\ClientBuilder; |
| 9 | +use Facile\OpenIDClient\Client\Metadata\ClientMetadataInterface; |
| 10 | +use Facile\OpenIDClient\Issuer\IssuerInterface; |
| 11 | +use Facile\OpenIDClientTest\TestCase; |
| 12 | + |
| 13 | +class ClientBuilderTest extends TestCase |
| 14 | +{ |
| 15 | + public function testWithoutClientJwks(): void |
| 16 | + { |
| 17 | + $issuer = $this->prophesize(IssuerInterface::class); |
| 18 | + $metadata = $this->prophesize(ClientMetadataInterface::class); |
| 19 | + $metadata->getJwks()->willReturn(null); |
| 20 | + $builder = (new ClientBuilder()) |
| 21 | + ->setClientMetadata($metadata->reveal()) |
| 22 | + ->setIssuer($issuer->reveal()); |
| 23 | + $client = $builder->build(); |
| 24 | + $provider = $client->getJwksProvider(); |
| 25 | + |
| 26 | + static::assertSame($issuer->reveal(), $client->getIssuer()); |
| 27 | + static::assertSame($metadata->reveal(), $client->getMetadata()); |
| 28 | + static::assertInstanceOf(MemoryJwksProvider::class, $client->getJwksProvider()); |
| 29 | + static::assertSame(['keys' => []], $client->getJwksProvider()->getJwks()); |
| 30 | + } |
| 31 | + |
| 32 | + public function testBuildWithClientJwks(): void |
| 33 | + { |
| 34 | + $jwks = [ |
| 35 | + 'keys' => [ |
| 36 | + 'kty' => 'RSA', |
| 37 | + ], |
| 38 | + ]; |
| 39 | + $issuer = $this->prophesize(IssuerInterface::class); |
| 40 | + $metadata = $this->prophesize(ClientMetadataInterface::class); |
| 41 | + $metadata->getJwks()->willReturn($jwks); |
| 42 | + $builder = (new ClientBuilder()) |
| 43 | + ->setClientMetadata($metadata->reveal()) |
| 44 | + ->setIssuer($issuer->reveal()); |
| 45 | + $client = $builder->build(); |
| 46 | + $provider = $client->getJwksProvider(); |
| 47 | + |
| 48 | + static::assertSame($issuer->reveal(), $client->getIssuer()); |
| 49 | + static::assertSame($metadata->reveal(), $client->getMetadata()); |
| 50 | + static::assertInstanceOf(MemoryJwksProvider::class, $client->getJwksProvider()); |
| 51 | + static::assertSame($jwks, $client->getJwksProvider()->getJwks()); |
| 52 | + } |
| 53 | +} |
0 commit comments