- {% trans '{oidc:client:allowed_origin}' %} |
+ {{ '{oidc:client:allowed_origin}'|trans }} |
{% for allowedOrigin in allowedOrigins %}
@@ -109,20 +109,20 @@
@@ -142,7 +142,7 @@
new ClipboardJS('.copy.link')
.on('success', function (e) {
e.clearSelection();
- $(e.trigger).popup('change content', '{% trans '{oidc:copied}' %}')
+ $(e.trigger).popup('change content', '{{ '{oidc:copied}'|trans }}')
})
;
diff --git a/templates/install.twig b/templates/install.twig
index 84d1371d..ea272a5c 100644
--- a/templates/install.twig
+++ b/templates/install.twig
@@ -9,24 +9,24 @@
- {% trans '{oidc:install:description}' %}
+ {{ '{oidc:install:description}'|trans }}
diff --git a/templates/logout.twig b/templates/logout.twig
index 423e7e66..024f634a 100644
--- a/templates/logout.twig
+++ b/templates/logout.twig
@@ -5,9 +5,9 @@
{% block content %}
{% if wasLogoutActionCalled %}
- {% trans '{oidc:logout:page_title_success}' %}
+ {{ '{oidc:logout:page_title_success}'|trans }}
{% else %}
- {% trans '{oidc:logout:page_title_fail}' %}
+ {{ '{oidc:logout:page_title_fail}'|trans }}
{% endif %}
@@ -15,13 +15,13 @@
{% if wasLogoutActionCalled %}
- {% trans '{oidc:logout:info_message_success}' %}
+ {{ '{oidc:logout:info_message_success}'|trans }}
{% else %}
- {% trans '{oidc:logout:info_message_fail}' %}
+ {{ '{oidc:logout:info_message_fail}'|trans }}
{% endif %}
diff --git a/templates/oidc_base.twig b/templates/oidc_base.twig
index c20b6b02..424c10b9 100644
--- a/templates/oidc_base.twig
+++ b/templates/oidc_base.twig
@@ -85,7 +85,7 @@
{% if messages is not empty %}
{% for message in messages %}
- {% trans message %}
+ {{ message|trans }}
{% endfor %}
{% endif %}
diff --git a/tests/ClaimTranslatorExtractorTest.php b/tests/ClaimTranslatorExtractorTest.php
index 6a1b6395..2dc71fc6 100644
--- a/tests/ClaimTranslatorExtractorTest.php
+++ b/tests/ClaimTranslatorExtractorTest.php
@@ -72,7 +72,7 @@ public function testTypeConversion(): void
],
'urn:oid:2.5.4.3' => ['stringAttribute']
];
- $userAttributes = Attributes::normalizeAttributesArray(
+ $userAttributes = (new Attributes())->normalizeAttributesArray(
[
'intAttribute' => '7890',
'boolAttribute1' => '1',
@@ -113,7 +113,7 @@ public function testTypeConversion(): void
public function testDefaultTypeConversion(): void
{
// Address is the only non-string attribute with a default saml source
- $userAttributes = Attributes::normalizeAttributesArray(
+ $userAttributes = (new Attributes())->normalizeAttributesArray(
[
'postalAddress' => 'myAddress'
]
@@ -159,7 +159,7 @@ public function testStandardClaimTypesCanBeSet(): void
]
],
];
- $userAttributes = Attributes::normalizeAttributesArray(
+ $userAttributes = (new Attributes())->normalizeAttributesArray(
[
'country' => 'CA',
'postal' => '93105',
@@ -200,7 +200,7 @@ public function testInvalidTypeConversion(): void
'testClaim'
],
];
- $userAttributes = Attributes::normalizeAttributesArray(['testClaim' => '7890F',]);
+ $userAttributes = (new Attributes())->normalizeAttributesArray(['testClaim' => '7890F',]);
$claimTranslator = new ClaimTranslatorExtractor(self::$userIdAttr, [$claimSet], $translate);
$claimTranslator->extract(['typeConversion'], $userAttributes);
}
diff --git a/tests/Controller/ClientCreateControllerTest.php b/tests/Controller/ClientCreateControllerTest.php
index 4eac54eb..e18d0fe6 100644
--- a/tests/Controller/ClientCreateControllerTest.php
+++ b/tests/Controller/ClientCreateControllerTest.php
@@ -2,13 +2,226 @@
namespace SimpleSAML\Test\Module\oidc\Controller;
+use Laminas\Diactoros\Response\RedirectResponse;
+use Laminas\Diactoros\ServerRequest;
use SimpleSAML\Module\oidc\Controller\ClientCreateController;
use PHPUnit\Framework\TestCase;
+use SimpleSAML\Module\oidc\Entity\ClientEntity;
+use SimpleSAML\Module\oidc\Factories\FormFactory;
+use SimpleSAML\Module\oidc\Factories\TemplateFactory;
+use SimpleSAML\Module\oidc\Form\ClientForm;
+use SimpleSAML\Module\oidc\Repositories\AllowedOriginRepository;
+use SimpleSAML\Module\oidc\Repositories\ClientRepository;
+use SimpleSAML\Module\oidc\Services\AuthContextService;
+use SimpleSAML\Module\oidc\Services\SessionMessagesService;
+use SimpleSAML\XHTML\Template;
+/**
+ * @covers \SimpleSAML\Module\oidc\Controller\ClientCreateController
+ */
class ClientCreateControllerTest extends TestCase
{
- public function testIncomplete(): void
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $clientRepositoryMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $allowedOriginRepositoryMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $templateFactoryMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $formFactoryMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $sessionMessageServiceMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $authContextServiceMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $clientFormMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\Stub
+ */
+ protected $serverRequestStub;
+ /**
+ * @var \PHPUnit\Framework\MockObject\Stub
+ */
+ protected $templateStub;
+
+ protected function setUp(): void
+ {
+ $this->clientRepositoryMock = $this->createMock(ClientRepository::class);
+ $this->allowedOriginRepositoryMock = $this->createMock(AllowedOriginRepository::class);
+ $this->templateFactoryMock = $this->createMock(TemplateFactory::class);
+ $this->formFactoryMock = $this->createMock(FormFactory::class);
+ $this->sessionMessageServiceMock = $this->createMock(SessionMessagesService::class);
+ $this->authContextServiceMock = $this->createMock(AuthContextService::class);
+
+ $this->clientFormMock = $this->createMock(ClientForm::class);
+ $this->serverRequestStub = $this->createStub(ServerRequest::class);
+ $this->templateStub = $this->createStub(Template::class);
+ }
+
+ public function testCanInstantiate(): void
+ {
+ $controller = $this->getStubbedInstance();
+ $this->assertInstanceOf(ClientCreateController::class, $controller);
+ }
+
+ protected function getStubbedInstance(): ClientCreateController
{
- $this->markTestIncomplete();
+ return new ClientCreateController(
+ $this->clientRepositoryMock,
+ $this->allowedOriginRepositoryMock,
+ $this->templateFactoryMock,
+ $this->formFactoryMock,
+ $this->sessionMessageServiceMock,
+ $this->authContextServiceMock
+ );
+ }
+
+ public function testCanShowNewClientForm(): void
+ {
+ $this->clientFormMock
+ ->expects($this->once())
+ ->method('setAction')
+ ->with($this->anything());
+ $this->clientFormMock
+ ->expects($this->once())
+ ->method('isSuccess')
+ ->willReturn(false);
+
+ $this->templateFactoryMock
+ ->expects($this->once())
+ ->method('render')
+ ->with('oidc:clients/new.twig', [
+ 'form' => $this->clientFormMock,
+ 'regexUri' => ClientForm::REGEX_URI,
+ 'regexAllowedOriginUrl' => ClientForm::REGEX_ALLOWED_ORIGIN_URL,
+ 'regexHttpUri' => ClientForm::REGEX_HTTP_URI,
+ ])
+ ->willReturn($this->templateStub);
+
+ $this->formFactoryMock
+ ->expects($this->once())
+ ->method('build')
+ ->with($this->equalTo(ClientForm::class))
+ ->willReturn($this->clientFormMock);
+
+ $controller = $this->getStubbedInstance();
+ $this->assertSame($this->templateStub, $controller->__invoke($this->serverRequestStub));
+ }
+
+ public function testCanCreateNewClientFromFormData(): void
+ {
+ $this->clientFormMock
+ ->expects($this->once())
+ ->method('setAction')
+ ->with($this->anything());
+ $this->clientFormMock
+ ->expects($this->once())
+ ->method('isSuccess')
+ ->willReturn(true);
+ $this->clientFormMock
+ ->expects($this->once())
+ ->method('getValues')
+ ->willReturn(
+ [
+ 'name' => 'name',
+ 'description' => 'description',
+ 'auth_source' => 'auth_source',
+ 'redirect_uri' => ['http://localhost/redirect'],
+ 'scopes' => ['openid'],
+ 'is_enabled' => true,
+ 'is_confidential' => false,
+ 'allowed_origin' => [],
+ 'post_logout_redirect_uri' => [],
+ 'backchannel_logout_uri' => null,
+ ]
+ );
+
+ $this->formFactoryMock
+ ->expects($this->once())
+ ->method('build')
+ ->willReturn($this->clientFormMock);
+
+ $this->clientRepositoryMock
+ ->expects($this->once())
+ ->method('add')
+ ->with($this->isInstanceOf(ClientEntity::class));
+
+ $this->allowedOriginRepositoryMock
+ ->expects($this->once())
+ ->method('set')
+ ->with($this->isType('string'), []);
+ $this->sessionMessageServiceMock
+ ->expects($this->once())
+ ->method('addMessage')
+ ->with('{oidc:client:added}');
+
+ $controller = $this->getStubbedInstance();
+ $this->assertInstanceOf(RedirectResponse::class, $controller->__invoke($this->serverRequestStub));
+ }
+
+ public function testCanSetOwnerInNewClient(): void
+ {
+ $this->authContextServiceMock->expects($this->once())->method('isSspAdmin')->willReturn(false);
+ $this->authContextServiceMock->method('getAuthUserId')->willReturn('ownerUsername');
+
+ $this->clientFormMock
+ ->expects($this->once())
+ ->method('setAction')
+ ->with($this->anything());
+ $this->clientFormMock
+ ->expects($this->once())
+ ->method('isSuccess')
+ ->willReturn(true);
+ $this->clientFormMock
+ ->expects($this->once())
+ ->method('getValues')
+ ->willReturn(
+ [
+ 'name' => 'name',
+ 'description' => 'description',
+ 'auth_source' => 'auth_source',
+ 'redirect_uri' => ['http://localhost/redirect'],
+ 'scopes' => ['openid'],
+ 'is_enabled' => true,
+ 'is_confidential' => false,
+ 'owner' => 'wrongOwner',
+ 'allowed_origin' => [],
+ 'post_logout_redirect_uri' => [],
+ 'backchannel_logout_uri' => null,
+ ]
+ );
+
+ $this->formFactoryMock
+ ->expects($this->once())
+ ->method('build')
+ ->willReturn($this->clientFormMock);
+
+ $this->clientRepositoryMock->expects($this->once())->method('add')
+ ->with($this->callback(function ($client) {
+ return is_callable([$client, 'getOwner']) &&
+ $client->getOwner() == 'ownerUsername';
+ }));
+
+ $this->sessionMessageServiceMock
+ ->expects($this->once())
+ ->method('addMessage')
+ ->with('{oidc:client:added}');
+
+ $controller = $this->getStubbedInstance();
+ $this->assertInstanceOf(RedirectResponse::class, $controller->__invoke($this->serverRequestStub));
}
}
diff --git a/tests/Controller/ClientDeleteControllerTest.php b/tests/Controller/ClientDeleteControllerTest.php
new file mode 100644
index 00000000..28d04465
--- /dev/null
+++ b/tests/Controller/ClientDeleteControllerTest.php
@@ -0,0 +1,184 @@
+clientRepositoryMock = $this->createMock(ClientRepository::class);
+ $this->templateFactoryMock = $this->createMock(TemplateFactory::class);
+ $this->sessionMessageServiceMock = $this->createMock(SessionMessagesService::class);
+ $this->serverRequestMock = $this->createMock(ServerRequest::class);
+ $this->uriStub = $this->createStub(UriInterface::class);
+ $this->authContextServiceMock = $this->createMock(AuthContextService::class);
+
+ $this->clientEntityMock = $this->createMock(ClientEntity::class);
+ $this->templateStub = $this->createStub(Template::class);
+ }
+
+ protected function getStubbedInstance(): ClientDeleteController
+ {
+ return new ClientDeleteController(
+ $this->clientRepositoryMock,
+ $this->templateFactoryMock,
+ $this->sessionMessageServiceMock,
+ $this->authContextServiceMock
+ );
+ }
+
+ public function testCanInstantiate(): void
+ {
+ $controller = $this->getStubbedInstance();
+ $this->assertInstanceOf(ClientDeleteController::class, $controller);
+ }
+
+ public function testItAsksConfirmationBeforeDeletingClient(): void
+ {
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+ $this->serverRequestMock->expects($this->once())->method('getParsedBody')->willReturn([]);
+ $this->serverRequestMock->expects($this->once())->method('getMethod')->willReturn('get');
+ $this->clientRepositoryMock->expects($this->once())->method('findById')->with('clientid')
+ ->willReturn($this->clientEntityMock);
+ $this->templateFactoryMock->expects($this->once())->method('render')
+ ->with('oidc:clients/delete.twig', ['client' => $this->clientEntityMock])
+ ->willReturn($this->templateStub);
+
+ $controller = $this->getStubbedInstance();
+
+ $this->assertInstanceOf(Template::class, $controller->__invoke($this->serverRequestMock));
+ }
+
+ public function testThrowsIfIdNotFoundInDeleteAction(): void
+ {
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')->willReturn([]);
+
+ $this->expectException(BadRequest::class);
+
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock);
+ }
+
+ public function testThrowsIfSecretNotFoundInDeleteAction(): void
+ {
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+ $this->serverRequestMock->expects($this->once())->method('getParsedBody')->willReturn([]);
+ $this->serverRequestMock->expects($this->once())->method('getMethod')->willReturn('post');
+ $this->clientRepositoryMock->expects($this->once())->method('findById')
+ ->willReturn($this->clientEntityMock);
+
+ $this->expectException(BadRequest::class);
+
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock);
+ }
+
+ public function testThrowsIfSecretIsInvalidInDeleteAction(): void
+ {
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+ $this->serverRequestMock->expects($this->once())->method('getParsedBody')
+ ->willReturn(['secret' => 'invalidsecret']);
+ $this->serverRequestMock->expects($this->once())->method('getMethod')->willReturn('post');
+ $this->clientEntityMock->expects($this->once())->method('getSecret')->willReturn('validsecret');
+ $this->clientRepositoryMock->expects($this->once())->method('findById')
+ ->willReturn($this->clientEntityMock);
+
+ $this->expectException(BadRequest::class);
+
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock);
+ }
+
+ public function testItDeletesClient(): void
+ {
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+ $this->serverRequestMock->expects($this->once())->method('getParsedBody')
+ ->willReturn(['secret' => 'validsecret']);
+ $this->serverRequestMock->expects($this->once())->method('getMethod')->willReturn('post');
+ $this->clientEntityMock->expects($this->once())->method('getSecret')->willReturn('validsecret');
+ $this->clientRepositoryMock->expects($this->once())->method('findById')
+ ->willReturn($this->clientEntityMock);
+ $this->clientRepositoryMock->expects($this->once())->method('delete')
+ ->with($this->clientEntityMock, null);
+ $this->sessionMessageServiceMock->expects($this->once())->method('addMessage')
+ ->with('{oidc:client:removed}');
+
+ $this->assertInstanceOf(
+ RedirectResponse::class,
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock)
+ );
+ }
+
+ public function testItDeletesClientWithOwner(): void
+ {
+ $this->authContextServiceMock->expects($this->exactly(2))->method('isSspAdmin')->willReturn(false);
+ $this->authContextServiceMock->expects($this->exactly(2))->method('getAuthUserId')->willReturn('theOwner');
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+ $this->serverRequestMock->expects($this->once())->method('getParsedBody')
+ ->willReturn(['secret' => 'validsecret']);
+ $this->serverRequestMock->expects($this->once())->method('getMethod')->willReturn('post');
+ $this->clientEntityMock->expects($this->once())->method('getSecret')->willReturn('validsecret');
+ $this->clientRepositoryMock->expects($this->once())->method('findById')
+ ->willReturn($this->clientEntityMock);
+ $this->clientRepositoryMock->expects($this->once())->method('delete')
+ ->with($this->clientEntityMock, 'theOwner');
+ $this->sessionMessageServiceMock->expects($this->once())->method('addMessage')
+ ->with('{oidc:client:removed}');
+
+ $this->assertInstanceOf(
+ RedirectResponse::class,
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock)
+ );
+ }
+}
diff --git a/tests/Controller/ClientEditControllerTest.php b/tests/Controller/ClientEditControllerTest.php
index 65e4377f..8848dd58 100644
--- a/tests/Controller/ClientEditControllerTest.php
+++ b/tests/Controller/ClientEditControllerTest.php
@@ -2,13 +2,348 @@
namespace SimpleSAML\Test\Module\oidc\Controller;
+use Laminas\Diactoros\Response\RedirectResponse;
+use Laminas\Diactoros\ServerRequest;
+use Psr\Http\Message\UriInterface;
+use SimpleSAML\Error\BadRequest;
+use SimpleSAML\Error\NotFound;
use SimpleSAML\Module\oidc\Controller\ClientEditController;
use PHPUnit\Framework\TestCase;
+use SimpleSAML\Module\oidc\Entity\ClientEntity;
+use SimpleSAML\Module\oidc\Factories\FormFactory;
+use SimpleSAML\Module\oidc\Factories\TemplateFactory;
+use SimpleSAML\Module\oidc\Form\ClientForm;
+use SimpleSAML\Module\oidc\Repositories\AllowedOriginRepository;
+use SimpleSAML\Module\oidc\Repositories\ClientRepository;
+use SimpleSAML\Module\oidc\Services\AuthContextService;
+use SimpleSAML\Module\oidc\Services\ConfigurationService;
+use SimpleSAML\Module\oidc\Services\SessionMessagesService;
+use SimpleSAML\XHTML\Template;
+/**
+ * @covers \SimpleSAML\Module\oidc\Controller\ClientEditController
+ */
class ClientEditControllerTest extends TestCase
{
- public function testIncomplete(): void
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $configurationServiceMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $clientRepositoryMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $allowedOriginRepositoryMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $templateFactoryMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $formFactoryMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $sessionMessageServiceMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $serverRequestMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\Stub
+ */
+ protected $uriStub;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $authContextServiceMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $clientEntityMock;
+ /**
+ * @var \PHPUnit\Framework\MockObject\Stub
+ */
+ protected $templateStub;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ protected $clientFormMock;
+
+ protected function setUp(): void
+ {
+ $this->configurationServiceMock = $this->createMock(ConfigurationService::class);
+ $this->clientRepositoryMock = $this->createMock(ClientRepository::class);
+ $this->allowedOriginRepositoryMock = $this->createMock(AllowedOriginRepository::class);
+ $this->templateFactoryMock = $this->createMock(TemplateFactory::class);
+ $this->formFactoryMock = $this->createMock(FormFactory::class);
+ $this->sessionMessageServiceMock = $this->createMock(SessionMessagesService::class);
+ $this->authContextServiceMock = $this->createMock(AuthContextService::class);
+ $this->serverRequestMock = $this->createMock(ServerRequest::class);
+ $this->uriStub = $this->createStub(UriInterface::class);
+
+ $this->clientEntityMock = $this->createMock(ClientEntity::class);
+ $this->templateStub = $this->createStub(Template::class);
+ $this->clientFormMock = $this->createMock(ClientForm::class);
+
+ $this->configurationServiceMock->method('getOpenIdConnectModuleURL')->willReturn('url');
+ $this->uriStub->method('getPath')->willReturn('/');
+ $this->serverRequestMock->method('getUri')->willReturn($this->uriStub);
+ $this->serverRequestMock->method('withQueryParams')->willReturn($this->serverRequestMock);
+ }
+
+ protected function getStubbedInstance(): ClientEditController
+ {
+ return new ClientEditController(
+ $this->configurationServiceMock,
+ $this->clientRepositoryMock,
+ $this->allowedOriginRepositoryMock,
+ $this->templateFactoryMock,
+ $this->formFactoryMock,
+ $this->sessionMessageServiceMock,
+ $this->authContextServiceMock
+ );
+ }
+
+ public function testItIsInitializable(): void
+ {
+ $this->assertInstanceOf(ClientEditController::class, $this->getStubbedInstance());
+ }
+
+ public function testItShowsEditClientForm(): void
+ {
+ $this->authContextServiceMock->method('isSspAdmin')->willReturn(true);
+
+ $data = [
+ 'id' => 'clientid',
+ 'secret' => 'validsecret',
+ 'name' => 'name',
+ 'description' => 'description',
+ 'auth_source' => 'auth_source',
+ 'redirect_uri' => ['http://localhost/redirect'],
+ 'scopes' => ['openid'],
+ 'is_enabled' => true,
+ 'allowed_origin' => [],
+ 'post_logout_redirect_uri' => [],
+ 'backchannel_logout_uri' => null,
+ ];
+
+ $this->clientEntityMock->expects($this->atLeastOnce())->method('getIdentifier')->willReturn('clientid');
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+ $this->clientEntityMock->expects($this->once())->method('toArray')->willReturn($data);
+ $this->clientRepositoryMock->expects($this->once())->method('findById')
+ ->willReturn($this->clientEntityMock);
+ $this->allowedOriginRepositoryMock->expects($this->once())->method('get')->with('clientid')
+ ->willReturn([]);
+ $this->clientFormMock->expects($this->once())->method('setAction');
+ $this->clientFormMock->expects($this->once())->method('setDefaults')->with($data);
+ $this->clientFormMock->expects($this->once())->method('isSuccess')->willReturn(false);
+ $this->formFactoryMock->expects($this->once())->method('build')->willReturn($this->clientFormMock);
+ $this->templateFactoryMock->expects($this->once())->method('render')->with(
+ 'oidc:clients/edit.twig',
+ [
+ 'form' => $this->clientFormMock,
+ 'regexUri' => ClientForm::REGEX_URI,
+ 'regexAllowedOriginUrl' => ClientForm::REGEX_ALLOWED_ORIGIN_URL,
+ 'regexHttpUri' => ClientForm::REGEX_HTTP_URI,
+ ]
+ )->willReturn($this->templateStub);
+
+ $this->assertSame(
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock),
+ $this->templateStub
+ );
+ }
+
+ public function testItUpdatesClientFromEditClientFormData(): void
+ {
+ $this->authContextServiceMock->method('isSspAdmin')->willReturn(true);
+
+ $data = [
+ 'id' => 'clientid',
+ 'secret' => 'validsecret',
+ 'name' => 'name',
+ 'description' => 'description',
+ 'auth_source' => 'auth_source',
+ 'redirect_uri' => ['http://localhost/redirect'],
+ 'scopes' => ['openid'],
+ 'is_enabled' => true,
+ 'is_confidential' => false,
+ 'owner' => 'existingOwner',
+ 'allowed_origin' => [],
+ 'post_logout_redirect_uri' => [],
+ 'backchannel_logout_uri' => null,
+ ];
+
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+
+ $this->clientEntityMock->expects($this->atLeastOnce())->method('getIdentifier')->willReturn('clientid');
+ $this->clientEntityMock->expects($this->once())->method('getSecret')->willReturn('validsecret');
+ $this->clientEntityMock->expects($this->once())->method('getOwner')->willReturn('existingOwner');
+ $this->clientEntityMock->expects($this->once())->method('toArray')->willReturn($data);
+
+ $this->clientRepositoryMock->expects($this->once())->method('findById')
+ ->willReturn($this->clientEntityMock);
+
+ $this->allowedOriginRepositoryMock->expects($this->once())->method('get')->with('clientid')
+ ->willReturn([]);
+
+ $this->clientFormMock->expects($this->once())->method('setAction');
+ $this->clientFormMock->expects($this->once())->method('setDefaults')->with($data);
+ $this->clientFormMock->expects($this->once())->method('isSuccess')->willReturn(true);
+ $this->clientFormMock->expects($this->once())->method('getValues')->willReturn(
+ [
+ 'name' => 'name',
+ 'description' => 'description',
+ 'auth_source' => 'auth_source',
+ 'redirect_uri' => ['http://localhost/redirect'],
+ 'scopes' => ['openid'],
+ 'is_enabled' => true,
+ 'is_confidential' => false,
+ 'owner' => 'existingOwner',
+ 'allowed_origin' => [],
+ 'post_logout_redirect_uri' => [],
+ 'backchannel_logout_uri' => null,
+ ]
+ );
+
+ $this->formFactoryMock->expects($this->once())->method('build')->willReturn($this->clientFormMock);
+
+ $this->clientRepositoryMock->expects($this->once())->method('update')->with(
+ ClientEntity::fromData(
+ 'clientid',
+ 'validsecret',
+ 'name',
+ 'description',
+ ['http://localhost/redirect'],
+ ['openid'],
+ true,
+ false,
+ 'auth_source',
+ 'existingOwner',
+ []
+ ),
+ null
+ );
+
+ $this->allowedOriginRepositoryMock->expects($this->once())->method('set')->with('clientid', []);
+ $this->sessionMessageServiceMock->expects($this->once())->method('addMessage')
+ ->with('{oidc:client:updated}');
+
+ $this->assertInstanceOf(
+ RedirectResponse::class,
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock)
+ );
+ }
+
+ public function testItSendsOwnerArgToRepoOnUpdate(): void
{
- $this->markTestIncomplete();
+ $this->authContextServiceMock->expects($this->atLeastOnce())->method('isSspAdmin')->willReturn(false);
+ $this->authContextServiceMock->method('getAuthUserId')->willReturn('authedUserId');
+ $data = [
+ 'id' => 'clientid',
+ 'secret' => 'validsecret',
+ 'name' => 'name',
+ 'description' => 'description',
+ 'auth_source' => 'auth_source',
+ 'redirect_uri' => ['http://localhost/redirect'],
+ 'scopes' => ['openid'],
+ 'is_enabled' => true,
+ 'is_confidential' => false,
+ 'owner' => 'existingOwner',
+ 'allowed_origin' => [],
+ 'post_logout_redirect_uri' => [],
+ 'backchannel_logout_uri' => null,
+ ];
+
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+
+ $this->clientEntityMock->expects($this->atLeastOnce())->method('getIdentifier')->willReturn('clientid');
+ $this->clientEntityMock->expects($this->once())->method('getSecret')->willReturn('validsecret');
+ $this->clientEntityMock->expects($this->once())->method('getOwner')->willReturn('existingOwner');
+ $this->clientEntityMock->expects($this->once())->method('toArray')->willReturn($data);
+
+ $this->clientRepositoryMock->expects($this->once())->method('findById')
+ ->with('clientid', 'authedUserId')->willReturn($this->clientEntityMock);
+
+ $this->allowedOriginRepositoryMock->expects($this->once())->method('get')->with('clientid')
+ ->willReturn([]);
+
+ $this->clientFormMock->expects($this->once())->method('setAction');
+ $this->clientFormMock->expects($this->once())->method('setDefaults')->with($data);
+ $this->clientFormMock->expects($this->once())->method('isSuccess')->willReturn(true);
+ $this->clientFormMock->expects($this->once())->method('getValues')->willReturn(
+ [
+ 'name' => 'name',
+ 'description' => 'description',
+ 'auth_source' => 'auth_source',
+ 'redirect_uri' => ['http://localhost/redirect'],
+ 'scopes' => ['openid'],
+ 'is_enabled' => true,
+ 'is_confidential' => false,
+ 'owner' => 'existingOwner',
+ 'allowed_origin' => [],
+ 'post_logout_redirect_uri' => [],
+ 'backchannel_logout_uri' => null,
+ ]
+ );
+
+ $this->formFactoryMock->expects($this->once())->method('build')->willReturn($this->clientFormMock);
+
+ $this->clientRepositoryMock->expects($this->once())->method('update')->with(
+ ClientEntity::fromData(
+ 'clientid',
+ 'validsecret',
+ 'name',
+ 'description',
+ ['http://localhost/redirect'],
+ ['openid'],
+ true,
+ false,
+ 'auth_source',
+ 'existingOwner',
+ [],
+ null
+ ),
+ 'authedUserId'
+ );
+
+ $this->allowedOriginRepositoryMock->expects($this->once())->method('get')->with('clientid')
+ ->willReturn([]);
+ $this->allowedOriginRepositoryMock->expects($this->once())->method('set')->with('clientid', []);
+ $this->sessionMessageServiceMock->expects($this->once())->method('addMessage')
+ ->with('{oidc:client:updated}');
+
+ $this->assertInstanceOf(
+ RedirectResponse::class,
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock)
+ );
+ }
+
+ public function testThrowsIdNotFoundExceptionInEditAction(): void
+ {
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')->willReturn([]);
+
+ $this->expectException(BadRequest::class);
+
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock);
+ }
+
+ public function testThrowsClientNotFoundExceptionInEditAction(): void
+ {
+ $this->serverRequestMock->expects($this->once())->method('getQueryParams')
+ ->willReturn(['client_id' => 'clientid']);
+ $this->clientRepositoryMock->expects($this->once())->method('findById')->willReturn(null);
+
+ $this->expectException(\Exception::class);
+
+ ($this->getStubbedInstance())->__invoke($this->serverRequestMock);
}
}
diff --git a/tests/Controller/ClientIndexControllerTest.php b/tests/Controller/ClientIndexControllerTest.php
new file mode 100644
index 00000000..3385e907
--- /dev/null
+++ b/tests/Controller/ClientIndexControllerTest.php
@@ -0,0 +1,104 @@
+clientRepositoryMock = $this->createMock(ClientRepository::class);
+ $this->templateFactoryMock = $this->createMock(TemplateFactory::class);
+ $this->authContextServiceMock = $this->createMock(AuthContextService::class);
+ $this->serverRequestMock = $this->createMock(ServerRequest::class);
+ $this->uriStub = $this->createStub(UriInterface::class);
+
+ $this->templateStub = $this->createStub(Template::class);
+
+ $this->authContextServiceMock->method('isSspAdmin')->willReturn(true);
+ $this->uriStub->method('getPath')->willReturn('/');
+ $this->serverRequestMock->method('getUri')->willReturn($this->uriStub);
+ $this->serverRequestMock->method('getQueryParams')->willReturn(['page' => 1]);
+ }
+
+ protected function getStubbedInstance(): ClientIndexController
+ {
+ return new ClientIndexController(
+ $this->clientRepositoryMock,
+ $this->templateFactoryMock,
+ $this->authContextServiceMock
+ );
+ }
+
+ public function testItIsInitializable(): void
+ {
+ $this->assertInstanceOf(ClientIndexController::class, $this->getStubbedInstance());
+ }
+
+ public function testItShowsClientIndex(): void
+ {
+ $this->clientRepositoryMock->expects($this->once())->method('findPaginated')
+ ->with(1, '', null)
+ ->willReturn(
+ [
+ 'items' => [],
+ 'numPages' => 1,
+ 'currentPage' => 1
+ ]
+ );
+
+ $this->templateFactoryMock->expects($this->once())->method('render')->with(
+ 'oidc:clients/index.twig',
+ [
+ 'clients' => [],
+ 'numPages' => 1,
+ 'currentPage' => 1,
+ 'query' => '',
+ ]
+ )->willReturn($this->templateStub);
+
+ $this->assertSame($this->templateStub, ($this->getStubbedInstance())->__invoke($this->serverRequestMock));
+ }
+}
diff --git a/tests/Repositories/AccessTokenRepositoryTest.php b/tests/Repositories/AccessTokenRepositoryTest.php
index 59a373b3..bfcb19b5 100644
--- a/tests/Repositories/AccessTokenRepositoryTest.php
+++ b/tests/Repositories/AccessTokenRepositoryTest.php
@@ -44,7 +44,7 @@ public static function setUpBeforeClass(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Repositories/AllowedOriginRepositoryTest.php b/tests/Repositories/AllowedOriginRepositoryTest.php
index 53413032..00a17019 100644
--- a/tests/Repositories/AllowedOriginRepositoryTest.php
+++ b/tests/Repositories/AllowedOriginRepositoryTest.php
@@ -39,7 +39,7 @@ public static function setUpBeforeClass(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Repositories/AuthCodeRepositoryTest.php b/tests/Repositories/AuthCodeRepositoryTest.php
index 5662f74e..a25d6ef3 100644
--- a/tests/Repositories/AuthCodeRepositoryTest.php
+++ b/tests/Repositories/AuthCodeRepositoryTest.php
@@ -45,7 +45,7 @@ public static function setUpBeforeClass(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Repositories/ClientRepositoryTest.php b/tests/Repositories/ClientRepositoryTest.php
index a1a14bcd..d52be588 100644
--- a/tests/Repositories/ClientRepositoryTest.php
+++ b/tests/Repositories/ClientRepositoryTest.php
@@ -38,7 +38,7 @@ public static function setUpBeforeClass(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Repositories/RefreshTokenRepositoryTest.php b/tests/Repositories/RefreshTokenRepositoryTest.php
index 1faea6f9..be1fcf0e 100644
--- a/tests/Repositories/RefreshTokenRepositoryTest.php
+++ b/tests/Repositories/RefreshTokenRepositoryTest.php
@@ -46,7 +46,7 @@ public static function setUpBeforeClass(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Repositories/ScopeRepositoryTest.php b/tests/Repositories/ScopeRepositoryTest.php
index 235ef85d..867154f4 100644
--- a/tests/Repositories/ScopeRepositoryTest.php
+++ b/tests/Repositories/ScopeRepositoryTest.php
@@ -32,7 +32,7 @@ public static function setUpBeforeClass(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Repositories/UserRepositoryTest.php b/tests/Repositories/UserRepositoryTest.php
index 893775a2..bce4fd09 100644
--- a/tests/Repositories/UserRepositoryTest.php
+++ b/tests/Repositories/UserRepositoryTest.php
@@ -36,7 +36,7 @@ protected function setUp(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Server/Grants/AuthCodeGrantTest.php b/tests/Server/Grants/AuthCodeGrantTest.php
index a1027bb4..a309c619 100644
--- a/tests/Server/Grants/AuthCodeGrantTest.php
+++ b/tests/Server/Grants/AuthCodeGrantTest.php
@@ -16,24 +16,24 @@
class AuthCodeGrantTest extends TestCase
{
/**
- * @var \PHPUnit\Framework\MockObject\Stub|AuthCodeRepositoryInterface
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $authCodeRepositoryStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|AccessTokenRepositoryInterface
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $accessTokenRepositoryStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|RefreshTokenRepositoryInterface
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $refreshTokenRepositoryStub;
protected \DateInterval $authCodeTtl;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|RequestRulesManager
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $requestRulesManagerStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|ConfigurationService
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $configurationServiceStub;
diff --git a/tests/Server/Validators/BearerTokenValidatorTest.php b/tests/Server/Validators/BearerTokenValidatorTest.php
index f47d6029..66a28d07 100644
--- a/tests/Server/Validators/BearerTokenValidatorTest.php
+++ b/tests/Server/Validators/BearerTokenValidatorTest.php
@@ -111,7 +111,7 @@ public static function setUpBeforeClass(): void
Configuration::loadFromArray($config, '', 'simplesaml');
self::$publicKeyPath = $tempDir . '/oidc_module.crt';
- self::$privateKeyPath = $tempDir . '/oidc_module.pem';
+ self::$privateKeyPath = $tempDir . '/oidc_module.key';
$pkGenerate = openssl_pkey_new([
'private_key_bits' => 2048,
diff --git a/tests/Services/ConfigurationServiceTest.php b/tests/Services/ConfigurationServiceTest.php
index 8fff8e6e..cdbce5af 100644
--- a/tests/Services/ConfigurationServiceTest.php
+++ b/tests/Services/ConfigurationServiceTest.php
@@ -26,20 +26,20 @@ public function testSigningKeyNameCanBeCustomized(): void
// Test default cert and pem
$service = new ConfigurationService();
$this->assertEquals($certDir . 'oidc_module.crt', $service->getCertPath());
- $this->assertEquals($certDir . 'oidc_module.pem', $service->getPrivateKeyPath());
+ $this->assertEquals($certDir . 'oidc_module.key', $service->getPrivateKeyPath());
// Set customized
Configuration::setPreLoadedConfig(
Configuration::loadFromArray(
[
'privatekey' => 'myPrivateKey.key',
- 'certificate' => 'myCertificate.pem',
+ 'certificate' => 'myCertificate.crt',
]
),
'module_oidc.php'
);
$service = new ConfigurationService();
- $this->assertEquals($certDir . 'myCertificate.pem', $service->getCertPath());
+ $this->assertEquals($certDir . 'myCertificate.crt', $service->getCertPath());
$this->assertEquals($certDir . 'myPrivateKey.key', $service->getPrivateKeyPath());
}
}
diff --git a/tests/Services/JsonWebKeySetServiceTest.php b/tests/Services/JsonWebKeySetServiceTest.php
index d3ca5721..20037bc9 100644
--- a/tests/Services/JsonWebKeySetServiceTest.php
+++ b/tests/Services/JsonWebKeySetServiceTest.php
@@ -40,16 +40,10 @@ public static function setUpBeforeClass(): void
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]);
- // get the private key
- openssl_pkey_export($pkGenerate, $pkGeneratePrivate);
-
// get the public key
$pkGenerateDetails = openssl_pkey_get_details($pkGenerate);
self::$pkGeneratePublic = $pkGenerateDetails['key'];
- // free resources
- openssl_pkey_free($pkGenerate);
-
file_put_contents(sys_get_temp_dir() . '/oidc_module.crt', self::$pkGeneratePublic);
Configuration::setPreLoadedConfig(
diff --git a/tests/Services/JsonWebTokenBuilderServiceTest.php b/tests/Services/JsonWebTokenBuilderServiceTest.php
index 6a92d5fe..b1c940e1 100644
--- a/tests/Services/JsonWebTokenBuilderServiceTest.php
+++ b/tests/Services/JsonWebTokenBuilderServiceTest.php
@@ -34,7 +34,7 @@ class JsonWebTokenBuilderServiceTest extends TestCase
public static function setUpBeforeClass(): void
{
self::$certFolder = dirname(__DIR__, 2) . '/docker/ssp/';
- self::$privateKeyPath = self::$certFolder . 'oidc_module.pem';
+ self::$privateKeyPath = self::$certFolder . 'oidc_module.key';
self::$publicKeyPath = self::$certFolder . 'oidc_module.crt';
self::$signerSha256 = new Sha256();
}
diff --git a/tests/Services/LogoutTokenBuilderTest.php b/tests/Services/LogoutTokenBuilderTest.php
index a838edf2..4b6f1cd7 100644
--- a/tests/Services/LogoutTokenBuilderTest.php
+++ b/tests/Services/LogoutTokenBuilderTest.php
@@ -46,7 +46,7 @@ class LogoutTokenBuilderTest extends TestCase
public static function setUpBeforeClass(): void
{
self::$certFolder = dirname(__DIR__, 2) . '/docker/ssp/';
- self::$privateKeyPath = self::$certFolder . 'oidc_module.pem';
+ self::$privateKeyPath = self::$certFolder . 'oidc_module.key';
self::$publicKeyPath = self::$certFolder . 'oidc_module.crt';
self::$signerSha256 = new Sha256();
}
diff --git a/tests/Store/SessionLogoutTicketStoreBuilderTest.php b/tests/Store/SessionLogoutTicketStoreBuilderTest.php
index ae1eda72..0eb62732 100644
--- a/tests/Store/SessionLogoutTicketStoreBuilderTest.php
+++ b/tests/Store/SessionLogoutTicketStoreBuilderTest.php
@@ -20,7 +20,7 @@ public function testConstructWithDefaultStore(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Store/SessionLogoutTicketStoreDbTest.php b/tests/Store/SessionLogoutTicketStoreDbTest.php
index b2edb2d5..fb113c8c 100644
--- a/tests/Store/SessionLogoutTicketStoreDbTest.php
+++ b/tests/Store/SessionLogoutTicketStoreDbTest.php
@@ -21,7 +21,7 @@ public static function setUpBeforeClass(): void
'database.password' => null,
'database.prefix' => 'phpunit_',
'database.persistent' => true,
- 'database.slaves' => [],
+ 'database.secondaries' => [],
];
Configuration::loadFromArray($config, '', 'simplesaml');
diff --git a/tests/Utils/Checker/Rules/IdTokenHintRuleTest.php b/tests/Utils/Checker/Rules/IdTokenHintRuleTest.php
index ba50156d..a5b8ada7 100644
--- a/tests/Utils/Checker/Rules/IdTokenHintRuleTest.php
+++ b/tests/Utils/Checker/Rules/IdTokenHintRuleTest.php
@@ -43,7 +43,7 @@ class IdTokenHintRuleTest extends TestCase
public static function setUpBeforeClass(): void
{
self::$certFolder = dirname(__DIR__, 4) . '/docker/ssp/';
- self::$privateKeyPath = self::$certFolder . 'oidc_module.pem';
+ self::$privateKeyPath = self::$certFolder . 'oidc_module.key';
self::$publicKeyPath = self::$certFolder . 'oidc_module.crt';
self::$privateKey = new CryptKey(self::$privateKeyPath, null, false);
self::$publicKey = new CryptKey(self::$publicKeyPath, null, false);
@@ -66,6 +66,7 @@ protected function setUp(): void
$this->cryptKeyFactoryStub->method('buildPrivateKey')->willReturn(self::$privateKey);
$this->cryptKeyFactoryStub->method('buildPublicKey')->willReturn(self::$publicKey);
+ /** @psalm-suppress ArgumentTypeCoercion */
$this->jwtConfig = Configuration::forAsymmetricSigner(
$this->configurationServiceStub->getSigner(),
InMemory::plainText(self::$privateKey->getKeyContents()),
@@ -90,6 +91,7 @@ public function testConstruct(): void
public function testCheckRuleIsNullWhenParamNotSet(): void
{
$rule = new IdTokenHintRule($this->configurationServiceStub, $this->cryptKeyFactoryStub);
+ $this->requestStub->method('getMethod')->willReturn('');
$result = $rule->checkRule(
$this->requestStub,
$this->resultBagStub,
@@ -138,6 +140,7 @@ public function testCheckRuleThrowsForIdTokenWithInvalidIssuer(): void
{
$this->requestStub->method('getMethod')->willReturn('GET');
+ /** @psalm-suppress ArgumentTypeCoercion */
$invalidIssuerJwt = $this->jwtConfig->builder()->issuedBy('invalid')->getToken(
$this->configurationServiceStub->getSigner(),
InMemory::plainText(self::$privateKey->getKeyContents())
@@ -158,6 +161,7 @@ public function testCheckRulePassesForValidIdToken(): void
{
$this->requestStub->method('getMethod')->willReturn('GET');
+ /** @psalm-suppress ArgumentTypeCoercion */
$idToken = $this->jwtConfig->builder()->issuedBy(self::$issuer)->getToken(
$this->configurationServiceStub->getSigner(),
InMemory::plainText(self::$privateKey->getKeyContents())
diff --git a/tests/Utils/Checker/Rules/PostLogoutRedirectUriRuleTest.php b/tests/Utils/Checker/Rules/PostLogoutRedirectUriRuleTest.php
index f3204185..d73557ac 100644
--- a/tests/Utils/Checker/Rules/PostLogoutRedirectUriRuleTest.php
+++ b/tests/Utils/Checker/Rules/PostLogoutRedirectUriRuleTest.php
@@ -44,7 +44,7 @@ class PostLogoutRedirectUriRuleTest extends TestCase
public static function setUpBeforeClass(): void
{
self::$certFolder = dirname(__DIR__, 4) . '/docker/ssp/';
- self::$privateKeyPath = self::$certFolder . 'oidc_module.pem';
+ self::$privateKeyPath = self::$certFolder . 'oidc_module.key';
self::$publicKeyPath = self::$certFolder . 'oidc_module.crt';
self::$privateKey = new CryptKey(self::$privateKeyPath, null, false);
self::$publicKey = new CryptKey(self::$publicKeyPath, null, false);
@@ -58,6 +58,7 @@ protected function setUp(): void
$this->resultBagStub = $this->createStub(ResultBagInterface::class);
$this->clientStub = $this->createStub(ClientEntityInterface::class);
+ /** @psalm-suppress ArgumentTypeCoercion */
$this->jwtConfig = Configuration::forAsymmetricSigner(
new Sha256(),
InMemory::plainText(self::$privateKey->getKeyContents()),
@@ -103,6 +104,7 @@ public function testCheckRuleThrowsWhenAudClaimNotValid(): void
$this->requestStub->method('getQueryParams')
->willReturn(['post_logout_redirect_uri' => self::$postLogoutRedirectUri]);
+ /** @psalm-suppress ArgumentTypeCoercion */
$jwt = $this->jwtConfig->builder()->issuedBy(self::$issuer)
->getToken(
new Sha256(),
@@ -130,6 +132,7 @@ public function testCheckRuleThrowsWhenClientNotFound(): void
$this->requestStub->method('getQueryParams')
->willReturn(['post_logout_redirect_uri' => self::$postLogoutRedirectUri]);
+ /** @psalm-suppress ArgumentTypeCoercion */
$jwt = $this->jwtConfig->builder()
->issuedBy(self::$issuer)
->permittedFor('invalid-client-id')
@@ -160,6 +163,7 @@ public function testCheckRuleThrowsWhenPostLogoutRegisteredUriNotRegistered(): v
$this->requestStub->method('getQueryParams')
->willReturn(['post_logout_redirect_uri' => self::$postLogoutRedirectUri]);
+ /** @psalm-suppress ArgumentTypeCoercion */
$jwt = $this->jwtConfig->builder()
->issuedBy(self::$issuer)
->permittedFor('client-id')
@@ -195,6 +199,7 @@ public function testCheckRuleReturnsForRegisteredPostLogoutRedirectUri(): void
$this->requestStub->method('getQueryParams')
->willReturn(['post_logout_redirect_uri' => self::$postLogoutRedirectUri]);
+ /** @psalm-suppress ArgumentTypeCoercion */
$jwt = $this->jwtConfig->builder()
->issuedBy(self::$issuer)
->permittedFor('client-id')
diff --git a/tests/Utils/Checker/Rules/ScopeOfflineAccessRuleTest.php b/tests/Utils/Checker/Rules/ScopeOfflineAccessRuleTest.php
index 93587999..266c0539 100644
--- a/tests/Utils/Checker/Rules/ScopeOfflineAccessRuleTest.php
+++ b/tests/Utils/Checker/Rules/ScopeOfflineAccessRuleTest.php
@@ -21,51 +21,51 @@
class ScopeOfflineAccessRuleTest extends TestCase
{
/**
- * @var \PHPUnit\Framework\MockObject\Stub|ServerRequestInterface
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $serverRequestStub;
/**
- * @var \PHPUnit\Framework\MockObject\MockObject|ResultBagInterface
+ * @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $resultBagMock;
/**
- * @var \PHPUnit\Framework\MockObject\MockObject|LoggerService
+ * @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $loggerServiceMock;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|ClientEntityInterface
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $clientStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|ScopeEntityInterface
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $scopeEntityOpenid;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|ScopeEntityInterface
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $scopeEntityOfflineAccess;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|Result
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $redirectUriResultStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|Result
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $stateResultStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|Result
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $clientResultStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|Result
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $validScopesResultStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|ConfigurationService
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $configurationServiceStub;
/**
- * @var \PHPUnit\Framework\MockObject\Stub|Configuration
+ * @var \PHPUnit\Framework\MockObject\Stub
*/
protected $openIdConfigurationStub;
@@ -102,31 +102,6 @@ public function testCanCreateInstance(): void
);
}
- public function testReturnsTrueWhenDeployerSetToAlwaysIssueRefreshToken(): void
- {
- $this->clientStub->method('getScopes')->willReturn(['openid']);
- $this->clientResultStub->method('getValue')->willReturn($this->clientStub);
- $this->validScopesResultStub->method('getValue')->willReturn([$this->scopeEntityOpenid]);
-
- $this->resultBagMock
- ->method('getOrFail')
- ->willReturnOnConsecutiveCalls(
- $this->redirectUriResultStub,
- $this->stateResultStub,
- $this->clientResultStub,
- $this->validScopesResultStub
- );
-
- $this->openIdConfigurationStub->method('getBoolean')->willReturn(true);
- $this->configurationServiceStub->method('getOpenIDConnectConfiguration')
- ->willReturn($this->openIdConfigurationStub);
-
- $result = (new ScopeOfflineAccessRule($this->configurationServiceStub))
- ->checkRule($this->serverRequestStub, $this->resultBagMock, $this->loggerServiceMock);
-
- $this->assertTrue($result->getValue());
- }
-
public function testReturnsFalseWhenOfflineAccessScopeNotPresent(): void
{
$this->clientStub->method('getScopes')->willReturn(['openid']);
@@ -149,6 +124,7 @@ public function testReturnsFalseWhenOfflineAccessScopeNotPresent(): void
$result = (new ScopeOfflineAccessRule($this->configurationServiceStub))
->checkRule($this->serverRequestStub, $this->resultBagMock, $this->loggerServiceMock);
+ $this->assertNotNull($result);
$this->assertFalse($result->getValue());
}
@@ -201,6 +177,7 @@ public function testReturnsTrueWhenClientDoesHaveOfflineAccessScopeRegistered():
$result = (new ScopeOfflineAccessRule($this->configurationServiceStub))
->checkRule($this->serverRequestStub, $this->resultBagMock, $this->loggerServiceMock);
+ $this->assertNotNull($result);
$this->assertTrue($result->getValue());
}
}
| |