From 318b75aed9de8fb37ade07d23db0d48f3acbce9c Mon Sep 17 00:00:00 2001 From: Mati Kochen Date: Fri, 8 Dec 2023 19:32:06 +0100 Subject: [PATCH 1/5] fix: bump to php 8.0, allow 8.3 and remove old and unsupported dependency versions --- .github/workflows/build.yaml | 9 +-------- composer.json | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c709a01..18bc8ca 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,15 +9,8 @@ jobs: strategy: fail-fast: false matrix: - php: [7.2, 7.3, 7.4] + php: [8.0, 8.1, 8.2, 8.3] coverage: ["true"] - include: - - php: 8.0 - coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8 - - php: 8.1 - coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8 - - php: 8.2 - coverage: "false" # PHPUnit 8.5.14 doesn't support code coverage under PHP 8 steps: - name: Checkout diff --git a/composer.json b/composer.json index baa8b30..15b54a4 100644 --- a/composer.json +++ b/composer.json @@ -4,29 +4,29 @@ "type": "library", "license": "GPL-2.0-only", "require": { - "php": ">=7.2.0", + "php": ">=8.0.0", "ext-json": "*", "ext-openssl": "*", - "codercat/jwk-to-pem": "^1.0", - "guzzlehttp/guzzle": "^6.5 || ^7.0", - "lcobucci/jwt": "^3.4 || ^4.1.5", - "league/oauth2-server": "^8.2", - "nesbot/carbon": "^2.43", - "nyholm/psr7": "^1.3", + "codercat/jwk-to-pem": "^1.1", + "guzzlehttp/guzzle": "^7.8", + "lcobucci/jwt": "^4.3", + "league/oauth2-server": "^8.5", + "nesbot/carbon": "^2.72", + "nyholm/psr7": "^1.8", "php-http/message-factory": "^1.1", "phpseclib/phpseclib": "^3.0.34", - "psr/cache": "^1.0 || ^2.0 || ^3.0", - "psr/http-message": "^1.0", + "psr/cache": "^2.0 || ^3.0", + "psr/http-message": "^1.1", "psr/http-server-handler": "^1.0", "psr/log": "^1.0 || ^2.0 || ^3.0", - "ramsey/uuid": "^3.9 || ^4" + "ramsey/uuid": "^3.9 || ^4.7" }, "require-dev": { - "cache/array-adapter": "^1.1", - "phpunit/phpunit": "8.5.14", - "php-coveralls/php-coveralls": "^2.4", - "psalm/plugin-phpunit": "^0.15.1", - "vimeo/psalm": "^4.6" + "cache/array-adapter": "^1.2", + "phpunit/phpunit": "^9.6", + "php-coveralls/php-coveralls": "^2.7", + "psalm/plugin-phpunit": "^0.15", + "vimeo/psalm": "^4.30" }, "autoload": { "psr-4": { From 91566eaaa5b81fae80355b45c28d7db828af734d Mon Sep 17 00:00:00 2001 From: Mati Kochen Date: Fri, 8 Dec 2023 22:16:25 +0100 Subject: [PATCH 2/5] fix: replace abandoned php-http/message-factory with simple Nyholm\Psr7\Response --- composer.json | 1 - src/Security/Jwks/Server/JwksRequestHandler.php | 12 +++--------- .../Server/OidcAuthenticationRequestHandler.php | 12 +++--------- .../Server/OidcInitiationRequestHandler.php | 12 +++--------- src/Service/Server/LtiServiceServer.php | 17 +++++------------ .../Jwks/Server/JwksRequestHandlerTest.php | 2 +- tests/Traits/NetworkTestingTrait.php | 4 ++-- .../Service/Server/LtiServiceServerTest.php | 10 +++++----- 8 files changed, 22 insertions(+), 48 deletions(-) diff --git a/composer.json b/composer.json index 15b54a4..790840e 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,6 @@ "league/oauth2-server": "^8.5", "nesbot/carbon": "^2.72", "nyholm/psr7": "^1.8", - "php-http/message-factory": "^1.1", "phpseclib/phpseclib": "^3.0.34", "psr/cache": "^2.0 || ^3.0", "psr/http-message": "^1.1", diff --git a/src/Security/Jwks/Server/JwksRequestHandler.php b/src/Security/Jwks/Server/JwksRequestHandler.php index 8552317..b44e499 100644 --- a/src/Security/Jwks/Server/JwksRequestHandler.php +++ b/src/Security/Jwks/Server/JwksRequestHandler.php @@ -22,8 +22,7 @@ namespace OAT\Library\Lti1p3Core\Security\Jwks\Server; -use Http\Message\ResponseFactory; -use Nyholm\Psr7\Factory\HttplugFactory; +use Nyholm\Psr7\Response; use OAT\Library\Lti1p3Core\Security\Jwks\Exporter\JwksExporter; use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerInterface; @@ -38,19 +37,14 @@ class JwksRequestHandler /** @var JwksExporter */ private $exporter; - /** @var ResponseFactory */ - private $factory; - /** @var LoggerInterface */ private $logger; public function __construct( JwksExporter $exporter, - ?ResponseFactory $factory = null, ?LoggerInterface $logger = null ) { $this->exporter = $exporter; - $this->factory = $factory ?? new HttplugFactory(); $this->logger = $logger ?? new NullLogger(); } @@ -64,12 +58,12 @@ public function handle(string $keySetName): ResponseInterface 'Content-Length' => strlen($body) ]; - return $this->factory->createResponse(200, null, $headers, $body); + return new Response(200, $headers, $body); } catch (Throwable $exception) { $this->logger->error(sprintf('Error during JWKS server handling: %s', $exception->getMessage())); - return $this->factory->createResponse(500, null, [], 'Internal JWKS server error'); + return new Response(500, [], 'Internal JWKS server error'); } } } diff --git a/src/Security/Oidc/Server/OidcAuthenticationRequestHandler.php b/src/Security/Oidc/Server/OidcAuthenticationRequestHandler.php index 06ee29d..19e6647 100644 --- a/src/Security/Oidc/Server/OidcAuthenticationRequestHandler.php +++ b/src/Security/Oidc/Server/OidcAuthenticationRequestHandler.php @@ -22,8 +22,7 @@ namespace OAT\Library\Lti1p3Core\Security\Oidc\Server; -use Http\Message\ResponseFactory; -use Nyholm\Psr7\Factory\HttplugFactory; +use Nyholm\Psr7\Response; use OAT\Library\Lti1p3Core\Security\Oidc\OidcAuthenticator; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -40,19 +39,14 @@ class OidcAuthenticationRequestHandler implements RequestHandlerInterface /** @var OidcAuthenticator */ private $authenticator; - /** @var ResponseFactory */ - private $factory; - /** @var LoggerInterface */ private $logger; public function __construct( OidcAuthenticator $authenticator, - ?ResponseFactory $factory = null, ?LoggerInterface $logger = null ) { $this->authenticator = $authenticator; - $this->factory = $factory ?? new HttplugFactory(); $this->logger = $logger ?? new NullLogger(); } @@ -61,12 +55,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface try { $message = $this->authenticator->authenticate($request); - return $this->factory->createResponse(200, null, [], $message->toHtmlRedirectForm()); + return new Response(200, [], $message->toHtmlRedirectForm()); } catch (Throwable $exception) { $this->logger->error($exception->getMessage()); - return $this->factory->createResponse(500, null, [], 'Internal OIDC authentication server error'); + return new Response(500, [], 'Internal OIDC authentication server error'); } } } diff --git a/src/Security/Oidc/Server/OidcInitiationRequestHandler.php b/src/Security/Oidc/Server/OidcInitiationRequestHandler.php index 88100b8..91342c1 100644 --- a/src/Security/Oidc/Server/OidcInitiationRequestHandler.php +++ b/src/Security/Oidc/Server/OidcInitiationRequestHandler.php @@ -22,8 +22,7 @@ namespace OAT\Library\Lti1p3Core\Security\Oidc\Server; -use Http\Message\ResponseFactory; -use Nyholm\Psr7\Factory\HttplugFactory; +use Nyholm\Psr7\Response; use OAT\Library\Lti1p3Core\Security\Oidc\OidcInitiator; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -40,19 +39,14 @@ class OidcInitiationRequestHandler implements RequestHandlerInterface /** @var OidcInitiator */ private $initiator; - /** @var ResponseFactory */ - private $factory; - /** @var LoggerInterface */ private $logger; public function __construct( OidcInitiator $initiator, - ?ResponseFactory $factory = null, ?LoggerInterface $logger = null ) { $this->initiator = $initiator; - $this->factory = $factory ?? new HttplugFactory(); $this->logger = $logger ?? new NullLogger(); } @@ -61,12 +55,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface try { $message = $this->initiator->initiate($request); - return $this->factory->createResponse(302, null, ['Location' => $message->toUrl()]); + return new Response(302, ['Location' => $message->toUrl()]); } catch (Throwable $exception) { $this->logger->error($exception->getMessage()); - return $this->factory->createResponse(500, null, [], 'Internal OIDC initiation server error'); + return new Response(500, [], 'Internal OIDC initiation server error'); } } } diff --git a/src/Service/Server/LtiServiceServer.php b/src/Service/Server/LtiServiceServer.php index 8a65c7a..8b3e20f 100644 --- a/src/Service/Server/LtiServiceServer.php +++ b/src/Service/Server/LtiServiceServer.php @@ -22,8 +22,7 @@ namespace OAT\Library\Lti1p3Core\Service\Server; -use Http\Message\ResponseFactory; -use Nyholm\Psr7\Factory\HttplugFactory; +use Nyholm\Psr7\Response; use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidatorInterface; use OAT\Library\Lti1p3Core\Service\Server\Handler\LtiServiceServerRequestHandlerInterface; use Psr\Http\Message\ResponseInterface; @@ -41,21 +40,16 @@ class LtiServiceServer implements RequestHandlerInterface /** @var LtiServiceServerRequestHandlerInterface */ private $handler; - /** @var ResponseFactory */ - private $factory; - /** @var LoggerInterface */ private $logger; public function __construct( RequestAccessTokenValidatorInterface $validator, LtiServiceServerRequestHandlerInterface $handler, - ?ResponseFactory $factory = null, ?LoggerInterface $logger = null ) { $this->validator = $validator; $this->handler = $handler; - $this->factory = $factory ?? new HttplugFactory(); $this->logger = $logger ?? new NullLogger(); } @@ -67,7 +61,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface $message = sprintf('Not acceptable request method, accepts: [%s]', implode(', ', $allowedMethods)); $this->logger->error($message); - return $this->factory->createResponse(405, null, [], $message); + return new Response(405, [], $message); } $allowedContentType = $this->handler->getAllowedContentType(); @@ -78,7 +72,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface $message = sprintf('Not acceptable request content type, accepts: %s', $allowedContentType); $this->logger->error($message); - return $this->factory->createResponse(406, null, [], $message); + return new Response(406, [], $message); } $validationResult = $this->validator->validate($request, $this->handler->getAllowedScopes()); @@ -86,7 +80,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface if ($validationResult->hasError()) { $this->logger->error($validationResult->getError()); - return $this->factory->createResponse(401, null, [], $validationResult->getError()); + return new Response(401, [], $validationResult->getError()); } try { @@ -99,9 +93,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface } catch (Throwable $exception) { $this->logger->error($exception->getMessage()); - return $this->factory->createResponse( + return new Response( 500, - null, [], sprintf('Internal %s service error', $this->handler->getServiceName()) ); diff --git a/tests/Integration/Security/Jwks/Server/JwksRequestHandlerTest.php b/tests/Integration/Security/Jwks/Server/JwksRequestHandlerTest.php index 3548b26..eedf62e 100644 --- a/tests/Integration/Security/Jwks/Server/JwksRequestHandlerTest.php +++ b/tests/Integration/Security/Jwks/Server/JwksRequestHandlerTest.php @@ -71,7 +71,7 @@ public function testJwksErrorResponseOnInvalidExport(): void $logger = new TestLogger(); - $subject = new JwksRequestHandler($exporterMock, null, $logger); + $subject = new JwksRequestHandler($exporterMock, $logger); $response = $subject->handle('keySetName'); diff --git a/tests/Traits/NetworkTestingTrait.php b/tests/Traits/NetworkTestingTrait.php index b2b855c..f50aec0 100644 --- a/tests/Traits/NetworkTestingTrait.php +++ b/tests/Traits/NetworkTestingTrait.php @@ -22,8 +22,8 @@ namespace OAT\Library\Lti1p3Core\Tests\Traits; -use Nyholm\Psr7\Factory\HttplugFactory; use Nyholm\Psr7\Factory\Psr17Factory; +use Nyholm\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -56,6 +56,6 @@ private function createServerRequest( private function createResponse($content = null, int $statusCode = 200, array $headers = []): ResponseInterface { - return (new HttplugFactory())->createResponse($statusCode, null, $headers, $content); + return new Response($statusCode, $headers, $content); } } diff --git a/tests/Unit/Service/Server/LtiServiceServerTest.php b/tests/Unit/Service/Server/LtiServiceServerTest.php index b8ecff7..bca69e2 100644 --- a/tests/Unit/Service/Server/LtiServiceServerTest.php +++ b/tests/Unit/Service/Server/LtiServiceServerTest.php @@ -78,7 +78,7 @@ static function() use ($serviceResponse): ResponseInterface { ['scope'] ); - $subject = new LtiServiceServer($this->validator, $handler, null, $this->logger); + $subject = new LtiServiceServer($this->validator, $handler, $this->logger); $response = $subject->handle($serviceRequest); @@ -101,7 +101,7 @@ public function testServiceServerFailureOnInvalidMethod(): void ['GET'] ); - $subject = new LtiServiceServer($this->validator, $handler, null, $this->logger); + $subject = new LtiServiceServer($this->validator, $handler, $this->logger); $response = $subject->handle($serviceRequest); @@ -128,7 +128,7 @@ public function testServiceServerFailureOnInvalidContentType(): void ['POST'] ); - $subject = new LtiServiceServer($this->validator, $handler, null, $this->logger); + $subject = new LtiServiceServer($this->validator, $handler, $this->logger); $response = $subject->handle($serviceRequest); @@ -164,7 +164,7 @@ public function testServiceServerFailureOnInvalidAccessToken(): void ['scope'] ); - $subject = new LtiServiceServer($this->validator, $handler, null, $this->logger); + $subject = new LtiServiceServer($this->validator, $handler, $this->logger); $response = $subject->handle($serviceRequest); @@ -197,7 +197,7 @@ static function() { ['scope'] ); - $subject = new LtiServiceServer($this->validator, $handler, null, $this->logger); + $subject = new LtiServiceServer($this->validator, $handler, $this->logger); $response = $subject->handle($serviceRequest); From f22ec80e331f8e2ee55492b5fdf529fc7e2bb8f6 Mon Sep 17 00:00:00 2001 From: Mati Kochen Date: Fri, 8 Dec 2023 22:52:31 +0100 Subject: [PATCH 3/5] fix: remove deprecated at() method --- .../Unit/Security/Jwks/Fetcher/JwksFetcherTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/Unit/Security/Jwks/Fetcher/JwksFetcherTest.php b/tests/Unit/Security/Jwks/Fetcher/JwksFetcherTest.php index a7afdaa..697235e 100644 --- a/tests/Unit/Security/Jwks/Fetcher/JwksFetcherTest.php +++ b/tests/Unit/Security/Jwks/Fetcher/JwksFetcherTest.php @@ -74,16 +74,13 @@ public function testItLogCacheFetchAndSaveErrors(): void $exporter = new JwksExporter(new KeyChainRepository([$keyChain])); $this->cacheMock - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('getItem') ->with($cacheKey) - ->willThrowException(new Exception('cache fetch error')); - - $this->cacheMock - ->expects($this->at(1)) - ->method('getItem') - ->with($cacheKey) - ->willReturn(new CacheItem($cacheKey)); + ->willReturnOnConsecutiveCalls( + $this->throwException(new Exception('cache fetch error')), + new CacheItem($cacheKey) + ); $this->cacheMock ->expects($this->once()) From 72f5a64472ba4617ad658cc4a687518d0d12c0d2 Mon Sep 17 00:00:00 2001 From: Sergei Mikhailov Date: Thu, 21 Dec 2023 19:41:06 +0100 Subject: [PATCH 4/5] ci: execute Build workflow on pull requests to `master` --- .github/workflows/build.yaml | 73 ++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 18bc8ca..d668976 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,10 @@ name: Build -on: push +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] jobs: build: @@ -9,37 +13,40 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 8.1, 8.2, 8.3] - coverage: ["true"] + php: [ 8.0, 8.1, 8.2, 8.3 ] + coverage: [ "false" ] + include: + - php: 8.3 + coverage: "true" # Collecting coverage reports only once steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP & Composer - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - tools: composer:v2 - - - name: Install dependencies - run: composer install --no-interaction --no-suggest - - - name: PHPUnit - env: - COVERAGE: ${{ matrix.coverage }} - run: | - [ $COVERAGE = "true" ] \ - && mkdir -p build/logs && ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml \ - || ./vendor/bin/phpunit - - - name: Psalm - run: | - ./vendor/bin/psalm --shepherd - - - name: Coveralls - if: ${{ matrix.coverage == 'true' }} - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - ./vendor/bin/php-coveralls -v + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP & Composer + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + + - name: Install dependencies + run: composer install --no-interaction --no-suggest + + - name: PHPUnit + env: + COVERAGE: ${{ matrix.coverage }} + run: | + [ $COVERAGE = "true" ] \ + && mkdir -p build/logs && ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml \ + || ./vendor/bin/phpunit + + - name: Psalm + run: | + ./vendor/bin/psalm --shepherd + + - name: Coveralls + if: ${{ matrix.coverage == 'true' }} + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + ./vendor/bin/php-coveralls -v From f4e622f16f03350bef38193a524bba982b71366e Mon Sep 17 00:00:00 2001 From: Sergei Mikhailov Date: Thu, 21 Dec 2023 20:17:03 +0100 Subject: [PATCH 5/5] fix: migrate phpunit.xml.dist configuration to phpunit 9 --- phpunit.xml.dist | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1f0034f..40e15bf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,23 @@ - - - - - - - - - tests/Integration - - - tests/Unit - - - - - - src - - src/Security/Jwt/Decoder/AssociativeDecoder.php - - - + + + + src + + + src/Security/Jwt/Decoder/AssociativeDecoder.php + + + + + + + + tests/Integration + + + tests/Unit + +