From 25e0639760b228d937f21567e902f5a2a314c80b Mon Sep 17 00:00:00 2001 From: "DaveC @ DevedUp" Date: Fri, 28 Jan 2022 15:11:16 +0000 Subject: [PATCH 1/3] Remove the internal crypto algorithm enum that has to be maintained The algorithms are already downloaded from Apple, so just use this as the master list instead of keeping another internal lookup key list. --- src/Api/Enum/CryptographicAlgorithmEnum.php | 29 ------------------- src/Api/Factory/ResponseFactory.php | 10 ------- src/Api/Response/JsonWebKeySetCollection.php | 12 ++++---- .../Unit/Api/Factory/ResponseFactoryTest.php | 21 -------------- tests/Unit/Auth/Jwt/JwtVerifierTest.php | 4 +-- 5 files changed, 8 insertions(+), 68 deletions(-) delete mode 100644 src/Api/Enum/CryptographicAlgorithmEnum.php diff --git a/src/Api/Enum/CryptographicAlgorithmEnum.php b/src/Api/Enum/CryptographicAlgorithmEnum.php deleted file mode 100644 index aaba73e..0000000 --- a/src/Api/Enum/CryptographicAlgorithmEnum.php +++ /dev/null @@ -1,29 +0,0 @@ -authKeys[$algorithm] ?? null; + if(!$result) { throw new UnsupportedCryptographicAlgorithmException( sprintf( - 'Cryptographic algorithm `%s` is not supported. Supported algorithms: `%s`', - $algorithm, - implode(',', CryptographicAlgorithmEnum::supportedAlgorithms()) + 'Cryptographic algorithm `%s` is not supported.', + $algorithm ) ); } - - return $this->authKeys[$algorithm] ?? null; + return $result; } } diff --git a/tests/Unit/Api/Factory/ResponseFactoryTest.php b/tests/Unit/Api/Factory/ResponseFactoryTest.php index 38a3f01..bdebdda 100644 --- a/tests/Unit/Api/Factory/ResponseFactoryTest.php +++ b/tests/Unit/Api/Factory/ResponseFactoryTest.php @@ -113,27 +113,6 @@ public function provideCreateFromArrayThrowsResponseValidationExceptionWhenKeyAr ]; } - public function testIfCreateFromArraySkipsCreatingJsonWebKeySetWhenKidIsNotSupported(): void - { - self::assertEquals( - new JsonWebKeySetCollection([]), - $this->responseFactory->createFromArray( - [ - 'keys' => [ - [ - 'kty' => 'RSA', - 'kid' => 'bar', - 'use' => 'sig', - 'alg' => 'RS256', - 'n' => 'foo', - 'e' => 'AQAB', - ], - ], - ] - ) - ); - } - public function testIfCreateFromArrayReturnsExpectedJsonWebKeySetCollection(): void { $responseBody = [ diff --git a/tests/Unit/Auth/Jwt/JwtVerifierTest.php b/tests/Unit/Auth/Jwt/JwtVerifierTest.php index 20c2bec..652045f 100644 --- a/tests/Unit/Auth/Jwt/JwtVerifierTest.php +++ b/tests/Unit/Auth/Jwt/JwtVerifierTest.php @@ -78,7 +78,7 @@ public function testIfVerifyThrowsInvalidCryptographicAlgorithmExceptionWhenAlgo $this->expectException(Exception\InvalidCryptographicAlgorithmException::class); $this->expectExceptionMessage( - 'Cryptographic algorithm `foo` is not supported. Supported algorithms: `86D88Kf,eXaunmL,YuyXoY,W6WcOKB`' + 'Cryptographic algorithm `foo` is not supported.' ); $this->jwtVerifier->verify($this->jwtTokenMock); } @@ -96,7 +96,7 @@ public function testIfVerifyThrowsInvalidCryptographicAlgorithmExceptionWhenAuth ->andReturn(new JWT\Token\DataSet(['kid' => '86D88Kf'], '')); $this->expectException(Exception\InvalidCryptographicAlgorithmException::class); - $this->expectExceptionMessage('Unsupported cryptographic algorithm passed `86D88Kf'); + $this->expectExceptionMessage('Cryptographic algorithm `86D88Kf` is not supported.'); $this->jwtVerifier->verify($this->jwtTokenMock); } From 92bd8cb927ab9cb5c5b3cd4c41e4816db297609d Mon Sep 17 00:00:00 2001 From: "DaveC @ DevedUp" Date: Fri, 4 Feb 2022 10:57:52 +0000 Subject: [PATCH 2/3] Removed import and other formatting --- src/Api/Response/JsonWebKeySetCollection.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Api/Response/JsonWebKeySetCollection.php b/src/Api/Response/JsonWebKeySetCollection.php index ddc71d7..3e94835 100644 --- a/src/Api/Response/JsonWebKeySetCollection.php +++ b/src/Api/Response/JsonWebKeySetCollection.php @@ -2,7 +2,6 @@ namespace Azimo\Apple\Api\Response; -use Azimo\Apple\Api\Enum\CryptographicAlgorithmEnum; use Azimo\Apple\Api\Exception\UnsupportedCryptographicAlgorithmException; class JsonWebKeySetCollection @@ -19,7 +18,6 @@ public function __construct(array $authKeys) public function getByCryptographicAlgorithm(string $algorithm): ?JsonWebKeySet { - $result = $this->authKeys[$algorithm] ?? null; if(!$result) { throw new UnsupportedCryptographicAlgorithmException( @@ -29,6 +27,7 @@ public function getByCryptographicAlgorithm(string $algorithm): ?JsonWebKeySet ) ); } + return $result; } } From 2a637862367051498a74d80d156cf3afb7281b97 Mon Sep 17 00:00:00 2001 From: "DaveC @ DevedUp" Date: Fri, 4 Feb 2022 10:57:52 +0000 Subject: [PATCH 3/3] Removed import and other formatting --- src/Api/Factory/ResponseFactory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Api/Factory/ResponseFactory.php b/src/Api/Factory/ResponseFactory.php index b3b2062..4a0ee38 100644 --- a/src/Api/Factory/ResponseFactory.php +++ b/src/Api/Factory/ResponseFactory.php @@ -2,7 +2,6 @@ namespace Azimo\Apple\Api\Factory; -use Azimo\Apple\Api\Enum\CryptographicAlgorithmEnum; use Azimo\Apple\Api\Exception\ResponseValidationException; use Azimo\Apple\Api\Exception\UnsupportedCryptographicAlgorithmException; use Azimo\Apple\Api\Response\JsonWebKeySet;