Skip to content

Commit

Permalink
feat: OIDC initiator throw separate exception type for bad request
Browse files Browse the repository at this point in the history
  • Loading branch information
pnal committed Nov 21, 2024
1 parent d2af7e4 commit 2a7a9a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Security/Oidc/OidcInitiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

namespace OAT\Library\Lti1p3Core\Security\Oidc;

use InvalidArgumentException;
use OAT\Library\Lti1p3Core\Exception\LtiBadRequestException;
use OAT\Library\Lti1p3Core\Exception\LtiException;
use OAT\Library\Lti1p3Core\Exception\LtiExceptionInterface;
use OAT\Library\Lti1p3Core\Message\LtiMessage;
Expand Down Expand Up @@ -121,6 +123,12 @@ public function initiate(ServerRequestInterface $request): LtiMessageInterface

} catch (LtiExceptionInterface $exception) {
throw $exception;
} catch (InvalidArgumentException $exception) {
throw new LtiBadRequestException(
sprintf('OIDC initiation request failed: %s', $exception->getMessage()),
$exception->getCode(),
$exception
);
} catch (Throwable $exception) {
throw new LtiException(
sprintf('OIDC initiation failed: %s', $exception->getMessage()),
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/Security/Oidc/OidcInitiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OAT\Library\Lti1p3Core\Tests\Unit\Security\Oidc;

use Exception;
use OAT\Library\Lti1p3Core\Exception\LtiBadRequestException;
use OAT\Library\Lti1p3Core\Exception\LtiException;
use OAT\Library\Lti1p3Core\Registration\RegistrationInterface;
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
Expand Down Expand Up @@ -150,4 +151,14 @@ public function testInitiationFailureOnGenericError(): void

$this->subject->initiate($request);
}

public function testInitiationFailureOnMissingMandatoryRequestParams(): void
{
$this->expectException(LtiBadRequestException::class);
$this->expectExceptionMessage('OIDC initiation request failed: Missing mandatory iss');

$request = $this->createServerRequest('GET','http://tool.com/init');

$this->subject->initiate($request);
}
}

0 comments on commit 2a7a9a0

Please sign in to comment.