From 766b4d3228e0f60f433faeb8fad444679b1782f4 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Mon, 15 Dec 2025 16:28:52 -0300 Subject: [PATCH 1/4] fix: prevent stale configPath and CA ID exposure in root certificate API Filter configPath from API response when certificate is not generated to prevent form pre-population with outdated generation numbers that cause validation errors. Filter CA ID (libresign-ca-id:*) from OrganizationalUnit field to prevent users from submitting stale generation values that conflict with certificate validation. Refactor toArray() method by extracting logic into dedicated methods: - getConfigPathForApi(): Returns empty string for non-generated certificates - removeCaIdFromOrganizationalUnit(): Filters CA IDs from OU arrays Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../CertificateEngine/AEngineHandler.php | 26 ++- .../CertificateEngine/AEngineHandlerTest.php | 158 ++++++++++++++++++ 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lib/Handler/CertificateEngine/AEngineHandler.php b/lib/Handler/CertificateEngine/AEngineHandler.php index b6d597636e..2990681f2c 100644 --- a/lib/Handler/CertificateEngine/AEngineHandler.php +++ b/lib/Handler/CertificateEngine/AEngineHandler.php @@ -709,9 +709,10 @@ protected function checkRootCertificateExpiry(): ?ConfigureCheckHelper { } public function toArray(): array { + $generated = $this->isSetupOk(); $return = [ - 'configPath' => $this->getCurrentConfigPath(), - 'generated' => $this->isSetupOk(), + 'configPath' => $this->getConfigPathForApi($generated), + 'generated' => $generated, 'rootCert' => [ 'commonName' => $this->getCommonName(), 'names' => [], @@ -725,12 +726,31 @@ public function toArray(): array { foreach ($names as $name => $value) { $return['rootCert']['names'][] = [ 'id' => $name, - 'value' => $value, + 'value' => $this->filterNameValue($name, $value), ]; } return $return; } + private function getConfigPathForApi(bool $generated): string { + return $generated ? $this->getCurrentConfigPath() : ''; + } + + private function filterNameValue(string $name, mixed $value): mixed { + if ($name === 'OU' && is_array($value)) { + return $this->removeCaIdFromOrganizationalUnit($value); + } + return $value; + } + + private function removeCaIdFromOrganizationalUnit(array $organizationalUnits): array { + $filtered = array_filter( + $organizationalUnits, + fn ($item) => !str_starts_with($item, 'libresign-ca-id:') + ); + return array_values($filtered); + } + protected function getCrlDistributionUrl(): string { $caIdParsed = $this->caIdentifierService->getCaIdParsed(); return $this->urlGenerator->linkToRouteAbsolute('libresign.crl.getRevocationList', [ diff --git a/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php b/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php index fa8cc013d7..51fb2a0759 100644 --- a/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php +++ b/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php @@ -232,4 +232,162 @@ public static function dataProviderIdentifyMethodsOtherEngines(): array { 'First time cfssl' => ['', 'cfssl', null, 'no previous config'], ]; } + + #[DataProvider('dataProviderToArray')] + public function testToArrayReturnsExpectedStructure( + bool $isSetupOk, + array $certificateData, + array $expectedKeys, + string $description, + ): void { + $instance = $this->getInstance(); + + foreach ($certificateData as $setter => $value) { + $method = 'set' . ucfirst($setter); + if (method_exists($instance, $method)) { + $instance->$method($value); + } + } + + if (!$isSetupOk) { + $this->appConfig->deleteKey(Application::APP_ID, 'config_path'); + } + + $result = $instance->toArray(); + + foreach ($expectedKeys as $key) { + $this->assertArrayHasKey($key, $result, "toArray() should contain '$key': $description"); + } + + $this->assertIsBool($result['generated'], "generated should be boolean: $description"); + } + + #[DataProvider('dataProviderToArrayConfigPath')] + public function testToArrayFiltersConfigPathWhenNotGenerated( + bool $certificateGenerated, + string $expectedConfigPath, + string $description, + ): void { + $instance = $this->getInstance(); + + $tempPath = $this->tempManager->getTemporaryFolder('test-config'); + $instance->setConfigPath($tempPath); + + if ($certificateGenerated) { + file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'ca.pem', 'fake-cert'); + file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'ca-key.pem', 'fake-key'); + } + + $result = $instance->toArray(); + + if ($expectedConfigPath === '') { + $this->assertEmpty($result['configPath'], "configPath should be empty: $description"); + } else { + $this->assertNotEmpty($result['configPath'], "configPath should not be empty: $description"); + } + + $this->assertEquals($certificateGenerated, $result['generated'], "generated flag: $description"); + } + + #[DataProvider('dataProviderToArrayCaIdFiltering')] + public function testToArrayFiltersCaIdFromOrganizationalUnit( + array $organizationalUnits, + array $expectedOuValues, + string $description, + ): void { + $instance = $this->getInstance(); + + $instance->setOrganizationalUnit($organizationalUnits); + $instance->setCountry('BR'); + + $result = $instance->toArray(); + + $ouFound = false; + foreach ($result['rootCert']['names'] as $name) { + if ($name['id'] === 'OU') { + $ouFound = true; + $this->assertEquals( + $expectedOuValues, + $name['value'], + "OrganizationalUnit should filter CA IDs: $description" + ); + break; + } + } + + if (!empty($expectedOuValues)) { + $this->assertTrue($ouFound, "OU should be present in names array: $description"); + } else { + $this->assertFalse($ouFound, "OU should not be present when filtered to empty: $description"); + } + } + + public static function dataProviderToArray(): array { + return [ + 'Basic structure with minimal data' => [ + false, + ['commonName' => 'Test CA'], + ['configPath', 'generated', 'rootCert', 'policySection'], + 'minimal certificate data', + ], + 'Complete certificate data' => [ + false, + [ + 'commonName' => 'LibreSign CA', + 'country' => 'BR', + 'state' => 'Santa Catarina', + 'locality' => 'Florianópolis', + 'organization' => 'LibreCode', + 'organizationalUnit' => ['Engineering', 'Security'], + ], + ['configPath', 'generated', 'rootCert', 'policySection'], + 'full certificate data', + ], + ]; + } + + public static function dataProviderToArrayConfigPath(): array { + return [ + 'Certificate not generated' => [ + false, + '', + 'configPath should be empty when certificate not generated', + ], + 'Certificate generated' => [ + true, + '/path/to/config', + 'configPath should be set when certificate is generated', + ], + ]; + } + + public static function dataProviderToArrayCaIdFiltering(): array { + return [ + 'OU without CA ID' => [ + ['Engineering', 'Security'], + ['Engineering', 'Security'], + 'normal OU values should pass through', + ], + 'OU with CA ID at start' => [ + ['libresign-ca-id:abc123_g:1_e:openssl', 'Engineering', 'Security'], + ['Engineering', 'Security'], + 'CA ID at start should be filtered out', + ], + 'OU with CA ID in middle' => [ + ['Engineering', 'libresign-ca-id:abc123_g:1_e:openssl', 'Security'], + ['Engineering', 'Security'], + 'CA ID in middle should be filtered out', + ], + 'OU with CA ID at end' => [ + ['Engineering', 'Security', 'libresign-ca-id:abc123_g:1_e:openssl'], + ['Engineering', 'Security'], + 'CA ID at end should be filtered out', + ], + 'OU with multiple CA IDs' => [ + ['libresign-ca-id:abc123_g:1_e:openssl', 'Engineering', 'libresign-ca-id:xyz789_g:2_e:cfssl', 'Security'], + ['Engineering', 'Security'], + 'multiple CA IDs should be filtered out', + ], + ]; + } } From 03170238d300ceb2002fc73548320f143b310448 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Mon, 15 Dec 2025 17:20:15 -0300 Subject: [PATCH 2/4] test: clean up config_path in AEngineHandlerTest setUp Prevent test state pollution by ensuring config_path is deleted in setUp(). This fixes failures in OpenSslHandlerTest where the temporary config path from AEngineHandlerTest was persisting through the shared appConfig mock, causing tests that expect properly formatted PKI directory names to fail. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php b/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php index 51fb2a0759..9380f4de7a 100644 --- a/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php +++ b/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php @@ -43,6 +43,7 @@ public function setUp(): void { $this->appConfig->deleteKey(Application::APP_ID, 'certificate_engine'); $this->appConfig->deleteKey(Application::APP_ID, 'identify_methods'); + $this->appConfig->deleteKey(Application::APP_ID, 'config_path'); } private function getInstance(): OpenSslHandler { From b37b998b6a50498f0f98cfa3d35753939859400f Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Mon, 15 Dec 2025 17:39:24 -0300 Subject: [PATCH 3/4] fix: filter CA ID from OU only when certificate not generated The CA ID (libresign-ca-id:...) in OrganizationalUnit should only be filtered out when the certificate is not generated (isSetupOk() returns false). When the certificate is successfully generated, the CA ID must be preserved in the API response. This ensures: - Generated certificates: CA ID is visible (expected behavior) - Failed/not generated: CA ID is filtered to prevent stale data in form Integration tests validated: - features/account/signature.feature:2 (OpenSSL) - features/account/signature.feature:23 (CFSSL) - features/admin/certificate_openssl.feature:2 - features/admin/certificate_openssl.feature:35 Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../CertificateEngine/AEngineHandler.php | 9 +-- .../CertificateEngine/AEngineHandlerTest.php | 71 ++++++++++++------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/lib/Handler/CertificateEngine/AEngineHandler.php b/lib/Handler/CertificateEngine/AEngineHandler.php index 2990681f2c..6e9fe58b86 100644 --- a/lib/Handler/CertificateEngine/AEngineHandler.php +++ b/lib/Handler/CertificateEngine/AEngineHandler.php @@ -726,7 +726,7 @@ public function toArray(): array { foreach ($names as $name => $value) { $return['rootCert']['names'][] = [ 'id' => $name, - 'value' => $this->filterNameValue($name, $value), + 'value' => $this->filterNameValue($name, $value, $generated), ]; } return $return; @@ -736,9 +736,10 @@ private function getConfigPathForApi(bool $generated): string { return $generated ? $this->getCurrentConfigPath() : ''; } - private function filterNameValue(string $name, mixed $value): mixed { - if ($name === 'OU' && is_array($value)) { - return $this->removeCaIdFromOrganizationalUnit($value); + private function filterNameValue(string $name, mixed $value, bool $generated): mixed { + if ($name === 'OU' && is_array($value) && !$generated) { + $filtered = $this->removeCaIdFromOrganizationalUnit($value); + return empty($filtered) ? null : $filtered; } return $value; } diff --git a/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php b/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php index 9380f4de7a..29f1b835fe 100644 --- a/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php +++ b/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php @@ -291,35 +291,43 @@ public function testToArrayFiltersConfigPathWhenNotGenerated( } #[DataProvider('dataProviderToArrayCaIdFiltering')] - public function testToArrayFiltersCaIdFromOrganizationalUnit( + public function testToArrayFiltersCaIdFromOrganizationalUnitWhenNotGenerated( + bool $certificateGenerated, array $organizationalUnits, array $expectedOuValues, string $description, ): void { $instance = $this->getInstance(); + $tempPath = $this->tempManager->getTemporaryFolder('test-config'); + $instance->setConfigPath($tempPath); $instance->setOrganizationalUnit($organizationalUnits); $instance->setCountry('BR'); + if ($certificateGenerated) { + file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'ca.pem', 'fake-cert'); + file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'ca-key.pem', 'fake-key'); + } + $result = $instance->toArray(); - $ouFound = false; + $ouFound = null; foreach ($result['rootCert']['names'] as $name) { if ($name['id'] === 'OU') { - $ouFound = true; - $this->assertEquals( - $expectedOuValues, - $name['value'], - "OrganizationalUnit should filter CA IDs: $description" - ); + $ouFound = $name['value']; break; } } if (!empty($expectedOuValues)) { - $this->assertTrue($ouFound, "OU should be present in names array: $description"); + $this->assertNotNull($ouFound, "OU should be present in names array: $description"); + $this->assertEquals( + $expectedOuValues, + $ouFound, + "OrganizationalUnit filtering: $description" + ); } else { - $this->assertFalse($ouFound, "OU should not be present when filtered to empty: $description"); + $this->assertNull($ouFound, "OU should not be present when filtered to empty: $description"); } } @@ -364,30 +372,41 @@ public static function dataProviderToArrayConfigPath(): array { public static function dataProviderToArrayCaIdFiltering(): array { return [ - 'OU without CA ID' => [ + 'OU without CA ID - not generated' => [ + false, ['Engineering', 'Security'], ['Engineering', 'Security'], - 'normal OU values should pass through', + 'normal OU values should pass through when not generated', ], - 'OU with CA ID at start' => [ - ['libresign-ca-id:abc123_g:1_e:openssl', 'Engineering', 'Security'], + 'OU without CA ID - generated' => [ + true, ['Engineering', 'Security'], - 'CA ID at start should be filtered out', - ], - 'OU with CA ID in middle' => [ - ['Engineering', 'libresign-ca-id:abc123_g:1_e:openssl', 'Security'], ['Engineering', 'Security'], - 'CA ID in middle should be filtered out', + 'normal OU values should pass through when generated', ], - 'OU with CA ID at end' => [ - ['Engineering', 'Security', 'libresign-ca-id:abc123_g:1_e:openssl'], + 'OU with CA ID - not generated (filtered)' => [ + false, + ['libresign-ca-id:abc123_g:1_e:openssl', 'Engineering', 'Security'], ['Engineering', 'Security'], - 'CA ID at end should be filtered out', + 'CA ID should be filtered when certificate not generated', ], - 'OU with multiple CA IDs' => [ - ['libresign-ca-id:abc123_g:1_e:openssl', 'Engineering', 'libresign-ca-id:xyz789_g:2_e:cfssl', 'Security'], - ['Engineering', 'Security'], - 'multiple CA IDs should be filtered out', + 'OU with CA ID - generated (kept)' => [ + true, + ['libresign-ca-id:abc123_g:1_e:openssl', 'Engineering', 'Security'], + ['libresign-ca-id:abc123_g:1_e:openssl', 'Engineering', 'Security'], + 'CA ID should be kept when certificate is generated', + ], + 'OU with only CA ID - not generated' => [ + false, + ['libresign-ca-id:abc123_g:1_e:openssl'], + [], + 'OU should be empty when only CA ID and not generated', + ], + 'OU with only CA ID - generated' => [ + true, + ['libresign-ca-id:abc123_g:1_e:openssl'], + ['libresign-ca-id:abc123_g:1_e:openssl'], + 'OU with only CA ID should be kept when generated', ], ]; } From c81867b997a38f6daf93498cafb564ff1c72c349 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Mon, 15 Dec 2025 18:41:19 -0300 Subject: [PATCH 4/4] refactor: add centralized reset in getMockAppConfig for test isolation - Add reset() method to AppConfigOverwrite that clears overWrite and deleted arrays and returns self - Integrate reset() directly into getMockAppConfig() to ensure clean state on every call - All tests now automatically get clean AppConfig state without explicit reset calls - Prevents state pollution across test suites by resetting at the source - Simplifies test code by removing need for separate reset wrapper method Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../Unit/Handler/CertificateEngine/AEngineHandlerTest.php | 6 +----- .../CertificateEngine/CertificateEngineFactoryTest.php | 2 +- .../Unit/Handler/CertificateEngine/OpenSslHandlerTest.php | 2 +- tests/php/Unit/Handler/FooterHandlerTest.php | 2 +- tests/php/Unit/Handler/PdfTest.php | 2 +- tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php | 2 +- tests/php/Unit/Handler/SignEngine/Pkcs12HandlerTest.php | 2 +- tests/php/Unit/Helper/JavaHelperTest.php | 2 +- tests/php/Unit/Service/CertificatePolicyServiceTest.php | 2 +- tests/php/Unit/Service/FileServiceTest.php | 2 +- tests/php/Unit/Service/FooterServiceTest.php | 2 +- tests/php/Unit/Service/IdentifyMethod/PasswordTest.php | 2 +- .../Unit/Service/Install/ConfigureCheckServiceTest.php | 2 +- tests/php/Unit/Service/Install/SignSetupServiceTest.php | 2 +- tests/php/Unit/Service/ReminderServiceTest.php | 2 +- tests/php/Unit/Service/SignFileServiceTest.php | 2 +- tests/php/Unit/Service/SignatureBackgroundServiceTest.php | 2 +- tests/php/Unit/Service/SignatureTextServiceTest.php | 2 +- tests/php/Unit/TestCase.php | 8 ++++++++ tests/php/lib/AppConfigOverwrite.php | 6 ++++++ 20 files changed, 32 insertions(+), 22 deletions(-) diff --git a/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php b/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php index 29f1b835fe..d44484aee8 100644 --- a/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php +++ b/tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php @@ -32,7 +32,7 @@ final class AEngineHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { public function setUp(): void { $this->config = \OCP\Server::get(IConfig::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->appDataFactory = \OCP\Server::get(IAppDataFactory::class); $this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class); $this->tempManager = \OCP\Server::get(ITempManager::class); @@ -40,10 +40,6 @@ public function setUp(): void { $this->urlGenerator = \OCP\Server::get(IURLGenerator::class); $this->caIdentifierService = \OCP\Server::get(CaIdentifierService::class); $this->logger = \OCP\Server::get(LoggerInterface::class); - - $this->appConfig->deleteKey(Application::APP_ID, 'certificate_engine'); - $this->appConfig->deleteKey(Application::APP_ID, 'identify_methods'); - $this->appConfig->deleteKey(Application::APP_ID, 'config_path'); } private function getInstance(): OpenSslHandler { diff --git a/tests/php/Unit/Handler/CertificateEngine/CertificateEngineFactoryTest.php b/tests/php/Unit/Handler/CertificateEngine/CertificateEngineFactoryTest.php index abf843d0df..56a4c12354 100644 --- a/tests/php/Unit/Handler/CertificateEngine/CertificateEngineFactoryTest.php +++ b/tests/php/Unit/Handler/CertificateEngine/CertificateEngineFactoryTest.php @@ -28,7 +28,7 @@ public function tearDown(): void { } public function setUp(): void { - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->openSslHandler = $this->createMock(OpenSslHandler::class); $this->cfsslHandler = $this->createMock(CfsslHandler::class); $this->noneHandler = $this->createMock(NoneHandler::class); diff --git a/tests/php/Unit/Handler/CertificateEngine/OpenSslHandlerTest.php b/tests/php/Unit/Handler/CertificateEngine/OpenSslHandlerTest.php index 1bfcf1f70c..332a0cfa77 100644 --- a/tests/php/Unit/Handler/CertificateEngine/OpenSslHandlerTest.php +++ b/tests/php/Unit/Handler/CertificateEngine/OpenSslHandlerTest.php @@ -39,7 +39,7 @@ final class OpenSslHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { private string $tempDir; public function setUp(): void { $this->config = \OCP\Server::get(IConfig::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->appDataFactory = \OCP\Server::get(IAppDataFactory::class); $this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class); $this->tempManager = \OCP\Server::get(ITempManager::class); diff --git a/tests/php/Unit/Handler/FooterHandlerTest.php b/tests/php/Unit/Handler/FooterHandlerTest.php index cdc099041f..bc83f924c7 100644 --- a/tests/php/Unit/Handler/FooterHandlerTest.php +++ b/tests/php/Unit/Handler/FooterHandlerTest.php @@ -27,7 +27,7 @@ final class FooterHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { private ITempManager $tempManager; private FooterHandler $footerHandler; public function setUp(): void { - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->pdfParserService = $this->createMock(PdfParserService::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->tempManager = \OCP\Server::get(ITempManager::class); diff --git a/tests/php/Unit/Handler/PdfTest.php b/tests/php/Unit/Handler/PdfTest.php index 03d60a7d49..3973ea51ca 100644 --- a/tests/php/Unit/Handler/PdfTest.php +++ b/tests/php/Unit/Handler/PdfTest.php @@ -24,7 +24,7 @@ final class PdfTest extends \OCA\Libresign\Tests\Unit\TestCase { public function setUp(): void { parent::setUp(); $this->javaHelper = $this->createMock(JavaHelper::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID); } diff --git a/tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php b/tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php index 8483a95541..c955db57b5 100644 --- a/tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php +++ b/tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php @@ -63,7 +63,7 @@ public static function setUpBeforeClass(): void { } } public function setUp(): void { - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->loggerInterface = $this->createMock(LoggerInterface::class); $this->tempManager = \OCP\Server::get(ITempManager::class); $this->signatureBackgroundService = $this->createMock(SignatureBackgroundService::class); diff --git a/tests/php/Unit/Handler/SignEngine/Pkcs12HandlerTest.php b/tests/php/Unit/Handler/SignEngine/Pkcs12HandlerTest.php index 3fd013e10a..419120c9c9 100644 --- a/tests/php/Unit/Handler/SignEngine/Pkcs12HandlerTest.php +++ b/tests/php/Unit/Handler/SignEngine/Pkcs12HandlerTest.php @@ -37,7 +37,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { public function setUp(): void { $this->folderService = $this->createMock(FolderService::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->certificateEngineFactory = $this->createMock(CertificateEngineFactory::class); $this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID); $this->footerHandler = $this->createMock(FooterHandler::class); diff --git a/tests/php/Unit/Helper/JavaHelperTest.php b/tests/php/Unit/Helper/JavaHelperTest.php index 8688ddf816..ae67e609d4 100644 --- a/tests/php/Unit/Helper/JavaHelperTest.php +++ b/tests/php/Unit/Helper/JavaHelperTest.php @@ -23,7 +23,7 @@ class JavaHelperTest extends \OCA\Libresign\Tests\Unit\TestCase { public function setUp(): void { parent::setUp(); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->l10n = $this->createMock(IL10N::class); $this->logger = $this->createMock(LoggerInterface::class); } diff --git a/tests/php/Unit/Service/CertificatePolicyServiceTest.php b/tests/php/Unit/Service/CertificatePolicyServiceTest.php index 9ce7120ebf..20b8f15175 100644 --- a/tests/php/Unit/Service/CertificatePolicyServiceTest.php +++ b/tests/php/Unit/Service/CertificatePolicyServiceTest.php @@ -33,7 +33,7 @@ final class CertificatePolicyServiceTest extends \OCA\Libresign\Tests\Unit\TestC public function setUp(): void { $this->appData = $this->createMock(IAppData::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID); } diff --git a/tests/php/Unit/Service/FileServiceTest.php b/tests/php/Unit/Service/FileServiceTest.php index 48e0a9cd4b..d47ac2f403 100644 --- a/tests/php/Unit/Service/FileServiceTest.php +++ b/tests/php/Unit/Service/FileServiceTest.php @@ -103,7 +103,7 @@ private function getService(): FileService { $this->accountManager = $this->createMock(IAccountManager::class); $this->client = \OCP\Server::get(IClientService::class); $this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->urlGenerator = \OCP\Server::get(IURLGenerator::class); $this->mimeTypeDetector = \OCP\Server::get(IMimeTypeDetector::class); $this->pkcs12Handler = \OCP\Server::get(Pkcs12Handler::class); diff --git a/tests/php/Unit/Service/FooterServiceTest.php b/tests/php/Unit/Service/FooterServiceTest.php index 372f9b652d..3d8b2a2b18 100644 --- a/tests/php/Unit/Service/FooterServiceTest.php +++ b/tests/php/Unit/Service/FooterServiceTest.php @@ -23,7 +23,7 @@ class FooterServiceTest extends TestCase { public function setUp(): void { parent::setUp(); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->footerHandler = $this->createMock(FooterHandler::class); $this->service = new FooterService($this->appConfig, $this->footerHandler); } diff --git a/tests/php/Unit/Service/IdentifyMethod/PasswordTest.php b/tests/php/Unit/Service/IdentifyMethod/PasswordTest.php index edd6cd2b67..0a1ec6fe31 100644 --- a/tests/php/Unit/Service/IdentifyMethod/PasswordTest.php +++ b/tests/php/Unit/Service/IdentifyMethod/PasswordTest.php @@ -43,7 +43,7 @@ final class PasswordTest extends \OCA\Libresign\Tests\Unit\TestCase { public function setUp(): void { $this->identifyService = $this->createMock(IdentifyService::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->folderService = $this->createMock(FolderService::class); $this->certificateEngineFactory = $this->createMock(CertificateEngineFactory::class); $this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID); diff --git a/tests/php/Unit/Service/Install/ConfigureCheckServiceTest.php b/tests/php/Unit/Service/Install/ConfigureCheckServiceTest.php index 11024ba59f..6c38f56f57 100644 --- a/tests/php/Unit/Service/Install/ConfigureCheckServiceTest.php +++ b/tests/php/Unit/Service/Install/ConfigureCheckServiceTest.php @@ -48,7 +48,7 @@ final class ConfigureCheckServiceTest extends \OCA\Libresign\Tests\Unit\TestCase public function setUp(): void { self::$mockExtensionLoaded = []; - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->systemConfig = $this->createMock(SystemConfig::class); $this->ocAppConfig = $this->createMock(AppConfig::class); $this->appManager = $this->createMock(IAppManager::class); diff --git a/tests/php/Unit/Service/Install/SignSetupServiceTest.php b/tests/php/Unit/Service/Install/SignSetupServiceTest.php index 0d6613a267..bdb5e8a04f 100644 --- a/tests/php/Unit/Service/Install/SignSetupServiceTest.php +++ b/tests/php/Unit/Service/Install/SignSetupServiceTest.php @@ -35,7 +35,7 @@ public function setUp(): void { $this->fileAccessHelper = new FileAccessHelper(); $this->appManager = $this->createMock(IAppManager::class); $this->config = $this->createMock(IConfig::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->appDataFactory = \OCP\Server::get(IAppDataFactory::class); $this->tempManager = \OCP\Server::get(ITempManager::class); } diff --git a/tests/php/Unit/Service/ReminderServiceTest.php b/tests/php/Unit/Service/ReminderServiceTest.php index 4fb9e03dbb..f696f11162 100644 --- a/tests/php/Unit/Service/ReminderServiceTest.php +++ b/tests/php/Unit/Service/ReminderServiceTest.php @@ -31,7 +31,7 @@ final class ReminderServiceTest extends \OCA\Libresign\Tests\Unit\TestCase { public function setUp(): void { $this->jobList = $this->createMock(IJobList::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->dateTimeZone = Server::get(IDateTimeZone::class); $this->time = $this->createMock(ITimeFactory::class); $this->signRequestMapper = $this->createMock(SignRequestMapper::class); diff --git a/tests/php/Unit/Service/SignFileServiceTest.php b/tests/php/Unit/Service/SignFileServiceTest.php index ef6a4b0801..0aa0657747 100644 --- a/tests/php/Unit/Service/SignFileServiceTest.php +++ b/tests/php/Unit/Service/SignFileServiceTest.php @@ -105,7 +105,7 @@ public function setUp(): void { $this->userManager = $this->createMock(IUserManager::class); $this->folderService = $this->createMock(FolderService::class); $this->logger = $this->createMock(LoggerInterface::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->validateHelper = $this->createMock(\OCA\Libresign\Helper\ValidateHelper::class); $this->signerElementsService = $this->createMock(SignerElementsService::class); $this->root = $this->createMock(\OCP\Files\IRootFolder::class); diff --git a/tests/php/Unit/Service/SignatureBackgroundServiceTest.php b/tests/php/Unit/Service/SignatureBackgroundServiceTest.php index a30af60e6e..7046dde0f7 100644 --- a/tests/php/Unit/Service/SignatureBackgroundServiceTest.php +++ b/tests/php/Unit/Service/SignatureBackgroundServiceTest.php @@ -23,7 +23,7 @@ final class SignatureBackgroundServiceTest extends \OCA\Libresign\Tests\Unit\Tes public function setUp(): void { $this->appData = $this->createMock(IAppData::class); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->config = $this->createMock(IConfig::class); $this->tempManager = $this->createMock(ITempManager::class); } diff --git a/tests/php/Unit/Service/SignatureTextServiceTest.php b/tests/php/Unit/Service/SignatureTextServiceTest.php index 9cc80b076a..2518e0db17 100644 --- a/tests/php/Unit/Service/SignatureTextServiceTest.php +++ b/tests/php/Unit/Service/SignatureTextServiceTest.php @@ -30,7 +30,7 @@ final class SignatureTextServiceTest extends \OCA\Libresign\Tests\Unit\TestCase public function setUp(): void { $this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID); - $this->appConfig = $this->getMockAppConfig(); + $this->appConfig = $this->getMockAppConfigWithReset(); $this->dateTimeZone = \OCP\Server::get(IDateTimeZone::class); $this->request = $this->createMock(IRequest::class); $this->userSession = $this->createMock(IUserSession::class); diff --git a/tests/php/Unit/TestCase.php b/tests/php/Unit/TestCase.php index 1d4bf6c77c..f9aec1c274 100644 --- a/tests/php/Unit/TestCase.php +++ b/tests/php/Unit/TestCase.php @@ -77,6 +77,14 @@ public static function getMockAppConfig(): IAppConfig { return $service; } + public static function getMockAppConfigWithReset(): IAppConfig { + $appConfig = self::getMockAppConfig(); + if ($appConfig instanceof AppConfigOverwrite) { + $appConfig->reset(); + } + return $appConfig; + } + public function mockConfig($config):void { $service = \OCP\Server::get(\OCP\IConfig::class); if (!$service instanceof AllConfigOverwrite) { diff --git a/tests/php/lib/AppConfigOverwrite.php b/tests/php/lib/AppConfigOverwrite.php index ccbf98c0a5..cec9323c0a 100644 --- a/tests/php/lib/AppConfigOverwrite.php +++ b/tests/php/lib/AppConfigOverwrite.php @@ -122,6 +122,12 @@ public function deleteKey(string $app, string $key): void { $this->markDeleted($app, $key); } + public function reset(): self { + $this->overWrite = []; + $this->deleted = []; + return $this; + } + private function isDeleted(string $app, string $key): bool { return isset($this->deleted[$app][$key]); }