Skip to content

Commit

Permalink
Merge pull request #174 from oat-sa/feature/TR-5944/upgrade-dependencies
Browse files Browse the repository at this point in the history
BREAKING CHANGE TR-5944 upgrade dependencies, removing `Http\Message\ResponseFactory` from dependencies
  • Loading branch information
wazelin committed Dec 22, 2023
2 parents fea7f31 + f4e622f commit fda1733
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 137 deletions.
78 changes: 39 additions & 39 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Build

on: push
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
Expand All @@ -9,44 +13,40 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.2, 7.3, 7.4]
coverage: ["true"]
php: [ 8.0, 8.1, 8.2, 8.3 ]
coverage: [ "false" ]
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
- 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
31 changes: 15 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
"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",
"php-http/message-factory": "^1.1",
"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",
"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": {
Expand Down
47 changes: 20 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
backupGlobals="false"
colors="true"
>
<php>
<env name="TEST_KEYS_ROOT_DIR" value="file://tests/Resource/Key/RSA" />
</php>

<testsuites>
<testsuite name="Integration">
<directory>tests/Integration</directory>
</testsuite>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory>src</directory>
<exclude>
<file>src/Security/Jwt/Decoder/AssociativeDecoder.php</file>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory>src</directory>
</include>
<exclude>
<file>src/Security/Jwt/Decoder/AssociativeDecoder.php</file>
</exclude>
</coverage>
<php>
<env name="TEST_KEYS_ROOT_DIR" value="file://tests/Resource/Key/RSA"/>
</php>
<testsuites>
<testsuite name="Integration">
<directory>tests/Integration</directory>
</testsuite>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
12 changes: 3 additions & 9 deletions src/Security/Jwks/Server/JwksRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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');
}
}
}
12 changes: 3 additions & 9 deletions src/Security/Oidc/Server/OidcAuthenticationRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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');
}
}
}
12 changes: 3 additions & 9 deletions src/Security/Oidc/Server/OidcInitiationRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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');
}
}
}
17 changes: 5 additions & 12 deletions src/Service/Server/LtiServiceServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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();
Expand All @@ -78,15 +72,15 @@ 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());

if ($validationResult->hasError()) {
$this->logger->error($validationResult->getError());

return $this->factory->createResponse(401, null, [], $validationResult->getError());
return new Response(401, [], $validationResult->getError());
}

try {
Expand All @@ -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())
);
Expand Down
Loading

0 comments on commit fda1733

Please sign in to comment.