From 1c181ee17fc23fe0f9dff9283de6cf0dbdecb4bf Mon Sep 17 00:00:00 2001 From: Seth Phat Date: Sun, 15 Oct 2023 11:44:39 +0700 Subject: [PATCH] ShipSaaS Laravel JWKS --- phpunit.xml | 25 +++++++++-------- tests/TestCase.php | 5 ---- tests/Unit/Entities/KeySetTest.php | 45 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 tests/Unit/Entities/KeySetTest.php diff --git a/phpunit.xml b/phpunit.xml index 0f93b8f..b17e9b6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,23 +1,24 @@ - - - - ./src - - - ./src/Configs - ./src/Routes - ./src/ShipSaasLaravelJwksServiceProvider.php - - + + ./tests/ - ./tests/TestCase.php + ./tests/TestCase.php + + + ./src + + + ./src/Configs + ./src/Routes + ./src/ShipSaasLaravelJwksServiceProvider.php + + diff --git a/tests/TestCase.php b/tests/TestCase.php index 734cc10..5a57ed8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,11 +10,6 @@ abstract class TestCase extends BaseTestCase { use WithFaker; - protected function setUp(): void - { - parent::setUp(); - } - protected function getPackageProviders($app): array { return [ diff --git a/tests/Unit/Entities/KeySetTest.php b/tests/Unit/Entities/KeySetTest.php new file mode 100644 index 0000000..96b64f0 --- /dev/null +++ b/tests/Unit/Entities/KeySetTest.php @@ -0,0 +1,45 @@ +add($key); + + $array = $keyset->toArray(); + + $this->assertNotEmpty($array); + + $this->assertSame($array[0]['alg'], 'RS256'); + $this->assertSame($array[0]['kty'], 'RSA'); + } + + public function testKetSetCanAddAndParseToString() + { + $keyset = new KeySet(); + + $keyContent = file_get_contents(__DIR__ . '/../../__fixtures__/public-key.pub'); + $key = Key::fromRaw($keyContent, new KeyConfiguration()); + + $keyset->add($key); + + $string = $keyset->__toString(); + + $this->assertNotEmpty($string); + + $this->assertStringContainsString('RS256', $string); + $this->assertStringContainsString('RSA', $string); + } +}