Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions src/Controllers/Traits/AuthenticatedGetClientFromRequestTrait.php

This file was deleted.

11 changes: 4 additions & 7 deletions src/Helpers/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
namespace SimpleSAML\Module\oidc\Helpers;

use Psr\Http\Message\ServerRequestInterface;
use SimpleSAML\Error\BadRequest;
use SimpleSAML\Error\NotFound;
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
use SimpleSAML\Module\oidc\Exceptions\OidcException;
use SimpleSAML\Module\oidc\Repositories\ClientRepository;

class Client
Expand All @@ -18,9 +17,7 @@ public function __construct(protected Http $http)

/**
* @throws \JsonException
* @throws \SimpleSAML\Error\BadRequest
* @throws \SimpleSAML\Error\NotFound
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
*/
public function getFromRequest(
ServerRequestInterface $request,
Expand All @@ -30,13 +27,13 @@ public function getFromRequest(
$clientId = empty($params['client_id']) ? null : (string)$params['client_id'];

if (!is_string($clientId)) {
throw new BadRequest('Client ID is missing.');
throw new OidcException('Client ID is missing.');
}

$client = $clientRepository->findById($clientId);

if (!$client) {
throw new NotFound('Client not found.');
throw new OidcException('Client not found.');
}

return $client;
Expand Down
9 changes: 5 additions & 4 deletions src/Services/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use SimpleSAML\Module\oidc\Controllers\EndSessionController;
use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface;
use SimpleSAML\Module\oidc\Entities\UserEntity;
use SimpleSAML\Module\oidc\Exceptions\OidcException;
use SimpleSAML\Module\oidc\Factories\AuthSimpleFactory;
use SimpleSAML\Module\oidc\Factories\Entities\UserEntityFactory;
use SimpleSAML\Module\oidc\Factories\ProcessingChainFactory;
Expand Down Expand Up @@ -78,12 +79,11 @@ public function __construct(
*
* @return array
* @throws Error\AuthSource
* @throws Error\BadRequest
* @throws Error\NotFound
* @throws Exception
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
* @throws Error\UnserializableException
* @throws \JsonException
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
*/
public function processRequest(
ServerRequestInterface $request,
Expand Down Expand Up @@ -117,13 +117,14 @@ public function processRequest(


/**
* @param array|null $state
* @param array|null $state
*
* @return UserEntity
* @throws Error\NotFound
* @throws Exception
* @throws \JsonException
* @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
* @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
*/
public function getAuthenticateUser(
?array $state,
Expand Down Expand Up @@ -164,7 +165,7 @@ public function getAuthenticateUser(

$client = $this->clientRepository->findById((string)$state['Oidc']['RelyingPartyMetadata']['id']);
if (!$client) {
throw new Error\NotFound('Client not found.');
throw new OidcException('Client not found.');
}

$this->addRelyingPartyAssociation($client, $user);
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/src/Entities/AccessTokenEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

/**
* @covers \SimpleSAML\Module\oidc\Entities\AccessTokenEntity
*
* @backupGlobals enabled
*/
class AccessTokenEntityTest extends TestCase
{
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/src/Forms/ClientFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ public function setUp(): void
$this->serverRequestMock = $this->createMock(ServerRequest::class);
}

public static function setUpBeforeClass(): void
{
// To make lib/SimpleSAML/Utils/HTTP::getSelfURL() work...
global $_SERVER;
$_SERVER['REQUEST_URI'] = '/';
}

public static function validateOriginProvider(): array
{
return [
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/src/Helpers/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use SimpleSAML\Error\BadRequest;
use SimpleSAML\Error\NotFound;
use SimpleSAML\Module\oidc\Entities\ClientEntity;
use SimpleSAML\Module\oidc\Exceptions\OidcException;
use SimpleSAML\Module\oidc\Helpers\Client;
use SimpleSAML\Module\oidc\Helpers\Http;
use SimpleSAML\Module\oidc\Repositories\ClientRepository;
Expand Down Expand Up @@ -56,15 +55,15 @@ public function testCanGetFromRequest(): void

public function testGetFromRequestThrowsIfNoClientId(): void
{
$this->expectException(BadRequest::class);
$this->expectException(OidcException::class);
$this->expectExceptionMessage('Client ID');

$this->sut()->getFromRequest($this->requestMock, $this->clientRepositoryMock);
}

public function testGetFromRequestThrowsIfClientNotFound(): void
{
$this->expectException(NotFound::class);
$this->expectException(OidcException::class);
$this->expectExceptionMessage('Client not found');

$this->httpMock->expects($this->once())->method('getAllRequestParams')
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/src/Server/Validators/BearerTokenValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

/**
* @covers \SimpleSAML\Module\oidc\Server\Validators\BearerTokenValidator
*
* @backupGlobals enabled
*/
class BearerTokenValidatorTest extends TestCase
{
Expand Down Expand Up @@ -60,10 +58,6 @@ public function setUp(): void
*/
public static function setUpBeforeClass(): void
{
// To make lib/SimpleSAML/Utils/HTTP::getSelfURL() work...
global $_SERVER;
$_SERVER['REQUEST_URI'] = '';

$tempDir = sys_get_temp_dir();

// Plant certdir config for JsonWebTokenBuilderService (since we don't inject it)
Expand Down
14 changes: 2 additions & 12 deletions tests/unit/src/Services/AuthenticationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
use SimpleSAML\Auth\State;
use SimpleSAML\Error\Exception;
use SimpleSAML\Error\NoState;
use SimpleSAML\Error\NotFound;
use SimpleSAML\Module\oidc\Entities\ClientEntity;
use SimpleSAML\Module\oidc\Entities\UserEntity;
use SimpleSAML\Module\oidc\Exceptions\OidcException;
use SimpleSAML\Module\oidc\Factories\AuthSimpleFactory;
use SimpleSAML\Module\oidc\Factories\Entities\UserEntityFactory;
use SimpleSAML\Module\oidc\Factories\ProcessingChainFactory;
Expand Down Expand Up @@ -84,16 +84,6 @@ class AuthenticationServiceTest extends TestCase
protected MockObject $requestParamsResolverMock;
protected MockObject $userEntityFactoryMock;

/**
* @return void
*/
public static function setUpBeforeClass(): void
{
// To make lib/SimpleSAML/Utils/HTTP::getSelfURL() work...
global $_SERVER;
$_SERVER['REQUEST_URI'] = '';
}

/**
* @throws \PHPUnit\Framework\MockObject\Exception
*/
Expand Down Expand Up @@ -280,7 +270,7 @@ public static function getUserState(): array
'AuthorizationRequestParameters' => self::AUTHZ_REQUEST_PARAMS,
],
],
NotFound::class,
OidcException::class,
'/Client not found./',
],
];
Expand Down