Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPF-435 Added scope config for Keycloak #1081

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 28 additions & 0 deletions app/Keycloak/ScopeConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Keycloak;

use App\Domain\Integrations\Integration;
use App\Domain\Integrations\IntegrationType;
use Ramsey\Uuid\UuidInterface;

final class ScopeConfig
{
public function __construct(
public UuidInterface $searchApi,
grubolsch marked this conversation as resolved.
Show resolved Hide resolved
public UuidInterface $entryApi,
public UuidInterface $widgets,
) {
}

public function getScopeIdFromIntegrationType(Integration $integration): UuidInterface
{
return match ($integration->type) {
IntegrationType::EntryApi => $this->entryApi,
IntegrationType::Widgets => $this->widgets,
IntegrationType::SearchApi => $this->searchApi
};
}
}
5 changes: 5 additions & 0 deletions config/keycloak.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
'base_url' => env('KEYCLOAK_BASE_URL', ''),
'client_id' => env('KEYCLOAK_CLIENT_ID', ''),
'client_secret' => env('KEYCLOAK_CLIENT_SECRET', ''),
'scope' => [
'search_api_id' => env('KEYCLOAK_SCOPE_SEARCH_API_ID', ''),
'entry_api_id' => env('KEYCLOAK_SCOPE_ENTRY_API_ID', ''),
'widgets_id' => env('KEYCLOAK_SCOPE_WIDGETS_ID', ''),
],
];
28 changes: 28 additions & 0 deletions tests/IntegrationHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Tests;

use App\Domain\Integrations\Integration;
use App\Domain\Integrations\IntegrationPartnerStatus;
use App\Domain\Integrations\IntegrationStatus;
use App\Domain\Integrations\IntegrationType;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

trait IntegrationHelper
{
public function createIntegration(UuidInterface $integrationId, array $options = []): Integration
grubolsch marked this conversation as resolved.
Show resolved Hide resolved
{
return new Integration(
$integrationId,
$options['type'] ?? IntegrationType::SearchApi,
$options['name'] ?? 'Mock Integration',
$options['description'] ?? 'Mock description',
Uuid::uuid4(),
$options['status'] ?? IntegrationStatus::Draft,
$options['partnerStatus'] ?? IntegrationPartnerStatus::THIRD_PARTY,
);
}
}
52 changes: 52 additions & 0 deletions tests/Keycloak/ScopeConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Tests\Keycloak;

use App\Domain\Integrations\IntegrationType;
use App\Keycloak\ScopeConfig;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
use Tests\IntegrationHelper;

final class ScopeConfigTest extends TestCase
{
use IntegrationHelper;

private const SEARCH_API_ID = '41255857-b8ad-44ce-9a17-db72540461b7';
private const ENTRY_API_ID = '824c09c0-2f3a-4fa0-bde2-8bf25c9a5b74';
private const WIDGETS_ID = 'deb654ab-1324-48ca-9931-1485a456c916';

private ScopeConfig $scopeConfig;

protected function setUp(): void
{
$this->scopeConfig = new ScopeConfig(
Uuid::fromString(self::SEARCH_API_ID),
Uuid::fromString(self::ENTRY_API_ID),
Uuid::fromString(self::WIDGETS_ID)
);
}

/**
* @dataProvider integrationDataProvider
*/
public function test_get_scope_id_from_integration(IntegrationType $type, string $expectedScopeId): void
{
$actualScopeId = $this->scopeConfig->getScopeIdFromIntegrationType(
$this->createIntegration(Uuid::uuid4(), ['type' => $type])
);

$this->assertEquals($expectedScopeId, $actualScopeId->toString());
}

public static function integrationDataProvider(): array
{
return [
[IntegrationType::SearchApi, self::SEARCH_API_ID],
[IntegrationType::EntryApi, self::ENTRY_API_ID],
[IntegrationType::Widgets, self::WIDGETS_ID],
];
}
}
Loading