Skip to content

Commit ca57a72

Browse files
committed
chore: add migration to remove legacy appConfig keys
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 8073953 commit ca57a72

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

lib/Migration/Version18001Date20260320000000.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use OCA\Libresign\Service\Policy\Provider\RequestSignGroups\RequestSignGroupsPolicyValue;
2727
use OCA\Libresign\Service\Policy\Provider\Signature\SignatureFlowPolicy;
2828
use OCA\Libresign\Service\Policy\Provider\SignatureText\SignatureTextPolicy;
29+
use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicy;
30+
use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicyValue;
2931
use OCP\DB\ISchemaWrapper;
3032
use OCP\Exceptions\AppConfigTypeConflictException;
3133
use OCP\IAppConfig;
@@ -53,6 +55,41 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $
5355
$this->migrateReminderSettings();
5456
$this->migrateExpirationRulesType();
5557
$this->migrateIdentifyMethodsType();
58+
$this->migrateTsaSettings();
59+
}
60+
61+
private function migrateTsaSettings(): void {
62+
$existingConsolidated = $this->readLegacyString(TsaPolicy::SYSTEM_APP_CONFIG_KEY);
63+
if ($existingConsolidated !== null && trim($existingConsolidated) !== '') {
64+
$this->deleteLegacyTsaNonSensitiveKeys();
65+
return;
66+
}
67+
68+
$tsaUrl = $this->readLegacyString('tsa_url');
69+
$tsaPolicyOid = $this->readLegacyString('tsa_policy_oid');
70+
$tsaAuthType = $this->readLegacyString('tsa_auth_type');
71+
$tsaUsername = $this->readLegacyString('tsa_username');
72+
73+
if ($tsaUrl === null && $tsaPolicyOid === null && $tsaAuthType === null && $tsaUsername === null) {
74+
return;
75+
}
76+
77+
$encoded = TsaPolicyValue::encode([
78+
'url' => $tsaUrl ?? '',
79+
'policy_oid' => $tsaPolicyOid ?? '',
80+
'auth_type' => $tsaAuthType ?? 'none',
81+
'username' => $tsaUsername ?? '',
82+
]);
83+
84+
$this->deleteLegacyTsaNonSensitiveKeys();
85+
$this->appConfig->setValueString(Application::APP_ID, TsaPolicy::SYSTEM_APP_CONFIG_KEY, $encoded);
86+
}
87+
88+
private function deleteLegacyTsaNonSensitiveKeys(): void {
89+
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_url');
90+
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_policy_oid');
91+
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_auth_type');
92+
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_username');
5693
}
5794

5895
private function migrateExpirationRulesType(): void {

tests/php/Unit/Migration/Version18001Date20260320000000Test.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use OCA\Libresign\Service\Policy\Provider\ExpirationRules\ExpirationRulesPolicy;
1414
use OCA\Libresign\Service\Policy\Provider\Footer\FooterPolicyValue;
1515
use OCA\Libresign\Service\Policy\Provider\SignatureText\SignatureTextPolicy;
16+
use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicy;
17+
use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicyValue;
1618
use OCP\Exceptions\AppConfigTypeConflictException;
1719
use OCP\IAppConfig;
1820
use OCP\Migration\IOutput;
@@ -91,6 +93,74 @@ public function testMigratesLegacyFooterSettingsIntoStructuredPayload(): void {
9193
self::assertContains([Application::APP_ID, 'add_footer'], $deletedKeys);
9294
}
9395

96+
public function testMigratesLegacyTsaSettingsIntoCanonicalPolicyAndDeletesLegacyKeys(): void {
97+
$this->appConfig
98+
->method('getValueString')
99+
->willReturnCallback(static function (string $app, string $key, string $default): string {
100+
if ($app !== Application::APP_ID) {
101+
return $default;
102+
}
103+
104+
$map = [
105+
'add_footer' => '',
106+
'write_qrcode_on_footer' => '',
107+
'validation_site' => '',
108+
'footer_template_is_default' => '',
109+
'collect_metadata' => '',
110+
'identification_documents' => '',
111+
'docmdp_level' => '',
112+
'groups_request_sign' => '',
113+
'policy.signature_flow.system' => '',
114+
'signature_flow' => '',
115+
'template_font_size' => '',
116+
'signature_width' => '',
117+
'signature_height' => '',
118+
'signature_font_size' => '',
119+
'signature_render_mode' => '',
120+
'identify_methods' => '',
121+
TsaPolicy::SYSTEM_APP_CONFIG_KEY => '',
122+
'tsa_url' => 'https://freetsa.org/tsr',
123+
'tsa_policy_oid' => '1.2.840.113549.1.9.16.1.4',
124+
'tsa_auth_type' => 'basic',
125+
'tsa_username' => 'tsa-user',
126+
];
127+
128+
return $map[$key] ?? $default;
129+
});
130+
131+
$deletedKeys = [];
132+
$savedStrings = [];
133+
134+
$this->appConfig
135+
->method('deleteKey')
136+
->willReturnCallback(static function (string $app, string $key) use (&$deletedKeys): void {
137+
$deletedKeys[] = [$app, $key];
138+
});
139+
140+
$this->appConfig
141+
->method('setValueString')
142+
->willReturnCallback(static function (string $app, string $key, string $value) use (&$savedStrings): bool {
143+
$savedStrings[] = [$app, $key, $value];
144+
return true;
145+
});
146+
147+
$migration = new Version18001Date20260320000000($this->appConfig);
148+
$migration->preSchemaChange($this->createMock(IOutput::class), static fn () => null, []);
149+
150+
$expectedTsaPayload = TsaPolicyValue::encode([
151+
'url' => 'https://freetsa.org/tsr',
152+
'policy_oid' => '1.2.840.113549.1.9.16.1.4',
153+
'auth_type' => 'basic',
154+
'username' => 'tsa-user',
155+
]);
156+
157+
self::assertContains([Application::APP_ID, TsaPolicy::SYSTEM_APP_CONFIG_KEY, $expectedTsaPayload], $savedStrings);
158+
self::assertContains([Application::APP_ID, 'tsa_url'], $deletedKeys);
159+
self::assertContains([Application::APP_ID, 'tsa_policy_oid'], $deletedKeys);
160+
self::assertContains([Application::APP_ID, 'tsa_auth_type'], $deletedKeys);
161+
self::assertContains([Application::APP_ID, 'tsa_username'], $deletedKeys);
162+
}
163+
94164
public function testReadsLegacyBooleanWhenAddFooterHasTypedBoolValue(): void {
95165
$this->appConfig
96166
->method('getValueString')

0 commit comments

Comments
 (0)