Strengthen settings gateway tests

This commit is contained in:
2026-03-19 20:32:34 +01:00
parent bc59ace240
commit b873efc973
4 changed files with 157 additions and 26 deletions

View File

@@ -50,4 +50,46 @@ class SettingsMicrosoftGatewayTest extends TestCase
$gateway = new SettingsMicrosoftGateway(new SettingsMetadataGateway($settings), $crypto);
$this->assertTrue($gateway->setMicrosoftSharedClientSecret('secret-value'));
}
public function testSetMicrosoftSharedClientSecretReturnsFalseWhenEncryptionFails(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->expects($this->never())->method('set');
$crypto = $this->createMock(SettingsCryptoGatewayInterface::class);
$crypto->expects($this->once())
->method('encryptString')
->with('secret-value')
->willThrowException(new \RuntimeException('encryption failed'));
$gateway = new SettingsMicrosoftGateway(new SettingsMetadataGateway($settings), $crypto);
$this->assertFalse($gateway->setMicrosoftSharedClientSecret('secret-value'));
}
public function testSetMicrosoftSharedClientSecretClearsSettingWhenEmpty(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->expects($this->once())
->method('set')
->with('microsoft_shared_client_secret_enc', null, 'setting.microsoft_shared_client_secret_enc')
->willReturn(true);
$crypto = $this->createMock(SettingsCryptoGatewayInterface::class);
$crypto->expects($this->never())->method('encryptString');
$gateway = new SettingsMicrosoftGateway(new SettingsMetadataGateway($settings), $crypto);
$this->assertTrue($gateway->setMicrosoftSharedClientSecret(' '));
}
public function testGetMicrosoftAuthorityFallsBackAndTrimsTrailingSlash(): void
{
$settings = $this->createMock(SettingRepositoryInterface::class);
$settings->method('getValue')->willReturnOnConsecutiveCalls(null, 'https://login.microsoftonline.com/common/v2.0/');
$crypto = $this->createMock(SettingsCryptoGatewayInterface::class);
$gateway = new SettingsMicrosoftGateway(new SettingsMetadataGateway($settings), $crypto);
$this->assertSame('https://login.microsoftonline.com/common/v2.0', $gateway->getMicrosoftAuthority());
$this->assertSame('https://login.microsoftonline.com/common/v2.0', $gateway->getMicrosoftAuthority());
}
}