Skip to content

Commit

Permalink
Merge pull request #25 from devedup/master
Browse files Browse the repository at this point in the history
Remove the internal crypto algorithm enum that has to be maintained
  • Loading branch information
hywak committed Feb 4, 2022
2 parents c0594bd + 2a63786 commit e98b439
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 69 deletions.
29 changes: 0 additions & 29 deletions src/Api/Enum/CryptographicAlgorithmEnum.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Api/Factory/ResponseFactory.php
Expand Up @@ -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;
Expand Down Expand Up @@ -56,15 +55,5 @@ private function validateAuthKey(array $authKey): void
)
);
}

if (!CryptographicAlgorithmEnum::isSupported($authKey['kid'])) {
throw new UnsupportedCryptographicAlgorithmException(
sprintf(
'Cryptographic algorithm `%s` is not supported. Supported algorithms: `%s`',
$authKey['kid'],
implode(',', CryptographicAlgorithmEnum::supportedAlgorithms())
)
);
}
}
}
11 changes: 5 additions & 6 deletions src/Api/Response/JsonWebKeySetCollection.php
Expand Up @@ -2,7 +2,6 @@

namespace Azimo\Apple\Api\Response;

use Azimo\Apple\Api\Enum\CryptographicAlgorithmEnum;
use Azimo\Apple\Api\Exception\UnsupportedCryptographicAlgorithmException;

class JsonWebKeySetCollection
Expand All @@ -19,16 +18,16 @@ public function __construct(array $authKeys)

public function getByCryptographicAlgorithm(string $algorithm): ?JsonWebKeySet
{
if (!CryptographicAlgorithmEnum::isSupported($algorithm)) {
$result = $this->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;
}
}
21 changes: 0 additions & 21 deletions tests/Unit/Api/Factory/ResponseFactoryTest.php
Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Auth/Jwt/JwtVerifierTest.php
Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down

0 comments on commit e98b439

Please sign in to comment.