Cluster 1 der Testabdeckungs-Initiative (.agents/runs/TEST-SEC-COVERAGE-001). +38 Tests / +233 Assertions, nur tests/** veraendert. - SettingsAuthorizationPolicyTest: Allow-Pfade fuer UPDATE/BRANDING_UPDATE/ TOKENS_REVOKE/USER_LIFECYCLE_RUN plus Unknown-Ability — schliesst die Halb-Test-Luecke, die zuvor nur Deny-Pfade fuer 4 von 5 Abilities pruefte. - AssignableRoleServiceTest: neu (GR-TEST-001, vorher nur transitiv via UserAssignmentServiceTest gedeckt). - AuthCryptoGatewayTest: neu (Roundtrip + Fehlerpfad, GR-SEC-005). - AuthSettingsGatewayTest: neu (Delegation zu 5 Settings-Sub-Gateways). - UserTenantContextServiceTest: neu, 18 Tests, Tenant-Scope-Logik (GR-SEC-009) — current/primary/fallback, inactive-filter, assign-checks. LdapConnectionGateway und OidcHttpGateway bleiben bewusst ohne Direkttests: beide sind architektonische Test-Seams (dokumentiert im Docblock bzw. reiner statischer Curl-Delegator). Ihre Logik ist ueber Konsumenten-Tests (LdapAuthServiceTest, MicrosoftOidcServiceTest) bereits gedeckt. Gates: QG-001 (1945 Tests) / QG-002 (PHPStan L5) / QG-003 (Architecture) / QG-006 (php-cs-fixer) pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
109 lines
4.6 KiB
PHP
109 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Service\Auth;
|
|
|
|
use MintyPHP\Service\Auth\AuthSettingsGateway;
|
|
use MintyPHP\Service\Settings\SettingsApiPolicyGateway;
|
|
use MintyPHP\Service\Settings\SettingsAppGateway;
|
|
use MintyPHP\Service\Settings\SettingsDefaultsGateway;
|
|
use MintyPHP\Service\Settings\SettingsLoginPersistenceGateway;
|
|
use MintyPHP\Service\Settings\SettingsMicrosoftGateway;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class AuthSettingsGatewayTest extends TestCase
|
|
{
|
|
public function testMicrosoftAccessorsDelegateAndCastToString(): void
|
|
{
|
|
$microsoft = $this->createMock(SettingsMicrosoftGateway::class);
|
|
$microsoft->method('getMicrosoftSharedClientId')->willReturn('client-id');
|
|
$microsoft->method('getMicrosoftSharedClientSecret')->willReturn('secret');
|
|
$microsoft->method('getMicrosoftAuthority')->willReturn('https://login.microsoftonline.com/tenant');
|
|
|
|
$gateway = $this->makeGateway(microsoft: $microsoft);
|
|
|
|
$this->assertSame('client-id', $gateway->getMicrosoftSharedClientId());
|
|
$this->assertSame('secret', $gateway->getMicrosoftSharedClientSecret());
|
|
$this->assertSame('https://login.microsoftonline.com/tenant', $gateway->getMicrosoftAuthority());
|
|
}
|
|
|
|
public function testMicrosoftAccessorsReturnEmptyStringWhenUnconfigured(): void
|
|
{
|
|
$microsoft = $this->createMock(SettingsMicrosoftGateway::class);
|
|
$microsoft->method('getMicrosoftSharedClientId')->willReturn('');
|
|
$microsoft->method('getMicrosoftSharedClientSecret')->willReturn('');
|
|
$microsoft->method('getMicrosoftAuthority')->willReturn('');
|
|
|
|
$gateway = $this->makeGateway(microsoft: $microsoft);
|
|
|
|
$this->assertSame('', $gateway->getMicrosoftSharedClientId());
|
|
$this->assertSame('', $gateway->getMicrosoftSharedClientSecret());
|
|
$this->assertSame('', $gateway->getMicrosoftAuthority());
|
|
}
|
|
|
|
public function testApiTokenTtlAccessorsDelegate(): void
|
|
{
|
|
$apiPolicy = $this->createMock(SettingsApiPolicyGateway::class);
|
|
$apiPolicy->method('getApiTokenMaxTtlDays')->willReturn(90);
|
|
$apiPolicy->method('getApiTokenDefaultTtlDays')->willReturn(30);
|
|
|
|
$gateway = $this->makeGateway(apiPolicy: $apiPolicy);
|
|
|
|
$this->assertSame(90, $gateway->getApiTokenMaxTtlDays());
|
|
$this->assertSame(30, $gateway->getApiTokenDefaultTtlDays());
|
|
}
|
|
|
|
public function testAppThemeAccessorsDelegate(): void
|
|
{
|
|
$app = $this->createMock(SettingsAppGateway::class);
|
|
$app->method('getAppTheme')->willReturn('dark');
|
|
$app->method('resolveDefaultTheme')->willReturn('light');
|
|
$app->expects($this->once())->method('normalizeTheme')->with('DARK')->willReturn('dark');
|
|
|
|
$gateway = $this->makeGateway(app: $app);
|
|
|
|
$this->assertSame('dark', $gateway->getAppTheme());
|
|
$this->assertSame('light', $gateway->defaultTheme());
|
|
$this->assertSame('dark', $gateway->normalizeTheme('DARK'));
|
|
}
|
|
|
|
public function testDefaultsAccessorsCastToInt(): void
|
|
{
|
|
$defaults = $this->createMock(SettingsDefaultsGateway::class);
|
|
$defaults->method('getDefaultRoleId')->willReturn(5);
|
|
$defaults->method('getDefaultDepartmentId')->willReturn(12);
|
|
|
|
$gateway = $this->makeGateway(defaults: $defaults);
|
|
|
|
$this->assertSame(5, $gateway->getDefaultRoleId());
|
|
$this->assertSame(12, $gateway->getDefaultDepartmentId());
|
|
}
|
|
|
|
public function testLoginPersistenceAccessorsDelegate(): void
|
|
{
|
|
$login = $this->createMock(SettingsLoginPersistenceGateway::class);
|
|
$login->method('isMicrosoftAutoRememberDefault')->willReturn(true);
|
|
$login->method('getRememberTokenLifetimeDays')->willReturn(14);
|
|
|
|
$gateway = $this->makeGateway(login: $login);
|
|
|
|
$this->assertTrue($gateway->isMicrosoftAutoRememberDefault());
|
|
$this->assertSame(14, $gateway->getRememberTokenLifetimeDays());
|
|
}
|
|
|
|
private function makeGateway(
|
|
?SettingsMicrosoftGateway $microsoft = null,
|
|
?SettingsApiPolicyGateway $apiPolicy = null,
|
|
?SettingsDefaultsGateway $defaults = null,
|
|
?SettingsAppGateway $app = null,
|
|
?SettingsLoginPersistenceGateway $login = null,
|
|
): AuthSettingsGateway {
|
|
return new AuthSettingsGateway(
|
|
$microsoft ?? $this->createMock(SettingsMicrosoftGateway::class),
|
|
$apiPolicy ?? $this->createMock(SettingsApiPolicyGateway::class),
|
|
$defaults ?? $this->createMock(SettingsDefaultsGateway::class),
|
|
$app ?? $this->createMock(SettingsAppGateway::class),
|
|
$login ?? $this->createMock(SettingsLoginPersistenceGateway::class),
|
|
);
|
|
}
|
|
}
|