|
13 | 13 | use OCA\Libresign\Service\Policy\Provider\ExpirationRules\ExpirationRulesPolicy; |
14 | 14 | use OCA\Libresign\Service\Policy\Provider\Footer\FooterPolicyValue; |
15 | 15 | 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; |
16 | 18 | use OCP\Exceptions\AppConfigTypeConflictException; |
17 | 19 | use OCP\IAppConfig; |
18 | 20 | use OCP\Migration\IOutput; |
@@ -91,6 +93,74 @@ public function testMigratesLegacyFooterSettingsIntoStructuredPayload(): void { |
91 | 93 | self::assertContains([Application::APP_ID, 'add_footer'], $deletedKeys); |
92 | 94 | } |
93 | 95 |
|
| 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 | + |
94 | 164 | public function testReadsLegacyBooleanWhenAddFooterHasTypedBoolValue(): void { |
95 | 165 | $this->appConfig |
96 | 166 | ->method('getValueString') |
|
0 commit comments