From 0654cfd475d4571e97a7b33acf20e0872e90ec4e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:36:03 +0100 Subject: [PATCH] Update web-token/jwt-library requirement from ^3.4 to ^3.4 || ^4.0 in the production-dependencies group (#1) * Update web-token/jwt-library requirement || ^4.0 Updates the requirements on [web-token/jwt-library](https://github.com/web-token/jwt-library) to permit the latest version. Updates `web-token/jwt-library` to 4.0.1 - [Commits](https://github.com/web-token/jwt-library/compare/3.4.0...4.0.1) --- updated-dependencies: - dependency-name: web-token/jwt-library dependency-type: direct:production dependency-group: production-dependencies ... Signed-off-by: dependabot[bot] * Update web-token/jwt-library requirement || ^4.0 Updates the requirements on [web-token/jwt-library](https://github.com/web-token/jwt-library) to permit the latest version. Updates `web-token/jwt-library` to 4.0.1 - [Commits](https://github.com/web-token/jwt-library/compare/3.4.0...4.0.1) --- updated-dependencies: - dependency-name: web-token/jwt-library dependency-type: direct:production dependency-group: production-dependencies ... Signed-off-by: dependabot[bot] * Abstract finals to decorators * Add coverage * Requre specific deps for GHA unit test run --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marko Ivancic --- .github/workflows/php.yml | 18 +++-- composer.json | 11 ++- src/Algorithms/AlgorithmManager.php | 9 --- src/Algorithms/AlgorithmManagerDecorator.php | 20 +++++ src/Core.php | 73 ++++++++++--------- src/Core/Factories/ClientAssertionFactory.php | 4 +- src/Core/Factories/RequestObjectFactory.php | 4 +- .../AlgorithmManagerDecoratorFactory.php | 21 ++++++ src/Factories/AlgorithmManagerFactory.php | 16 ---- .../JwsSerializerManagerDecoratorFactory.php | 21 ++++++ src/Factories/JwsSerializerManagerFactory.php | 16 ---- src/Federation.php | 57 ++++++++------- src/Federation/EntityStatement.php | 12 +-- .../Factories/EntityStatementFactory.php | 16 ++-- .../Factories/RequestObjectFactory.php | 4 +- src/Federation/Factories/TrustMarkFactory.php | 4 +- src/Jwks.php | 61 ++++++++-------- src/Jwks/Factories/SignedJwksFactory.php | 4 +- src/Jws/Factories/JwsParserFactory.php | 6 +- .../Factories/JwsVerifierDecoratorFactory.php | 21 ++++++ src/Jws/Factories/JwsVerifierFactory.php | 16 ---- src/Jws/Factories/ParsedJwsFactory.php | 12 +-- src/Jws/JwsParser.php | 6 +- src/Jws/JwsVerifier.php | 9 --- src/Jws/JwsVerifierDecorator.php | 35 +++++++++ src/Jws/ParsedJws.php | 25 +++---- src/Serializers/JwsSerializerManager.php | 9 --- .../JwsSerializerManagerDecorator.php | 31 ++++++++ ....php => AlgorithmManagerDecoratorTest.php} | 27 +++++-- tests/src/Core/ClientAssertionTest.php | 24 +++--- .../Factories/ClientAssertionFactoryTest.php | 24 +++--- .../Factories/RequestObjectFactoryTest.php | 24 +++--- tests/src/Core/RequestObjectTest.php | 24 +++--- tests/src/CoreTest.php | 18 +++-- ... AlgorithmManagerDecoratorFactoryTest.php} | 18 +++-- ...SerializerManagerDecoratorFactoryTest.php} | 18 ++--- tests/src/Federation/EntityStatementTest.php | 26 +++---- .../Factories/EntityStatementFactoryTest.php | 24 +++--- .../Factories/RequestObjectFactoryTest.php | 24 +++--- .../Factories/TrustMarkFactoryTest.php | 22 +++--- tests/src/Federation/RequestObjectTest.php | 24 +++--- tests/src/Federation/TrustMarkTest.php | 24 +++--- tests/src/FederationTest.php | 18 +++-- .../Jwks/Factories/SignedJwksFactoryTest.php | 24 +++--- tests/src/Jwks/SignedJwksTest.php | 24 +++--- tests/src/JwksTest.php | 18 +++-- .../Jws/Factories/JwsParserFactoryTest.php | 8 +- .../JwsVerifierDecoratorFactoryTest.php | 50 +++++++++++++ .../Jws/Factories/JwsVerifierFactoryTest.php | 46 ------------ .../Jws/Factories/ParsedJwsFactoryTest.php | 24 +++--- tests/src/Jws/JwsParserTest.php | 23 +++--- tests/src/Jws/JwsVerifierDecoratorTest.php | 60 +++++++++++++++ tests/src/Jws/ParsedJwsTest.php | 42 +++++------ .../JwsSerializerManagerDecoratorTest.php | 71 ++++++++++++++++++ 54 files changed, 761 insertions(+), 509 deletions(-) delete mode 100644 src/Algorithms/AlgorithmManager.php create mode 100644 src/Algorithms/AlgorithmManagerDecorator.php create mode 100644 src/Factories/AlgorithmManagerDecoratorFactory.php delete mode 100644 src/Factories/AlgorithmManagerFactory.php create mode 100644 src/Factories/JwsSerializerManagerDecoratorFactory.php delete mode 100644 src/Factories/JwsSerializerManagerFactory.php create mode 100644 src/Jws/Factories/JwsVerifierDecoratorFactory.php delete mode 100644 src/Jws/Factories/JwsVerifierFactory.php delete mode 100644 src/Jws/JwsVerifier.php create mode 100644 src/Jws/JwsVerifierDecorator.php delete mode 100644 src/Serializers/JwsSerializerManager.php create mode 100644 src/Serializers/JwsSerializerManagerDecorator.php rename tests/src/Algorithms/{AlgorithmManagerTest.php => AlgorithmManagerDecoratorTest.php} (50%) rename tests/src/Factories/{AlgorithmManagerFactoryTest.php => AlgorithmManagerDecoratorFactoryTest.php} (72%) rename tests/src/Factories/{JwsSerializerManagerFactoryTest.php => JwsSerializerManagerDecoratorFactoryTest.php} (72%) create mode 100644 tests/src/Jws/Factories/JwsVerifierDecoratorFactoryTest.php delete mode 100644 tests/src/Jws/Factories/JwsVerifierFactoryTest.php create mode 100644 tests/src/Jws/JwsVerifierDecoratorTest.php create mode 100644 tests/src/Serializers/JwsSerializerManagerDecoratorTest.php diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 94b4b27..10603d5 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -148,7 +148,7 @@ jobs: run: composer audit unit-tests-linux: - name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}" + name: "Unit tests, PHP ${{ matrix.php-versions }}, JWT ${{ matrix.jwt-version }}, ${{ matrix.operating-system }}" runs-on: ${{ matrix.operating-system }} needs: [linter, quality, security] strategy: @@ -156,6 +156,7 @@ jobs: matrix: operating-system: [ubuntu-latest] php-versions: ['8.2', '8.3'] + jwt-version: ['^3.4', '^4.0.2'] steps: - name: Setup PHP, with composer and extensions @@ -191,11 +192,14 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- + - name: Require specific dependencies + run: composer require web-token/jwt-framework:${{ matrix.jwt-version }} --no-update + - name: Install Composer dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Run unit tests with coverage - if: ${{ matrix.php-versions == '8.3' }} + if: ${{ matrix.php-versions == '8.3' && matrix.jwt-version == '^4.0.2' }} run: vendor/bin/phpunit - name: Run unit tests (no coverage) @@ -203,14 +207,14 @@ jobs: run: vendor/bin/phpunit --no-coverage - name: Save coverage data - if: ${{ matrix.php-versions == '8.3' }} + if: ${{ matrix.php-versions == '8.3' && matrix.jwt-version == '^4.0.2' }} uses: actions/upload-artifact@v4 with: name: coverage-data path: ${{ github.workspace }}/build unit-tests-windows: - name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}" + name: "Unit tests, PHP ${{ matrix.php-versions }}, JWT ${{ matrix.jwt-version }}, ${{ matrix.operating-system }}" runs-on: ${{ matrix.operating-system }} needs: [linter, quality, security] strategy: @@ -218,6 +222,7 @@ jobs: matrix: operating-system: [windows-latest] php-versions: ['8.2', '8.3'] + jwt-version: ['^3.4', '^4.0.2'] steps: - name: Setup PHP, with composer and extensions @@ -225,7 +230,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - extensions: ctype, date, dom, filter, hash, mbstring, openssl, pcre, soap, spl, xml + extensions: ctype, date, dom, filter, hash, mbstring, openssl, pcre, soap, spl, xml, sodium tools: composer ini-values: error_reporting=E_ALL coverage: none @@ -253,6 +258,9 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- + - name: Require specific dependencies + run: composer require web-token/jwt-framework:${{ matrix.jwt-version }} --no-update + - name: Install Composer dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader diff --git a/composer.json b/composer.json index c1bcac1..591f09b 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "psr/http-message": "^2", "psr/log": "^3", "psr/simple-cache": "^3", - "web-token/jwt-library": "^3.4" + "web-token/jwt-library": "^3.4 || ^4.0.2" }, "require-dev": { "phpstan/phpstan": "^2.1", @@ -49,10 +49,15 @@ }, "scripts": { "pre-commit": [ + "vendor/bin/phpcbf", "vendor/bin/phpcs -p", + "composer update web-token/jwt-framework --with web-token/jwt-framework:^3.0", "vendor/bin/psalm --no-cache", - "vendor/bin/rector --dry-run", - "vendor/bin/phpunit --no-coverage" + "vendor/bin/phpunit --no-coverage", + "composer update web-token/jwt-framework --with web-token/jwt-framework:^4.0", + "vendor/bin/psalm --no-cache", + "vendor/bin/phpunit --no-coverage", + "vendor/bin/rector --dry-run" ] } } diff --git a/src/Algorithms/AlgorithmManager.php b/src/Algorithms/AlgorithmManager.php deleted file mode 100644 index 2e03c33..0000000 --- a/src/Algorithms/AlgorithmManager.php +++ /dev/null @@ -1,9 +0,0 @@ -algorithmManager; + } +} diff --git a/src/Core.php b/src/Core.php index 2bb4470..26d96c8 100644 --- a/src/Core.php +++ b/src/Core.php @@ -11,29 +11,29 @@ use SimpleSAML\OpenID\Core\Factories\ClientAssertionFactory; use SimpleSAML\OpenID\Core\Factories\RequestObjectFactory; use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; -use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory; +use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory; use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory; -use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory; +use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\Factories\JwsParserFactory; -use SimpleSAML\OpenID\Jws\Factories\JwsVerifierFactory; +use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; class Core { protected DateIntervalDecorator $timestampValidationLeewayDecorator; - protected ?JwsSerializerManager $jwsSerializerManager = null; + protected ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null; protected ?JwsParser $jwsParser = null; - protected ?JwsVerifier $jwsVerifier = null; + protected ?JwsVerifierDecorator $jwsVerifierDecorator = null; protected ?RequestObjectFactory $requestObjectFactory = null; protected ?ClientAssertionFactory $clientAssertionFactory = null; protected ?Helpers $helpers = null; - protected ?AlgorithmManagerFactory $algorithmManagerFactory = null; - protected ?JwsSerializerManagerFactory $jwsSerializerManagerFactory = null; + protected ?AlgorithmManagerDecoratorFactory $algorithmManagerDecoratorFactory = null; + protected ?JwsSerializerManagerDecoratorFactory $jwsSerializerManagerDecoratorFactory = null; protected ?JwsParserFactory $jwsParserFactory = null; - protected ?JwsVerifierFactory $jwsVerifierFactory = null; + protected ?JwsVerifierDecoratorFactory $jwsVerifierDecoratorFactory = null; protected ?JwksFactory $jwksFactory = null; protected ?DateIntervalDecoratorFactory $dateIntervalDecoratorFactory = null; @@ -56,9 +56,9 @@ public function requestObjectFactory(): RequestObjectFactory { return $this->requestObjectFactory ??= new RequestObjectFactory( $this->jwsParser(), - $this->jwsVerifier(), + $this->jwsVerifierDecorator(), $this->jwksFactory(), - $this->jwsSerializerManager(), + $this->jwsSerializerManagerDecorator(), $this->timestampValidationLeewayDecorator, $this->helpers(), ); @@ -68,9 +68,9 @@ public function clientAssertionFactory(): ClientAssertionFactory { return $this->clientAssertionFactory ??= new ClientAssertionFactory( $this->jwsParser(), - $this->jwsVerifier(), + $this->jwsVerifierDecorator(), $this->jwksFactory(), - $this->jwsSerializerManager(), + $this->jwsSerializerManagerDecorator(), $this->timestampValidationLeewayDecorator, $this->helpers(), ); @@ -81,20 +81,20 @@ public function helpers(): Helpers return $this->helpers ??= new Helpers(); } - public function algorithmManagerFactory(): AlgorithmManagerFactory + public function algorithmManagerDecoratorFactory(): AlgorithmManagerDecoratorFactory { - if (is_null($this->algorithmManagerFactory)) { - $this->algorithmManagerFactory = new AlgorithmManagerFactory(); + if (is_null($this->algorithmManagerDecoratorFactory)) { + $this->algorithmManagerDecoratorFactory = new AlgorithmManagerDecoratorFactory(); } - return $this->algorithmManagerFactory; + return $this->algorithmManagerDecoratorFactory; } - public function jwsSerializerManagerFactory(): JwsSerializerManagerFactory + public function jwsSerializerManagerDecoratorFactory(): JwsSerializerManagerDecoratorFactory { - if (is_null($this->jwsSerializerManagerFactory)) { - $this->jwsSerializerManagerFactory = new JwsSerializerManagerFactory(); + if (is_null($this->jwsSerializerManagerDecoratorFactory)) { + $this->jwsSerializerManagerDecoratorFactory = new JwsSerializerManagerDecoratorFactory(); } - return $this->jwsSerializerManagerFactory; + return $this->jwsSerializerManagerDecoratorFactory; } public function jwsParserFactory(): JwsParserFactory @@ -105,12 +105,12 @@ public function jwsParserFactory(): JwsParserFactory return $this->jwsParserFactory; } - public function jwsVerifierFactory(): JwsVerifierFactory + public function jwsVerifierDecoratorFactory(): JwsVerifierDecoratorFactory { - if (is_null($this->jwsVerifierFactory)) { - $this->jwsVerifierFactory = new JwsVerifierFactory(); + if (is_null($this->jwsVerifierDecoratorFactory)) { + $this->jwsVerifierDecoratorFactory = new JwsVerifierDecoratorFactory(); } - return $this->jwsVerifierFactory; + return $this->jwsVerifierDecoratorFactory; } public function jwksFactory(): JwksFactory @@ -127,29 +127,30 @@ public function dateIntervalDecoratorFactory(): DateIntervalDecoratorFactory return $this->dateIntervalDecoratorFactory; } - public function jwsSerializerManager(): JwsSerializerManager + public function jwsSerializerManagerDecorator(): JwsSerializerManagerDecorator { - if (is_null($this->jwsSerializerManager)) { - $this->jwsSerializerManager = $this->jwsSerializerManagerFactory()->build($this->supportedSerializers); + if (is_null($this->jwsSerializerManagerDecorator)) { + $this->jwsSerializerManagerDecorator = $this->jwsSerializerManagerDecoratorFactory() + ->build($this->supportedSerializers); } - return $this->jwsSerializerManager; + return $this->jwsSerializerManagerDecorator; } public function jwsParser(): JwsParser { if (is_null($this->jwsParser)) { - $this->jwsParser = $this->jwsParserFactory()->build($this->jwsSerializerManager()); + $this->jwsParser = $this->jwsParserFactory()->build($this->jwsSerializerManagerDecorator()); } return $this->jwsParser; } - public function jwsVerifier(): JwsVerifier + public function jwsVerifierDecorator(): JwsVerifierDecorator { - if (is_null($this->jwsVerifier)) { - $this->jwsVerifier = $this->jwsVerifierFactory()->build( - $this->algorithmManagerFactory()->build($this->supportedAlgorithms), + if (is_null($this->jwsVerifierDecorator)) { + $this->jwsVerifierDecorator = $this->jwsVerifierDecoratorFactory()->build( + $this->algorithmManagerDecoratorFactory()->build($this->supportedAlgorithms), ); } - return $this->jwsVerifier; + return $this->jwsVerifierDecorator; } } diff --git a/src/Core/Factories/ClientAssertionFactory.php b/src/Core/Factories/ClientAssertionFactory.php index fb34df8..ccb17b6 100644 --- a/src/Core/Factories/ClientAssertionFactory.php +++ b/src/Core/Factories/ClientAssertionFactory.php @@ -13,9 +13,9 @@ public function fromToken(string $token): ClientAssertion { return new ClientAssertion( $this->jwsParser->parse($token), - $this->jwsVerifier, + $this->jwsVerifierDecorator, $this->jwksFactory, - $this->jwsSerializerManager, + $this->jwsSerializerManagerDecorator, $this->timestampValidationLeeway, $this->helpers, ); diff --git a/src/Core/Factories/RequestObjectFactory.php b/src/Core/Factories/RequestObjectFactory.php index 6524c2d..6d12bfe 100644 --- a/src/Core/Factories/RequestObjectFactory.php +++ b/src/Core/Factories/RequestObjectFactory.php @@ -13,9 +13,9 @@ public function fromToken(string $token): RequestObject { return new RequestObject( $this->jwsParser->parse($token), - $this->jwsVerifier, + $this->jwsVerifierDecorator, $this->jwksFactory, - $this->jwsSerializerManager, + $this->jwsSerializerManagerDecorator, $this->timestampValidationLeeway, $this->helpers, ); diff --git a/src/Factories/AlgorithmManagerDecoratorFactory.php b/src/Factories/AlgorithmManagerDecoratorFactory.php new file mode 100644 index 0000000..625cde6 --- /dev/null +++ b/src/Factories/AlgorithmManagerDecoratorFactory.php @@ -0,0 +1,21 @@ +getSignatureAlgorithmBag()->getAllInstances(), + ), + ); + } +} diff --git a/src/Factories/AlgorithmManagerFactory.php b/src/Factories/AlgorithmManagerFactory.php deleted file mode 100644 index aadbf74..0000000 --- a/src/Factories/AlgorithmManagerFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -getSignatureAlgorithmBag()->getAllInstances()); - } -} diff --git a/src/Factories/JwsSerializerManagerDecoratorFactory.php b/src/Factories/JwsSerializerManagerDecoratorFactory.php new file mode 100644 index 0000000..31c33d8 --- /dev/null +++ b/src/Factories/JwsSerializerManagerDecoratorFactory.php @@ -0,0 +1,21 @@ +getJwsSerializerBag()->getAllInstances(), + ), + ); + } +} diff --git a/src/Factories/JwsSerializerManagerFactory.php b/src/Factories/JwsSerializerManagerFactory.php deleted file mode 100644 index de8b933..0000000 --- a/src/Factories/JwsSerializerManagerFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -getJwsSerializerBag()->getAllInstances()); - } -} diff --git a/src/Federation.php b/src/Federation.php index 6791747..666b803 100644 --- a/src/Federation.php +++ b/src/Federation.php @@ -11,11 +11,11 @@ use SimpleSAML\OpenID\Decorators\CacheDecorator; use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; use SimpleSAML\OpenID\Decorators\HttpClientDecorator; -use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory; +use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory; use SimpleSAML\OpenID\Factories\CacheDecoratorFactory; use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory; use SimpleSAML\OpenID\Factories\HttpClientDecoratorFactory; -use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory; +use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory; use SimpleSAML\OpenID\Federation\EntityStatement\Factories\TrustMarkClaimBagFactory; use SimpleSAML\OpenID\Federation\EntityStatement\Factories\TrustMarkClaimFactory; use SimpleSAML\OpenID\Federation\EntityStatementFetcher; @@ -29,10 +29,10 @@ use SimpleSAML\OpenID\Federation\TrustChainResolver; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\Factories\JwsParserFactory; -use SimpleSAML\OpenID\Jws\Factories\JwsVerifierFactory; +use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; use SimpleSAML\OpenID\Utils\ArtifactFetcher; class Federation @@ -42,9 +42,9 @@ class Federation protected int $maxTrustChainDepth; protected ?CacheDecorator $cacheDecorator; protected HttpClientDecorator $httpClientDecorator; - protected ?JwsSerializerManager $jwsSerializerManager = null; + protected ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null; protected ?JwsParser $jwsParser = null; - protected ?JwsVerifier $jwsVerifier = null; + protected ?JwsVerifierDecorator $jwsVerifierDecorator = null; protected ?EntityStatementFetcher $entityStatementFetcher = null; protected ?MetadataPolicyResolver $metadataPolicyResolver = null; protected ?MetadataPolicyApplicator $metadataPolicyApplicator = null; @@ -56,10 +56,10 @@ class Federation protected ?TrustMarkClaimFactory $trustMarkClaimFactory = null; protected ?TrustMarkClaimBagFactory $trustMarkClaimBagFactory = null; protected ?Helpers $helpers = null; - protected ?AlgorithmManagerFactory $algorithmManagerFactory = null; - protected ?JwsSerializerManagerFactory $jwsSerializerManagerFactory = null; + protected ?AlgorithmManagerDecoratorFactory $algorithmManagerDecoratorFactory = null; + protected ?JwsSerializerManagerDecoratorFactory $jwsSerializerManagerDecoratorFactory = null; protected ?JwsParserFactory $jwsParserFactory = null; - protected ?JwsVerifierFactory $jwsVerifierFactory = null; + protected ?JwsVerifierDecoratorFactory $jwsVerifierDecoratorFactory = null; protected ?JwksFactory $jwksFactory = null; protected ?DateIntervalDecoratorFactory $dateIntervalDecoratorFactory = null; protected ?HttpClientDecoratorFactory $httpClientDecoratorFactory = null; @@ -85,21 +85,22 @@ public function __construct( $this->httpClientDecorator = $this->httpClientDecoratorFactory()->build($client); } - public function jwsVerifier(): JwsVerifier + public function jwsVerifierDecorator(): JwsVerifierDecorator { - return $this->jwsVerifier ??= $this->jwsVerifierFactory()->build( - $this->algorithmManagerFactory()->build($this->supportedAlgorithms), + return $this->jwsVerifierDecorator ??= $this->jwsVerifierDecoratorFactory()->build( + $this->algorithmManagerDecoratorFactory()->build($this->supportedAlgorithms), ); } public function jwsParser(): JwsParser { - return $this->jwsParser ??= $this->jwsParserFactory()->build($this->jwsSerializerManager()); + return $this->jwsParser ??= $this->jwsParserFactory()->build($this->jwsSerializerManagerDecorator()); } - public function jwsSerializerManager(): JwsSerializerManager + public function jwsSerializerManagerDecorator(): JwsSerializerManagerDecorator { - return $this->jwsSerializerManager ??= $this->jwsSerializerManagerFactory()->build($this->supportedSerializers); + return $this->jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorFactory() + ->build($this->supportedSerializers); } public function entityStatementFetcher(): EntityStatementFetcher @@ -150,9 +151,9 @@ public function entityStatementFactory(): EntityStatementFactory { return $this->entityStatementFactory ??= new EntityStatementFactory( $this->jwsParser(), - $this->jwsVerifier(), + $this->jwsVerifierDecorator(), $this->jwksFactory(), - $this->jwsSerializerManager(), + $this->jwsSerializerManagerDecorator(), $this->timestampValidationLeewayDecorator, $this->helpers(), $this->trustMarkClaimFactory(), @@ -164,9 +165,9 @@ public function requestObjectFactory(): RequestObjectFactory { return $this->requestObjectFactory ??= new RequestObjectFactory( $this->jwsParser(), - $this->jwsVerifier(), + $this->jwsVerifierDecorator(), $this->jwksFactory(), - $this->jwsSerializerManager(), + $this->jwsSerializerManagerDecorator(), $this->timestampValidationLeewayDecorator, $this->helpers(), ); @@ -176,9 +177,9 @@ public function trustMarkFactory(): TrustMarkFactory { return $this->trustMarkFactory ??= new TrustMarkFactory( $this->jwsParser(), - $this->jwsVerifier(), + $this->jwsVerifierDecorator(), $this->jwksFactory(), - $this->jwsSerializerManager(), + $this->jwsSerializerManagerDecorator(), $this->timestampValidationLeewayDecorator, $this->helpers(), ); @@ -194,14 +195,14 @@ public function helpers(): Helpers return $this->helpers ??= new Helpers(); } - public function algorithmManagerFactory(): AlgorithmManagerFactory + public function algorithmManagerDecoratorFactory(): AlgorithmManagerDecoratorFactory { - return $this->algorithmManagerFactory ??= new AlgorithmManagerFactory(); + return $this->algorithmManagerDecoratorFactory ??= new AlgorithmManagerDecoratorFactory(); } - public function jwsSerializerManagerFactory(): JwsSerializerManagerFactory + public function jwsSerializerManagerDecoratorFactory(): JwsSerializerManagerDecoratorFactory { - return $this->jwsSerializerManagerFactory ??= new JwsSerializerManagerFactory(); + return $this->jwsSerializerManagerDecoratorFactory ??= new JwsSerializerManagerDecoratorFactory(); } public function jwsParserFactory(): JwsParserFactory @@ -209,9 +210,9 @@ public function jwsParserFactory(): JwsParserFactory return $this->jwsParserFactory ??= new JwsParserFactory(); } - public function jwsVerifierFactory(): JwsVerifierFactory + public function jwsVerifierDecoratorFactory(): JwsVerifierDecoratorFactory { - return $this->jwsVerifierFactory ??= new JwsVerifierFactory(); + return $this->jwsVerifierDecoratorFactory ??= new JwsVerifierDecoratorFactory(); } public function jwksFactory(): JwksFactory diff --git a/src/Federation/EntityStatement.php b/src/Federation/EntityStatement.php index c7ecabc..c680acb 100644 --- a/src/Federation/EntityStatement.php +++ b/src/Federation/EntityStatement.php @@ -16,17 +16,17 @@ use SimpleSAML\OpenID\Helpers; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; class EntityStatement extends ParsedJws { public function __construct( JwsDecorator $jwsDecorator, - JwsVerifier $jwsVerifier, + JwsVerifierDecorator $jwsVerifierDecorator, JwksFactory $jwksFactory, - JwsSerializerManager $jwsSerializerManager, + JwsSerializerManagerDecorator $jwsSerializerManagerDecorator, DateIntervalDecorator $timestampValidationLeeway, Helpers $helpers, protected readonly TrustMarkClaimFactory $trustMarkClaimFactory, @@ -34,9 +34,9 @@ public function __construct( ) { parent::__construct( $jwsDecorator, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $timestampValidationLeeway, $helpers, ); diff --git a/src/Federation/Factories/EntityStatementFactory.php b/src/Federation/Factories/EntityStatementFactory.php index 9500c75..751f7a2 100644 --- a/src/Federation/Factories/EntityStatementFactory.php +++ b/src/Federation/Factories/EntityStatementFactory.php @@ -12,16 +12,16 @@ use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; class EntityStatementFactory extends ParsedJwsFactory { public function __construct( JwsParser $jwsParser, - JwsVerifier $jwsVerifier, + JwsVerifierDecorator $jwsVerifierDecorator, JwksFactory $jwksFactory, - JwsSerializerManager $jwsSerializerManager, + JwsSerializerManagerDecorator $jwsSerializerManagerDecorator, DateIntervalDecorator $timestampValidationLeeway, Helpers $helpers, protected readonly TrustMarkClaimFactory $trustMarkClaimFactory, @@ -29,9 +29,9 @@ public function __construct( ) { parent::__construct( $jwsParser, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $timestampValidationLeeway, $helpers, ); @@ -44,9 +44,9 @@ public function fromToken(string $token): EntityStatement { return new EntityStatement( $this->jwsParser->parse($token), - $this->jwsVerifier, + $this->jwsVerifierDecorator, $this->jwksFactory, - $this->jwsSerializerManager, + $this->jwsSerializerManagerDecorator, $this->timestampValidationLeeway, $this->helpers, $this->trustMarkClaimFactory, diff --git a/src/Federation/Factories/RequestObjectFactory.php b/src/Federation/Factories/RequestObjectFactory.php index aeeda1e..ebb9403 100644 --- a/src/Federation/Factories/RequestObjectFactory.php +++ b/src/Federation/Factories/RequestObjectFactory.php @@ -17,9 +17,9 @@ public function fromToken(string $token): RequestObject { return new RequestObject( $this->jwsParser->parse($token), - $this->jwsVerifier, + $this->jwsVerifierDecorator, $this->jwksFactory, - $this->jwsSerializerManager, + $this->jwsSerializerManagerDecorator, $this->timestampValidationLeeway, $this->helpers, ); diff --git a/src/Federation/Factories/TrustMarkFactory.php b/src/Federation/Factories/TrustMarkFactory.php index 42cd256..6d5baff 100644 --- a/src/Federation/Factories/TrustMarkFactory.php +++ b/src/Federation/Factories/TrustMarkFactory.php @@ -13,9 +13,9 @@ public function fromToken(string $token): TrustMark { return new TrustMark( $this->jwsParser->parse($token), - $this->jwsVerifier, + $this->jwsVerifierDecorator, $this->jwksFactory, - $this->jwsSerializerManager, + $this->jwsSerializerManagerDecorator, $this->timestampValidationLeeway, $this->helpers, ); diff --git a/src/Jwks.php b/src/Jwks.php index c5b3def..f231639 100644 --- a/src/Jwks.php +++ b/src/Jwks.php @@ -11,19 +11,19 @@ use SimpleSAML\OpenID\Decorators\CacheDecorator; use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; use SimpleSAML\OpenID\Decorators\HttpClientDecorator; -use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory; +use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory; use SimpleSAML\OpenID\Factories\CacheDecoratorFactory; use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory; use SimpleSAML\OpenID\Factories\HttpClientDecoratorFactory; -use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory; +use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jwks\Factories\SignedJwksFactory; use SimpleSAML\OpenID\Jwks\JwksFetcher; use SimpleSAML\OpenID\Jws\Factories\JwsParserFactory; -use SimpleSAML\OpenID\Jws\Factories\JwsVerifierFactory; +use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; class Jwks { @@ -32,16 +32,16 @@ class Jwks protected ?CacheDecorator $cacheDecorator; protected ?JwksFetcher $jwksFetcher = null; protected HttpClientDecorator $httpClientDecorator; - protected ?JwsSerializerManager $jwsSerializerManager = null; + protected ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null; protected ?JwsParser $jwsParser = null; - protected ?JwsVerifier $jwsVerifier = null; + protected ?JwsVerifierDecorator $jwsVerifierDecorator = null; protected ?JwksFactory $jwksFactory = null; protected ?SignedJwksFactory $signedJwksFactory = null; protected ?Helpers $helpers = null; - protected ?AlgorithmManagerFactory $algorithmManagerFactory = null; - protected ?JwsSerializerManagerFactory $jwsSerializerManagerFactory = null; + protected ?AlgorithmManagerDecoratorFactory $algorithmManagerDecoratorFactory = null; + protected ?JwsSerializerManagerDecoratorFactory $jwsSerializerManagerDecoratorFactory = null; protected ?JwsParserFactory $jwsParserFactory = null; - protected ?JwsVerifierFactory $jwsVerifierFactory = null; + protected ?JwsVerifierDecoratorFactory $jwsVerifierDecoratorFactory = null; protected ?DateIntervalDecoratorFactory $dateIntervalDecoratorFactory = null; protected ?CacheDecoratorFactory $cacheDecoratorFactory = null; protected ?HttpClientDecoratorFactory $httpClientDecoratorFactory = null; @@ -71,9 +71,9 @@ public function signedJwksFactory(): SignedJwksFactory { return $this->signedJwksFactory ??= new SignedJwksFactory( $this->jwsParser(), - $this->jwsVerifier(), + $this->jwsVerifierDecorator(), $this->jwksFactory(), - $this->jwsSerializerManager(), + $this->jwsSerializerManagerDecorator(), $this->timestampValidationLeewayDecorator, $this->helpers(), ); @@ -97,20 +97,20 @@ public function helpers(): Helpers return $this->helpers ??= new Helpers(); } - public function algorithmManagerFactory(): AlgorithmManagerFactory + public function algorithmManagerDecoratorFactory(): AlgorithmManagerDecoratorFactory { - if (is_null($this->algorithmManagerFactory)) { - $this->algorithmManagerFactory = new AlgorithmManagerFactory(); + if (is_null($this->algorithmManagerDecoratorFactory)) { + $this->algorithmManagerDecoratorFactory = new AlgorithmManagerDecoratorFactory(); } - return $this->algorithmManagerFactory; + return $this->algorithmManagerDecoratorFactory; } - public function jwsSerializerManagerFactory(): JwsSerializerManagerFactory + public function jwsSerializerManagerDecoratorFactory(): JwsSerializerManagerDecoratorFactory { - if (is_null($this->jwsSerializerManagerFactory)) { - $this->jwsSerializerManagerFactory = new JwsSerializerManagerFactory(); + if (is_null($this->jwsSerializerManagerDecoratorFactory)) { + $this->jwsSerializerManagerDecoratorFactory = new JwsSerializerManagerDecoratorFactory(); } - return $this->jwsSerializerManagerFactory; + return $this->jwsSerializerManagerDecoratorFactory; } public function jwsParserFactory(): JwsParserFactory @@ -121,12 +121,12 @@ public function jwsParserFactory(): JwsParserFactory return $this->jwsParserFactory; } - public function jwsVerifierFactory(): JwsVerifierFactory + public function jwsVerifierDecoratorFactory(): JwsVerifierDecoratorFactory { - if (is_null($this->jwsVerifierFactory)) { - $this->jwsVerifierFactory = new JwsVerifierFactory(); + if (is_null($this->jwsVerifierDecoratorFactory)) { + $this->jwsVerifierDecoratorFactory = new JwsVerifierDecoratorFactory(); } - return $this->jwsVerifierFactory; + return $this->jwsVerifierDecoratorFactory; } public function dateIntervalDecoratorFactory(): DateIntervalDecoratorFactory @@ -156,20 +156,21 @@ public function httpClientDecoratorFactory(): HttpClientDecoratorFactory return $this->httpClientDecoratorFactory; } - public function jwsVerifier(): JwsVerifier + public function jwsVerifierDecorator(): JwsVerifierDecorator { - return $this->jwsVerifier ??= $this->jwsVerifierFactory()->build( - $this->algorithmManagerFactory()->build($this->supportedAlgorithms), + return $this->jwsVerifierDecorator ??= $this->jwsVerifierDecoratorFactory()->build( + $this->algorithmManagerDecoratorFactory()->build($this->supportedAlgorithms), ); } public function jwsParser(): JwsParser { - return $this->jwsParser ??= $this->jwsParserFactory()->build($this->jwsSerializerManager()); + return $this->jwsParser ??= $this->jwsParserFactory()->build($this->jwsSerializerManagerDecorator()); } - public function jwsSerializerManager(): JwsSerializerManager + public function jwsSerializerManagerDecorator(): JwsSerializerManagerDecorator { - return $this->jwsSerializerManager ??= $this->jwsSerializerManagerFactory()->build($this->supportedSerializers); + return $this->jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorFactory() + ->build($this->supportedSerializers); } } diff --git a/src/Jwks/Factories/SignedJwksFactory.php b/src/Jwks/Factories/SignedJwksFactory.php index 5e15116..2abb7e6 100644 --- a/src/Jwks/Factories/SignedJwksFactory.php +++ b/src/Jwks/Factories/SignedJwksFactory.php @@ -16,9 +16,9 @@ public function fromToken(string $token): SignedJwks { return new SignedJwks( $this->jwsParser->parse($token), - $this->jwsVerifier, + $this->jwsVerifierDecorator, $this->jwksFactory, - $this->jwsSerializerManager, + $this->jwsSerializerManagerDecorator, $this->timestampValidationLeeway, $this->helpers, ); diff --git a/src/Jws/Factories/JwsParserFactory.php b/src/Jws/Factories/JwsParserFactory.php index 44f7535..d637963 100644 --- a/src/Jws/Factories/JwsParserFactory.php +++ b/src/Jws/Factories/JwsParserFactory.php @@ -5,12 +5,12 @@ namespace SimpleSAML\OpenID\Jws\Factories; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; class JwsParserFactory { - public function build(JwsSerializerManager $jwsSerializerManager): JwsParser + public function build(JwsSerializerManagerDecorator $jwsSerializerManagerDecorator): JwsParser { - return new JwsParser($jwsSerializerManager); + return new JwsParser($jwsSerializerManagerDecorator); } } diff --git a/src/Jws/Factories/JwsVerifierDecoratorFactory.php b/src/Jws/Factories/JwsVerifierDecoratorFactory.php new file mode 100644 index 0000000..8c482da --- /dev/null +++ b/src/Jws/Factories/JwsVerifierDecoratorFactory.php @@ -0,0 +1,21 @@ +algorithmManager(), + ), + ); + } +} diff --git a/src/Jws/Factories/JwsVerifierFactory.php b/src/Jws/Factories/JwsVerifierFactory.php deleted file mode 100644 index ec4013c..0000000 --- a/src/Jws/Factories/JwsVerifierFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -jwsParser->parse($token), - $this->jwsVerifier, + $this->jwsVerifierDecorator, $this->jwksFactory, - $this->jwsSerializerManager, + $this->jwsSerializerManagerDecorator, $this->timestampValidationLeeway, $this->helpers, ); diff --git a/src/Jws/JwsParser.php b/src/Jws/JwsParser.php index 5e2eaff..467799b 100644 --- a/src/Jws/JwsParser.php +++ b/src/Jws/JwsParser.php @@ -5,13 +5,13 @@ namespace SimpleSAML\OpenID\Jws; use SimpleSAML\OpenID\Exceptions\JwsException; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; use Throwable; class JwsParser { public function __construct( - protected readonly JwsSerializerManager $serializerManager, + protected readonly JwsSerializerManagerDecorator $serializerManagerDecorator, ) { } @@ -21,7 +21,7 @@ public function __construct( public function parse(string $token): JwsDecorator { try { - return new JwsDecorator($this->serializerManager->unserialize($token)); + return $this->serializerManagerDecorator->unserialize($token); } catch (Throwable $exception) { throw new JwsException('Unable to parse token.', (int)$exception->getCode(), $exception); } diff --git a/src/Jws/JwsVerifier.php b/src/Jws/JwsVerifier.php deleted file mode 100644 index 6c6db2a..0000000 --- a/src/Jws/JwsVerifier.php +++ /dev/null @@ -1,9 +0,0 @@ -jwsVerifier; + } + + public function verifyWithKeySet( + JwsDecorator $jwsDecorator, + JwksDecorator $jwksDecorator, + int $signatureIndex, + ?string $detachedPayload = null, + ): bool { + return $this->jwsVerifier->verifyWithKeySet( + $jwsDecorator->jws(), + $jwksDecorator->jwks(), + $signatureIndex, + $detachedPayload, + ); + } +} diff --git a/src/Jws/ParsedJws.php b/src/Jws/ParsedJws.php index ef9f64c..4f2f282 100644 --- a/src/Jws/ParsedJws.php +++ b/src/Jws/ParsedJws.php @@ -4,7 +4,6 @@ namespace SimpleSAML\OpenID\Jws; -use Jose\Component\Signature\JWS; use JsonException; use SimpleSAML\OpenID\Codebooks\ClaimsEnum; use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; @@ -12,12 +11,11 @@ use SimpleSAML\OpenID\Helpers; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Serializers\JwsSerializerEnum; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; use Throwable; class ParsedJws { - protected JWS $jws; /** * @var array */ @@ -30,14 +28,13 @@ class ParsedJws protected ?string $token = null; public function __construct( - JwsDecorator $jwsDecorator, - protected readonly JwsVerifier $jwsVerifier, + protected readonly JwsDecorator $jwsDecorator, + protected readonly JwsVerifierDecorator $jwsVerifierDecorator, protected readonly JwksFactory $jwksFactory, - protected readonly JwsSerializerManager $jwsSerializerManager, + protected readonly JwsSerializerManagerDecorator $jwsSerializerManagerDecorator, protected readonly DateIntervalDecorator $timestampValidationLeeway, protected readonly Helpers $helpers, ) { - $this->jws = $jwsDecorator->jws(); $this->validate(); } @@ -103,7 +100,7 @@ public function getHeader(int $signatureId = 0): array { try { /** @psalm-suppress MixedAssignment */ - return $this->header ??= $this->jws->getSignature($signatureId)->getProtectedHeader(); + return $this->header ??= $this->jwsDecorator->jws()->getSignature($signatureId)->getProtectedHeader(); } catch (Throwable $exception) { throw new JwsException('Unable to get protected header.', (int)$exception->getCode(), $exception); } @@ -130,9 +127,9 @@ public function getToken( JwsSerializerEnum $jwsSerializerEnum = JwsSerializerEnum::Compact, ?int $signatureIndex = null, ): string { - return $this->token ??= $this->jwsSerializerManager->serialize( + return $this->token ??= $this->jwsSerializerManagerDecorator->serialize( $jwsSerializerEnum->value, - $this->jws, + $this->jwsDecorator, $signatureIndex, ); } @@ -147,7 +144,7 @@ public function getPayload(): array return $this->payload; } - $payloadString = $this->jws->getPayload(); + $payloadString = $this->jwsDecorator->jws()->getPayload(); if ($payloadString === null || $payloadString === '' || $payloadString === '0') { return $this->payload = []; } @@ -168,9 +165,9 @@ public function getPayload(): array public function verifyWithKeySet(array $jwks, int $signatureIndex = 0): void { if ( - !$this->jwsVerifier->verifyWithKeySet( - $this->jws, - $this->jwksFactory->fromKeyData($jwks)->jwks(), + !$this->jwsVerifierDecorator->verifyWithKeySet( + $this->jwsDecorator, + $this->jwksFactory->fromKeyData($jwks), $signatureIndex, ) ) { diff --git a/src/Serializers/JwsSerializerManager.php b/src/Serializers/JwsSerializerManager.php deleted file mode 100644 index cf5cffe..0000000 --- a/src/Serializers/JwsSerializerManager.php +++ /dev/null @@ -1,9 +0,0 @@ -jwsSerializerManager; + } + + public function serialize(string $name, JwsDecorator $jwsDecorator, ?int $signatureIndex = null): string + { + return $this->jwsSerializerManager()->serialize($name, $jwsDecorator->jws(), $signatureIndex); + } + + public function unserialize(string $input, ?string &$name = null): JwsDecorator + { + return new JwsDecorator($this->jwsSerializerManager()->unserialize($input, $name)); + } +} diff --git a/tests/src/Algorithms/AlgorithmManagerTest.php b/tests/src/Algorithms/AlgorithmManagerDecoratorTest.php similarity index 50% rename from tests/src/Algorithms/AlgorithmManagerTest.php rename to tests/src/Algorithms/AlgorithmManagerDecoratorTest.php index 02bcb66..a6a5e16 100644 --- a/tests/src/Algorithms/AlgorithmManagerTest.php +++ b/tests/src/Algorithms/AlgorithmManagerDecoratorTest.php @@ -4,33 +4,44 @@ namespace SimpleSAML\Test\OpenID\Algorithms; +use Jose\Component\Core\AlgorithmManager; use Jose\Component\Signature\Algorithm\SignatureAlgorithm; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use SimpleSAML\OpenID\Algorithms\AlgorithmManager; +use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator; -#[CoversClass(AlgorithmManager::class)] -class AlgorithmManagerTest extends TestCase +#[CoversClass(AlgorithmManagerDecorator::class)] +class AlgorithmManagerDecoratorTest extends TestCase { protected MockObject $signatureAlgorithmMock; /** @var \PHPUnit\Framework\MockObject\MockObject[] */ protected array $signatureAlgorithmMocks; + protected AlgorithmManager $algorithmManager; protected function setUp(): void { $this->signatureAlgorithmMock = $this->createMock(SignatureAlgorithm::class); $this->signatureAlgorithmMocks[] = $this->signatureAlgorithmMock; + + $this->algorithmManager = new AlgorithmManager($this->signatureAlgorithmMocks); } - protected function sut(?array $signatureAlgorithms = null): AlgorithmManager - { - $signatureAlgorithms ??= $this->signatureAlgorithmMocks; - return new AlgorithmManager($signatureAlgorithms); + protected function sut( + ?AlgorithmManager $algorithmManager = null, + ): AlgorithmManagerDecorator { + $algorithmManager ??= $this->algorithmManager; + + return new AlgorithmManagerDecorator($algorithmManager); } public function testCanCreateInstance(): void { - $this->assertInstanceOf(AlgorithmManager::class, $this->sut()); + $this->assertInstanceOf(AlgorithmManagerDecorator::class, $this->sut()); + } + + public function testCanGetAlgorithmManager(): void + { + $this->assertInstanceOf(AlgorithmManager::class, $this->sut()->algorithmManager()); } } diff --git a/tests/src/Core/ClientAssertionTest.php b/tests/src/Core/ClientAssertionTest.php index e922a7b..23077cb 100644 --- a/tests/src/Core/ClientAssertionTest.php +++ b/tests/src/Core/ClientAssertionTest.php @@ -15,9 +15,9 @@ use SimpleSAML\OpenID\Helpers; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(ClientAssertion::class)] #[UsesClass(ParsedJws::class)] @@ -25,9 +25,9 @@ class ClientAssertionTest extends TestCase { protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -56,9 +56,9 @@ protected function setUp(): void $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); $this->jwsDecoratorMock->method('jws')->willReturn($this->jwsMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -71,24 +71,24 @@ protected function setUp(): void protected function sut( ?JwsDecorator $jwsDecorator = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): ClientAssertion { $jwsDecorator ??= $this->jwsDecoratorMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new ClientAssertion( $jwsDecorator, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/Core/Factories/ClientAssertionFactoryTest.php b/tests/src/Core/Factories/ClientAssertionFactoryTest.php index 6b9d707..aa57e7c 100644 --- a/tests/src/Core/Factories/ClientAssertionFactoryTest.php +++ b/tests/src/Core/Factories/ClientAssertionFactoryTest.php @@ -17,9 +17,9 @@ use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(ClientAssertionFactory::class)] #[UsesClass(ParsedJwsFactory::class)] @@ -30,9 +30,9 @@ class ClientAssertionFactoryTest extends TestCase protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; protected MockObject $jwsParserMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -65,9 +65,9 @@ protected function setUp(): void $this->jwsParserMock = $this->createMock(JwsParser::class); $this->jwsParserMock->method('parse')->willReturn($this->jwsDecoratorMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -80,24 +80,24 @@ protected function setUp(): void protected function sut( ?JwsParser $jwsParser = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): ClientAssertionFactory { $jwsParser ??= $this->jwsParserMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new ClientAssertionFactory( $jwsParser, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/Core/Factories/RequestObjectFactoryTest.php b/tests/src/Core/Factories/RequestObjectFactoryTest.php index f0723cb..e929b0d 100644 --- a/tests/src/Core/Factories/RequestObjectFactoryTest.php +++ b/tests/src/Core/Factories/RequestObjectFactoryTest.php @@ -18,9 +18,9 @@ use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(RequestObjectFactory::class)] #[UsesClass(ParsedJwsFactory::class)] @@ -31,9 +31,9 @@ class RequestObjectFactoryTest extends TestCase protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; protected MockObject $jwsParserMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -57,9 +57,9 @@ protected function setUp(): void $this->jwsParserMock = $this->createMock(JwsParser::class); $this->jwsParserMock->method('parse')->willReturn($this->jwsDecoratorMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -69,24 +69,24 @@ protected function setUp(): void protected function sut( ?JwsParser $jwsParser = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): RequestObjectFactory { $jwsParser ??= $this->jwsParserMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new RequestObjectFactory( $jwsParser, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/Core/RequestObjectTest.php b/tests/src/Core/RequestObjectTest.php index bdadafa..6b17101 100644 --- a/tests/src/Core/RequestObjectTest.php +++ b/tests/src/Core/RequestObjectTest.php @@ -16,9 +16,9 @@ use SimpleSAML\OpenID\Helpers; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(RequestObject::class)] #[UsesClass(ParsedJws::class)] @@ -27,9 +27,9 @@ class RequestObjectTest extends TestCase protected MockObject $signatureMock; protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -50,9 +50,9 @@ protected function setUp(): void $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); $this->jwsDecoratorMock->method('jws')->willReturn($this->jwsMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -62,24 +62,24 @@ protected function setUp(): void protected function sut( ?JwsDecorator $jwsDecorator = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): RequestObject { $jwsDecorator ??= $this->jwsDecoratorMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new RequestObject( $jwsDecorator, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/CoreTest.php b/tests/src/CoreTest.php index 6e580ad..acca538 100644 --- a/tests/src/CoreTest.php +++ b/tests/src/CoreTest.php @@ -10,17 +10,20 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; +use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator; use SimpleSAML\OpenID\Core; use SimpleSAML\OpenID\Core\Factories\ClientAssertionFactory; use SimpleSAML\OpenID\Core\Factories\RequestObjectFactory; use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; -use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory; +use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory; use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory; -use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory; +use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory; use SimpleSAML\OpenID\Jws\Factories\JwsParserFactory; -use SimpleSAML\OpenID\Jws\Factories\JwsVerifierFactory; +use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory; use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsParser; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; use SimpleSAML\OpenID\SupportedAlgorithms; use SimpleSAML\OpenID\SupportedSerializers; @@ -30,11 +33,14 @@ #[UsesClass(ClientAssertionFactory::class)] #[UsesClass(DateIntervalDecorator::class)] #[UsesClass(DateIntervalDecoratorFactory::class)] -#[UsesClass(AlgorithmManagerFactory::class)] -#[UsesClass(JwsSerializerManagerFactory::class)] +#[UsesClass(AlgorithmManagerDecoratorFactory::class)] +#[UsesClass(JwsSerializerManagerDecoratorFactory::class)] #[UsesClass(JwsParserFactory::class)] -#[UsesClass(JwsVerifierFactory::class)] +#[UsesClass(JwsVerifierDecoratorFactory::class)] #[UsesClass(JwsParser::class)] +#[UsesClass(AlgorithmManagerDecorator::class)] +#[UsesClass(JwsVerifierDecorator::class)] +#[UsesClass(JwsSerializerManagerDecorator::class)] class CoreTest extends TestCase { protected MockObject $supportedAlgorithmsMock; diff --git a/tests/src/Factories/AlgorithmManagerFactoryTest.php b/tests/src/Factories/AlgorithmManagerDecoratorFactoryTest.php similarity index 72% rename from tests/src/Factories/AlgorithmManagerFactoryTest.php rename to tests/src/Factories/AlgorithmManagerDecoratorFactoryTest.php index 37790e0..507ddc8 100644 --- a/tests/src/Factories/AlgorithmManagerFactoryTest.php +++ b/tests/src/Factories/AlgorithmManagerDecoratorFactoryTest.php @@ -6,15 +6,17 @@ use Jose\Component\Signature\Algorithm\SignatureAlgorithm; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use SimpleSAML\OpenID\Algorithms\AlgorithmManager; +use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator; use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmBag; -use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory; +use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory; use SimpleSAML\OpenID\SupportedAlgorithms; -#[CoversClass(AlgorithmManagerFactory::class)] -class AlgorithmManagerFactoryTest extends TestCase +#[CoversClass(AlgorithmManagerDecoratorFactory::class)] +#[UsesClass(AlgorithmManagerDecorator::class)] +class AlgorithmManagerDecoratorFactoryTest extends TestCase { protected MockObject $supportedAlgorithmsMock; protected MockObject $signatureAlgorithmBagMock; @@ -34,15 +36,15 @@ protected function setUp(): void ]); } - protected function sut(): AlgorithmManagerFactory + protected function sut(): AlgorithmManagerDecoratorFactory { - return new AlgorithmManagerFactory(); + return new AlgorithmManagerDecoratorFactory(); } public function testCanCreateInstance(): void { $this->assertInstanceOf( - AlgorithmManagerFactory::class, + AlgorithmManagerDecoratorFactory::class, $this->sut(), ); } @@ -50,7 +52,7 @@ public function testCanCreateInstance(): void public function testCanBuild(): void { $this->assertInstanceOf( - AlgorithmManager::class, + AlgorithmManagerDecorator::class, $this->sut()->build($this->supportedAlgorithmsMock), ); } diff --git a/tests/src/Factories/JwsSerializerManagerFactoryTest.php b/tests/src/Factories/JwsSerializerManagerDecoratorFactoryTest.php similarity index 72% rename from tests/src/Factories/JwsSerializerManagerFactoryTest.php rename to tests/src/Factories/JwsSerializerManagerDecoratorFactoryTest.php index 7acef03..4b00bf7 100644 --- a/tests/src/Factories/JwsSerializerManagerFactoryTest.php +++ b/tests/src/Factories/JwsSerializerManagerDecoratorFactoryTest.php @@ -9,14 +9,14 @@ use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory; +use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory; use SimpleSAML\OpenID\Serializers\JwsSerializerBag; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; use SimpleSAML\OpenID\SupportedSerializers; -#[CoversClass(JwsSerializerManagerFactory::class)] -#[UsesClass(JwsSerializerManager::class)] -class JwsSerializerManagerFactoryTest extends TestCase +#[CoversClass(JwsSerializerManagerDecoratorFactory::class)] +#[UsesClass(JwsSerializerManagerDecorator::class)] +class JwsSerializerManagerDecoratorFactoryTest extends TestCase { protected MockObject $supportedSerializersMock; protected MockObject $jwsSerializerBagMock; @@ -35,15 +35,15 @@ protected function setUp(): void ->willReturn([$this->jwsSerializerMock]); } - protected function sut(): JwsSerializerManagerFactory + protected function sut(): JwsSerializerManagerDecoratorFactory { - return new JwsSerializerManagerFactory(); + return new JwsSerializerManagerDecoratorFactory(); } public function testCanCreateInstance(): void { $this->assertInstanceOf( - JwsSerializerManagerFactory::class, + JwsSerializerManagerDecoratorFactory::class, $this->sut(), ); } @@ -51,7 +51,7 @@ public function testCanCreateInstance(): void public function testCanBuild(): void { $this->assertInstanceOf( - JwsSerializerManager::class, + JwsSerializerManagerDecorator::class, $this->sut()->build($this->supportedSerializersMock), ); } diff --git a/tests/src/Federation/EntityStatementTest.php b/tests/src/Federation/EntityStatementTest.php index 00f1043..4674eb0 100644 --- a/tests/src/Federation/EntityStatementTest.php +++ b/tests/src/Federation/EntityStatementTest.php @@ -18,9 +18,9 @@ use SimpleSAML\OpenID\Helpers; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(EntityStatement::class)] #[UsesClass(ParsedJws::class)] @@ -29,9 +29,9 @@ class EntityStatementTest extends TestCase protected MockObject $signatureMock; protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -108,9 +108,9 @@ protected function setUp(): void $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); $this->jwsDecoratorMock->method('jws')->willReturn($this->jwsMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -126,18 +126,18 @@ protected function setUp(): void protected function sut( ?JwsDecorator $jwsDecorator = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ?TrustMarkClaimFactory $trustMarkClaimFactory = null, ?TrustMarkClaimBagFactory $trustMarkClaimBagFactory = null, ): EntityStatement { $jwsDecorator ??= $this->jwsDecoratorMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; $trustMarkClaimFactory ??= $this->trustMarkClaimFactoryMock; @@ -145,9 +145,9 @@ protected function sut( return new EntityStatement( $jwsDecorator, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, $trustMarkClaimFactory, @@ -200,7 +200,7 @@ public function testIsNotConfiguration(): void public function testVerifyWithKeySetRuns(): void { - $this->jwsVerifierMock->expects($this->once())->method('verifyWithKeySet') + $this->jwsVerifierDecoratorMock->expects($this->once())->method('verifyWithKeySet') ->willReturn(true); $this->signatureMock->method('getProtectedHeader')->willReturn($this->sampleHeader); diff --git a/tests/src/Federation/Factories/EntityStatementFactoryTest.php b/tests/src/Federation/Factories/EntityStatementFactoryTest.php index 589d857..b22724a 100644 --- a/tests/src/Federation/Factories/EntityStatementFactoryTest.php +++ b/tests/src/Federation/Factories/EntityStatementFactoryTest.php @@ -20,9 +20,9 @@ use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(EntityStatementFactory::class)] #[UsesClass(ParsedJwsFactory::class)] @@ -34,9 +34,9 @@ class EntityStatementFactoryTest extends TestCase protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; protected MockObject $jwsParserMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $trustMarkClaimFactoryMock; @@ -110,9 +110,9 @@ protected function setUp(): void $this->jwsParserMock = $this->createMock(JwsParser::class); $this->jwsParserMock->method('parse')->willReturn($this->jwsDecoratorMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); $this->trustMarkClaimFactoryMock = $this->createMock(TrustMarkClaimFactory::class); @@ -127,18 +127,18 @@ protected function setUp(): void protected function sut( ?JwsParser $jwsParser = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ?TrustMarkClaimFactory $trustMarkClaimFactory = null, ?TrustMarkClaimBagFactory $trustMarkClaimBagFactory = null, ): EntityStatementFactory { $jwsParser ??= $this->jwsParserMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; $trustMarkClaimFactory ??= $this->trustMarkClaimFactoryMock; @@ -146,9 +146,9 @@ protected function sut( return new EntityStatementFactory( $jwsParser, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, $trustMarkClaimFactory, diff --git a/tests/src/Federation/Factories/RequestObjectFactoryTest.php b/tests/src/Federation/Factories/RequestObjectFactoryTest.php index 09a44d0..f41f74e 100644 --- a/tests/src/Federation/Factories/RequestObjectFactoryTest.php +++ b/tests/src/Federation/Factories/RequestObjectFactoryTest.php @@ -18,9 +18,9 @@ use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(RequestObjectFactory::class)] #[UsesClass(ParsedJwsFactory::class)] @@ -32,9 +32,9 @@ class RequestObjectFactoryTest extends TestCase protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; protected MockObject $jwsParserMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -73,9 +73,9 @@ protected function setUp(): void $this->jwsParserMock = $this->createMock(JwsParser::class); $this->jwsParserMock->method('parse')->willReturn($this->jwsDecoratorMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -88,24 +88,24 @@ protected function setUp(): void protected function sut( ?JwsParser $jwsParser = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): RequestObjectFactory { $jwsParser ??= $this->jwsParserMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new RequestObjectFactory( $jwsParser, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/Federation/Factories/TrustMarkFactoryTest.php b/tests/src/Federation/Factories/TrustMarkFactoryTest.php index 0726526..671e458 100644 --- a/tests/src/Federation/Factories/TrustMarkFactoryTest.php +++ b/tests/src/Federation/Factories/TrustMarkFactoryTest.php @@ -18,9 +18,9 @@ use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(TrustMarkFactory::class)] #[UsesClass(ParsedJwsFactory::class)] @@ -32,7 +32,7 @@ class TrustMarkFactoryTest extends TestCase protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; protected MockObject $jwsParserMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; protected MockObject $jwsSerializerManagerMock; protected MockObject $dateIntervalDecoratorMock; @@ -71,9 +71,9 @@ protected function setUp(): void $this->jwsParserMock = $this->createMock(JwsParser::class); $this->jwsParserMock->method('parse')->willReturn($this->jwsDecoratorMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -86,24 +86,24 @@ protected function setUp(): void protected function sut( ?JwsParser $jwsParser = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): TrustMarkFactory { $jwsParser ??= $this->jwsParserMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new TrustMarkFactory( $jwsParser, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/Federation/RequestObjectTest.php b/tests/src/Federation/RequestObjectTest.php index 628a561..3205e50 100644 --- a/tests/src/Federation/RequestObjectTest.php +++ b/tests/src/Federation/RequestObjectTest.php @@ -16,9 +16,9 @@ use SimpleSAML\OpenID\Helpers; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(RequestObject::class)] #[UsesClass(ParsedJws::class)] @@ -27,9 +27,9 @@ class RequestObjectTest extends TestCase protected MockObject $signatureMock; protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -59,9 +59,9 @@ protected function setUp(): void $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); $this->jwsDecoratorMock->method('jws')->willReturn($this->jwsMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -74,24 +74,24 @@ protected function setUp(): void protected function sut( ?JwsDecorator $jwsDecorator = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): RequestObject { $jwsDecorator ??= $this->jwsDecoratorMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new RequestObject( $jwsDecorator, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/Federation/TrustMarkTest.php b/tests/src/Federation/TrustMarkTest.php index 512f0ab..248dcb7 100644 --- a/tests/src/Federation/TrustMarkTest.php +++ b/tests/src/Federation/TrustMarkTest.php @@ -15,9 +15,9 @@ use SimpleSAML\OpenID\Helpers; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(TrustMark::class)] #[UsesClass(ParsedJws::class)] @@ -26,9 +26,9 @@ class TrustMarkTest extends TestCase protected MockObject $signatureMock; protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -61,9 +61,9 @@ protected function setUp(): void $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); $this->jwsDecoratorMock->method('jws')->willReturn($this->jwsMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -76,24 +76,24 @@ protected function setUp(): void protected function sut( ?JwsDecorator $jwsDecorator = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): TrustMark { $jwsDecorator ??= $this->jwsDecoratorMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new TrustMark( $jwsDecorator, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/FederationTest.php b/tests/src/FederationTest.php index aa57d5c..fe72a12 100644 --- a/tests/src/FederationTest.php +++ b/tests/src/FederationTest.php @@ -12,14 +12,15 @@ use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Psr\SimpleCache\CacheInterface; +use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator; use SimpleSAML\OpenID\Decorators\CacheDecorator; use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; use SimpleSAML\OpenID\Decorators\HttpClientDecorator; -use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory; +use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory; use SimpleSAML\OpenID\Factories\CacheDecoratorFactory; use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory; use SimpleSAML\OpenID\Factories\HttpClientDecoratorFactory; -use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory; +use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory; use SimpleSAML\OpenID\Federation; use SimpleSAML\OpenID\Federation\EntityStatement\Factories\TrustMarkClaimFactory; use SimpleSAML\OpenID\Federation\EntityStatementFetcher; @@ -32,10 +33,12 @@ use SimpleSAML\OpenID\Federation\TrustChainResolver; use SimpleSAML\OpenID\Jws\AbstractJwsFetcher; use SimpleSAML\OpenID\Jws\Factories\JwsParserFactory; -use SimpleSAML\OpenID\Jws\Factories\JwsVerifierFactory; +use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory; use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsFetcher; use SimpleSAML\OpenID\Jws\JwsParser; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; use SimpleSAML\OpenID\SupportedAlgorithms; use SimpleSAML\OpenID\SupportedSerializers; use SimpleSAML\OpenID\Utils\ArtifactFetcher; @@ -51,11 +54,11 @@ #[UsesClass(RequestObjectFactory::class)] #[UsesClass(TrustMarkFactory::class)] #[UsesClass(TrustMarkClaimFactory::class)] -#[UsesClass(AlgorithmManagerFactory::class)] -#[UsesClass(JwsSerializerManagerFactory::class)] +#[UsesClass(AlgorithmManagerDecoratorFactory::class)] +#[UsesClass(JwsSerializerManagerDecoratorFactory::class)] #[UsesClass(JwsParserFactory::class)] #[UsesClass(JwsParser::class)] -#[UsesClass(JwsVerifierFactory::class)] +#[UsesClass(JwsVerifierDecoratorFactory::class)] #[UsesClass(DateIntervalDecorator::class)] #[UsesClass(DateIntervalDecoratorFactory::class)] #[UsesClass(CacheDecorator::class)] @@ -65,6 +68,9 @@ #[UsesClass(ArtifactFetcher::class)] #[UsesClass(AbstractJwsFetcher::class)] #[UsesClass(JwsFetcher::class)] +#[UsesClass(AlgorithmManagerDecorator::class)] +#[UsesClass(JwsVerifierDecorator::class)] +#[UsesClass(JwsSerializerManagerDecorator::class)] class FederationTest extends TestCase { protected MockObject $supportedAlgorithmsMock; diff --git a/tests/src/Jwks/Factories/SignedJwksFactoryTest.php b/tests/src/Jwks/Factories/SignedJwksFactoryTest.php index 2de9f7e..4b66ef3 100644 --- a/tests/src/Jwks/Factories/SignedJwksFactoryTest.php +++ b/tests/src/Jwks/Factories/SignedJwksFactoryTest.php @@ -18,9 +18,9 @@ use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(SignedJwksFactory::class)] #[UsesClass(ParsedJwsFactory::class)] @@ -32,9 +32,9 @@ class SignedJwksFactoryTest extends TestCase protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; protected MockObject $jwsParserMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -81,9 +81,9 @@ protected function setUp(): void $this->jwsParserMock = $this->createMock(JwsParser::class); $this->jwsParserMock->method('parse')->willReturn($this->jwsDecoratorMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -96,24 +96,24 @@ protected function setUp(): void protected function sut( ?JwsParser $jwsParser = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): SignedJwksFactory { $jwsParser ??= $this->jwsParserMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new SignedJwksFactory( $jwsParser, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/Jwks/SignedJwksTest.php b/tests/src/Jwks/SignedJwksTest.php index e1836c4..9357de1 100644 --- a/tests/src/Jwks/SignedJwksTest.php +++ b/tests/src/Jwks/SignedJwksTest.php @@ -15,9 +15,9 @@ use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jwks\SignedJwks; use SimpleSAML\OpenID\Jws\JwsDecorator; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(SignedJwks::class)] #[UsesClass(ParsedJws::class)] @@ -26,9 +26,9 @@ class SignedJwksTest extends TestCase protected MockObject $signatureMock; protected MockObject $jwsMock; protected MockObject $jwsDecoratorMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; protected MockObject $jsonHelperMock; @@ -72,9 +72,9 @@ protected function setUp(): void $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); $this->jwsDecoratorMock->method('jws')->willReturn($this->jwsMock); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -87,24 +87,24 @@ protected function setUp(): void protected function sut( ?JwsDecorator $jwsDecorator = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): SignedJwks { $jwsDecorator ??= $this->jwsDecoratorMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new SignedJwks( $jwsDecorator, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/JwksTest.php b/tests/src/JwksTest.php index 3c196a3..d9671ef 100644 --- a/tests/src/JwksTest.php +++ b/tests/src/JwksTest.php @@ -12,22 +12,25 @@ use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Psr\SimpleCache\CacheInterface; +use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator; use SimpleSAML\OpenID\Decorators\CacheDecorator; use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; use SimpleSAML\OpenID\Decorators\HttpClientDecorator; -use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory; +use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory; use SimpleSAML\OpenID\Factories\CacheDecoratorFactory; use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory; use SimpleSAML\OpenID\Factories\HttpClientDecoratorFactory; -use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory; +use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory; use SimpleSAML\OpenID\Jwks; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jwks\Factories\SignedJwksFactory; use SimpleSAML\OpenID\Jwks\JwksFetcher; use SimpleSAML\OpenID\Jws\Factories\JwsParserFactory; -use SimpleSAML\OpenID\Jws\Factories\JwsVerifierFactory; +use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory; use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsParser; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; use SimpleSAML\OpenID\SupportedAlgorithms; use SimpleSAML\OpenID\SupportedSerializers; @@ -42,11 +45,14 @@ #[UsesClass(CacheDecoratorFactory::class)] #[UsesClass(DateIntervalDecoratorFactory::class)] #[UsesClass(HttpClientDecoratorFactory::class)] -#[UsesClass(AlgorithmManagerFactory::class)] -#[UsesClass(JwsSerializerManagerFactory::class)] +#[UsesClass(AlgorithmManagerDecoratorFactory::class)] +#[UsesClass(JwsSerializerManagerDecoratorFactory::class)] #[UsesClass(JwsParserFactory::class)] -#[UsesClass(JwsVerifierFactory::class)] +#[UsesClass(JwsVerifierDecoratorFactory::class)] #[UsesClass(JwsParser::class)] +#[UsesClass(AlgorithmManagerDecorator::class)] +#[UsesClass(JwsVerifierDecorator::class)] +#[UsesClass(JwsSerializerManagerDecorator::class)] class JwksTest extends TestCase { protected MockObject $supportedAlgorithmsMock; diff --git a/tests/src/Jws/Factories/JwsParserFactoryTest.php b/tests/src/Jws/Factories/JwsParserFactoryTest.php index a45c084..71f574b 100644 --- a/tests/src/Jws/Factories/JwsParserFactoryTest.php +++ b/tests/src/Jws/Factories/JwsParserFactoryTest.php @@ -10,17 +10,17 @@ use PHPUnit\Framework\TestCase; use SimpleSAML\OpenID\Jws\Factories\JwsParserFactory; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(JwsParserFactory::class)] #[UsesClass(JwsParser::class)] class JwsParserFactoryTest extends TestCase { - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected function setUp(): void { - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); } protected function sut(): JwsParserFactory @@ -37,7 +37,7 @@ public function testCanBuild(): void { $this->assertInstanceOf( JwsParser::class, - $this->sut()->build($this->jwsSerializerManagerMock), + $this->sut()->build($this->jwsSerializerManagerDecoratorMock), ); } } diff --git a/tests/src/Jws/Factories/JwsVerifierDecoratorFactoryTest.php b/tests/src/Jws/Factories/JwsVerifierDecoratorFactoryTest.php new file mode 100644 index 0000000..64eb976 --- /dev/null +++ b/tests/src/Jws/Factories/JwsVerifierDecoratorFactoryTest.php @@ -0,0 +1,50 @@ +algorithmManagerDecorator = new AlgorithmManagerDecorator( + new AlgorithmManager([]), + ); + } + + protected function sut(): JwsVerifierDecoratorFactory + { + return new JwsVerifierDecoratorFactory(); + } + + public function testCanCreateInstance(): void + { + $this->assertInstanceOf( + JwsVerifierDecoratorFactory::class, + $this->sut(), + ); + } + + public function testCanBuild(): void + { + $this->assertInstanceOf( + JwsVerifierDecorator::class, + $this->sut()->build($this->algorithmManagerDecorator), + ); + } +} diff --git a/tests/src/Jws/Factories/JwsVerifierFactoryTest.php b/tests/src/Jws/Factories/JwsVerifierFactoryTest.php deleted file mode 100644 index 24470df..0000000 --- a/tests/src/Jws/Factories/JwsVerifierFactoryTest.php +++ /dev/null @@ -1,46 +0,0 @@ -algorithmManagerMock = $this->createMock(AlgorithmManager::class); - } - - protected function sut(): JwsVerifierFactory - { - return new JwsVerifierFactory(); - } - - public function testCanCreateInstance(): void - { - $this->assertInstanceOf( - JwsVerifierFactory::class, - $this->sut(), - ); - } - - public function testCanBuild(): void - { - $this->assertInstanceOf( - JwsVerifier::class, - $this->sut()->build($this->algorithmManagerMock), - ); - } -} diff --git a/tests/src/Jws/Factories/ParsedJwsFactoryTest.php b/tests/src/Jws/Factories/ParsedJwsFactoryTest.php index cf6589f..10df2d6 100644 --- a/tests/src/Jws/Factories/ParsedJwsFactoryTest.php +++ b/tests/src/Jws/Factories/ParsedJwsFactoryTest.php @@ -13,18 +13,18 @@ use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(ParsedJwsFactory::class)] #[UsesClass(ParsedJws::class)] class ParsedJwsFactoryTest extends TestCase { protected MockObject $jwsParserMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $dateIntervalDecoratorMock; protected MockObject $helpersMock; @@ -33,33 +33,33 @@ class ParsedJwsFactoryTest extends TestCase protected function setUp(): void { $this->jwsParserMock = $this->createMock(JwsParser::class); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->dateIntervalDecoratorMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); } protected function sut( ?JwsParser $jwsParser = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $dateIntervalDecorator = null, ?Helpers $helpers = null, ): ParsedJwsFactory { $jwsParser ??= $this->jwsParserMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $dateIntervalDecorator ??= $this->dateIntervalDecoratorMock; $helpers ??= $this->helpersMock; return new ParsedJwsFactory( $jwsParser, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $dateIntervalDecorator, $helpers, ); diff --git a/tests/src/Jws/JwsParserTest.php b/tests/src/Jws/JwsParserTest.php index 6e9869d..f68e5e4 100644 --- a/tests/src/Jws/JwsParserTest.php +++ b/tests/src/Jws/JwsParserTest.php @@ -4,7 +4,6 @@ namespace SimpleSAML\Test\OpenID\Jws; -use Jose\Component\Signature\JWS; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\MockObject\MockObject; @@ -12,27 +11,27 @@ use SimpleSAML\OpenID\Exceptions\JwsException; use SimpleSAML\OpenID\Jws\JwsDecorator; use SimpleSAML\OpenID\Jws\JwsParser; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(JwsParser::class)] #[UsesClass(JwsDecorator::class)] class JwsParserTest extends TestCase { - protected MockObject $jwsSerializerManagerMock; - protected MockObject $jwsMock; + protected MockObject $jwsSerializerManagerDecoratorMock; + protected MockObject $jwsDecoratorMock; protected function setUp(): void { - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); - $this->jwsMock = $this->createMock(JWS::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); + $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); } protected function sut( - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ): JwsParser { - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; - return new JwsParser($jwsSerializerManager); + return new JwsParser($jwsSerializerManagerDecorator); } public function testCanCreateInstance(): void @@ -42,15 +41,15 @@ public function testCanCreateInstance(): void public function testCanParseToken(): void { - $this->jwsSerializerManagerMock->expects($this->once())->method('unserialize') - ->willReturn($this->jwsMock); + $this->jwsSerializerManagerDecoratorMock->expects($this->once())->method('unserialize') + ->willReturn($this->jwsDecoratorMock); $this->assertInstanceOf(JwsDecorator::class, $this->sut()->parse('token')); } public function testThrowsOnTokenParseError(): void { - $this->jwsSerializerManagerMock->expects($this->once())->method('unserialize') + $this->jwsSerializerManagerDecoratorMock->expects($this->once())->method('unserialize') ->willThrowException(new \Exception('Error')); $this->expectException(JwsException::class); diff --git a/tests/src/Jws/JwsVerifierDecoratorTest.php b/tests/src/Jws/JwsVerifierDecoratorTest.php new file mode 100644 index 0000000..f04b024 --- /dev/null +++ b/tests/src/Jws/JwsVerifierDecoratorTest.php @@ -0,0 +1,60 @@ +jwsVerifierMock = $this->createMock(JWSVerifier::class); + + $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); + $this->jwksDecoratorMock = $this->createMock(JwksDecorator::class); + } + + protected function sut( + ?JWSVerifier $jwsVerifier = null, + ): JwsVerifierDecorator { + $jwsVerifier ??= $this->jwsVerifierMock; + + return new JwsVerifierDecorator( + $jwsVerifier, + ); + } + + public function testCanCreateInstance(): void + { + $this->assertInstanceOf(JwsVerifierDecorator::class, $this->sut()); + } + + public function testCanGetJwsVerifier(): void + { + $this->assertInstanceOf(JwsVerifier::class, $this->sut()->jwsVerifier()); + } + + public function testCanVerifyWithKeySet(): void + { + $this->jwsVerifierMock->expects($this->once())->method('verifyWithKeySet'); + + $this->sut()->verifyWithKeySet( + $this->jwsDecoratorMock, + $this->jwksDecoratorMock, + 0, + ); + } +} diff --git a/tests/src/Jws/ParsedJwsTest.php b/tests/src/Jws/ParsedJwsTest.php index ea0fea6..e2e3de2 100644 --- a/tests/src/Jws/ParsedJwsTest.php +++ b/tests/src/Jws/ParsedJwsTest.php @@ -14,17 +14,17 @@ use SimpleSAML\OpenID\Helpers; use SimpleSAML\OpenID\Jwks\Factories\JwksFactory; use SimpleSAML\OpenID\Jws\JwsDecorator; -use SimpleSAML\OpenID\Jws\JwsVerifier; +use SimpleSAML\OpenID\Jws\JwsVerifierDecorator; use SimpleSAML\OpenID\Jws\ParsedJws; -use SimpleSAML\OpenID\Serializers\JwsSerializerManager; +use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator; #[CoversClass(ParsedJws::class)] class ParsedJwsTest extends TestCase { protected MockObject $jwsDecoratorMock; - protected MockObject $jwsVerifierMock; + protected MockObject $jwsVerifierDecoratorMock; protected MockObject $jwksFactoryMock; - protected MockObject $jwsSerializerManagerMock; + protected MockObject $jwsSerializerManagerDecoratorMock; protected MockObject $timestampValidationLeewayMock; protected MockObject $helpersMock; @@ -95,9 +95,9 @@ class ParsedJwsTest extends TestCase protected function setUp(): void { $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); - $this->jwsVerifierMock = $this->createMock(JwsVerifier::class); + $this->jwsVerifierDecoratorMock = $this->createMock(JwsVerifierDecorator::class); $this->jwksFactoryMock = $this->createMock(JwksFactory::class); - $this->jwsSerializerManagerMock = $this->createMock(JwsSerializerManager::class); + $this->jwsSerializerManagerDecoratorMock = $this->createMock(JwsSerializerManagerDecorator::class); $this->timestampValidationLeewayMock = $this->createMock(DateIntervalDecorator::class); $this->helpersMock = $this->createMock(Helpers::class); @@ -116,24 +116,24 @@ protected function setUp(): void protected function sut( ?JwsDecorator $jwsDecorator = null, - ?JwsVerifier $jwsVerifier = null, + ?JwsVerifierDecorator $jwsVerifierDecorator = null, ?JwksFactory $jwksFactory = null, - ?JwsSerializerManager $jwsSerializerManager = null, + ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null, ?DateIntervalDecorator $timestampValidationLeewayMock = null, ?Helpers $helpers = null, ): ParsedJws { $jwsDecorator ??= $this->jwsDecoratorMock; - $jwsVerifier ??= $this->jwsVerifierMock; + $jwsVerifierDecorator ??= $this->jwsVerifierDecoratorMock; $jwksFactory ??= $this->jwksFactoryMock; - $jwsSerializerManager ??= $this->jwsSerializerManagerMock; + $jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorMock; $timestampValidationLeewayMock ??= $this->timestampValidationLeewayMock; $helpers ??= $this->helpersMock; return new ParsedJws( $jwsDecorator, - $jwsVerifier, + $jwsVerifierDecorator, $jwksFactory, - $jwsSerializerManager, + $jwsSerializerManagerDecorator, $timestampValidationLeewayMock, $helpers, ); @@ -148,9 +148,9 @@ public function testCanValidateByCallbacks(): void { $sut = new class ( $this->jwsDecoratorMock, - $this->jwsVerifierMock, + $this->jwsVerifierDecoratorMock, $this->jwksFactoryMock, - $this->jwsSerializerManagerMock, + $this->jwsSerializerManagerDecoratorMock, $this->timestampValidationLeewayMock, $this->helpersMock, ) extends ParsedJws { @@ -174,9 +174,9 @@ public function testThrowsOnValidateByCallbacksError(): void new class ( $this->jwsDecoratorMock, - $this->jwsVerifierMock, + $this->jwsVerifierDecoratorMock, $this->jwksFactoryMock, - $this->jwsSerializerManagerMock, + $this->jwsSerializerManagerDecoratorMock, $this->timestampValidationLeewayMock, $this->helpersMock, ) extends ParsedJws { @@ -325,9 +325,9 @@ public function testThrowsOnEmptyStrings(): void { $sut = new class ( $this->jwsDecoratorMock, - $this->jwsVerifierMock, + $this->jwsVerifierDecoratorMock, $this->jwksFactoryMock, - $this->jwsSerializerManagerMock, + $this->jwsSerializerManagerDecoratorMock, $this->timestampValidationLeewayMock, $this->helpersMock, ) extends ParsedJws { @@ -345,7 +345,7 @@ public function simulateEmptyStringsCase(): array public function testCanSerializeToToken(): void { - $this->jwsSerializerManagerMock->expects($this->once())->method('serialize') + $this->jwsSerializerManagerDecoratorMock->expects($this->once())->method('serialize') ->willReturn('token'); $sut = $this->sut(); @@ -357,7 +357,7 @@ public function testCanSerializeToToken(): void public function testCanVerifyWithKeySet(): void { - $this->jwsVerifierMock->expects($this->once())->method('verifyWithKeySet') + $this->jwsVerifierDecoratorMock->expects($this->once())->method('verifyWithKeySet') ->willReturn(true); $this->sut()->verifyWithKeySet(['jwks']); @@ -365,7 +365,7 @@ public function testCanVerifyWithKeySet(): void public function testThrowsOnVerifyWithKeySetError(): void { - $this->jwsVerifierMock->expects($this->once())->method('verifyWithKeySet') + $this->jwsVerifierDecoratorMock->expects($this->once())->method('verifyWithKeySet') ->willReturn(false); $this->expectException(JwsException::class); diff --git a/tests/src/Serializers/JwsSerializerManagerDecoratorTest.php b/tests/src/Serializers/JwsSerializerManagerDecoratorTest.php new file mode 100644 index 0000000..4416504 --- /dev/null +++ b/tests/src/Serializers/JwsSerializerManagerDecoratorTest.php @@ -0,0 +1,71 @@ +jwsSerializerMock = $this->createMock(JWSSerializer::class); + $this->jwsSerializerMock->method('name')->willReturn('mockSerializer'); + + $this->jwsDecoratorMock = $this->createMock(JwsDecorator::class); + + // Can not mock, since it is final. + $this->jwsSerializerManager = new JWSSerializerManager([ + $this->jwsSerializerMock, + ]); + } + + protected function sut( + ?JWSSerializerManager $jwsSerializerManager = null, + ): JwsSerializerManagerDecorator { + $jwsSerializerManager ??= $this->jwsSerializerManager; + + return new JwsSerializerManagerDecorator( + $jwsSerializerManager, + ); + } + + public function testCanCreateInstance(): void + { + $this->assertInstanceOf(JwsSerializerManagerDecorator::class, $this->sut()); + } + + public function testCanSerialize(): void + { + $this->jwsSerializerMock->expects($this->once())->method('serialize')->willReturn('token'); + + $this->assertSame( + 'token', + $this->sut()->serialize('mockSerializer', $this->jwsDecoratorMock), + ); + } + + public function testCanUnserialize(): void + { + $this->jwsSerializerMock->expects($this->once())->method('unserialize'); + + $this->assertInstanceOf( + JwsDecorator::class, + $this->sut()->unserialize('token'), + ); + } +}