Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the internal crypto algorithm enum that has to be maintained #25

Merged
merged 3 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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
)
);
}

devedup marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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