Skip to content

Commit e8b18c7

Browse files
committed
fix: remove duplicated admin initial states and align TSA integration tests
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 897eec0 commit e8b18c7

4 files changed

Lines changed: 60 additions & 147 deletions

File tree

lib/Settings/Admin.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
use OCA\Libresign\Service\FooterService;
1717
use OCA\Libresign\Service\IdentifyMethodService;
1818
use OCA\Libresign\Service\Policy\PolicyService;
19-
use OCA\Libresign\Service\Policy\Provider\LegalInformation\LegalInformationPolicy;
20-
use OCA\Libresign\Service\Policy\Provider\SignatureBackground\SignatureBackgroundPolicy;
21-
use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicy;
22-
use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicyValue;
2319
use OCA\Libresign\Service\SignatureTextService;
2420
use OCP\AppFramework\Http\ContentSecurityPolicy;
2521
use OCP\AppFramework\Http\TemplateResponse;
@@ -66,9 +62,7 @@ public function getForm(): TemplateResponse {
6662
$this->initialState->provideInitialState('certificate_policies_oid', $this->certificatePolicyService->getOid());
6763
$this->initialState->provideInitialState('certificate_policies_cps', $this->certificatePolicyService->getCps());
6864
$this->initialState->provideInitialState('config_path', $this->appConfig->getValueString(Application::APP_ID, 'config_path'));
69-
$this->initialState->provideInitialState('legal_information', (string)$this->policyService->resolve(LegalInformationPolicy::KEY)->getEffectiveValue());
7065
$this->initialState->provideInitialState('signature_available_variables', $this->signatureTextService->getAvailableVariables());
71-
$this->initialState->provideInitialState('signature_background_type', (string)$this->policyService->resolve(SignatureBackgroundPolicy::KEY)->getEffectiveValue());
7266
$this->initialState->provideInitialState('signature_preview_zoom_level', $this->appConfig->getValueFloat(Application::APP_ID, 'signature_preview_zoom_level', 100));
7367
$this->initialState->provideInitialState('footer_preview_zoom_level', $this->appConfig->getValueFloat(Application::APP_ID, 'footer_preview_zoom_level', 100));
7468
$this->initialState->provideInitialState('footer_preview_width', $this->appConfig->getValueInt(Application::APP_ID, 'footer_preview_width', 595));
@@ -78,12 +72,6 @@ public function getForm(): TemplateResponse {
7872
$this->initialState->provideInitialState('footer_template', $this->footerService->getTemplate());
7973
$this->initialState->provideInitialState('footer_template_is_default', $this->footerService->isDefaultTemplate());
8074
$this->initialState->provideInitialState('signature_engine', $this->getSignatureEngineInitialState());
81-
$tsaSettings = $this->getTsaInitialState();
82-
$this->initialState->provideInitialState('tsa_url', $tsaSettings['url']);
83-
$this->initialState->provideInitialState('tsa_policy_oid', $tsaSettings['policy_oid']);
84-
$this->initialState->provideInitialState('tsa_auth_type', $tsaSettings['auth_type']);
85-
$this->initialState->provideInitialState('tsa_username', $tsaSettings['username']);
86-
$this->initialState->provideInitialState('tsa_password', $this->appConfig->getValueString(Application::APP_ID, 'tsa_password', self::PASSWORD_PLACEHOLDER));
8775
$this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings());
8876
$resolvedPolicies = [];
8977
foreach ($this->policyService->resolveKnownPolicies() as $policyKey => $resolvedPolicy) {
@@ -94,11 +82,7 @@ public function getForm(): TemplateResponse {
9482
]);
9583
$this->initialState->provideInitialState('signing_mode', $this->getSigningModeInitialState());
9684
$this->initialState->provideInitialState('worker_type', $this->getWorkerTypeInitialState());
97-
$this->initialState->provideInitialState('identification_documents', $this->appConfig->getValueBool(Application::APP_ID, 'identification_documents', false));
98-
$this->initialState->provideInitialState('approval_group', $this->appConfig->getValueString(Application::APP_ID, 'approval_group', '["admin"]'));
99-
$this->initialState->provideInitialState('envelope_enabled', $this->appConfig->getValueBool(Application::APP_ID, 'envelope_enabled', true));
10085
$this->initialState->provideInitialState('parallel_workers', $this->appConfig->getValueString(Application::APP_ID, 'parallel_workers', '4'));
101-
$this->initialState->provideInitialState('show_confetti_after_signing', $this->appConfig->getValueBool(Application::APP_ID, 'show_confetti_after_signing', true));
10286
$this->initialState->provideInitialState('crl_external_validation_enabled', $this->appConfig->getValueBool(Application::APP_ID, 'crl_external_validation_enabled', true));
10387
$this->initialState->provideInitialState('ldap_extension_available', function_exists('ldap_connect'));
10488

@@ -154,12 +138,4 @@ private function getWorkerTypeInitialState(): string {
154138
return 'local';
155139
}
156140

157-
/**
158-
* @return array{url: string, policy_oid: string, auth_type: string, username: string}
159-
*/
160-
private function getTsaInitialState(): array {
161-
$resolved = $this->policyService->resolve(TsaPolicy::KEY)->getEffectiveValue();
162-
$settings = TsaPolicyValue::decode($resolved);
163-
return $settings;
164-
}
165141
}

tests/integration/features/admin/initial_state.feature

Lines changed: 43 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Feature: admin/initial_state
6060
And run the command "config:app:delete libresign footer_template" with result code 0
6161
And run the command "config:app:delete libresign config_path" with result code 0
6262
And run the command "config:app:delete libresign tsa_password" with result code 0
63+
And sending "delete" to ocs "/apps/libresign/api/v1/admin/tsa"
64+
And the response should have a status code 200
6365
And the following libresign app config is set
6466
| certificate_engine | openssl |
6567
| certificate_policies_oid | |
@@ -76,10 +78,6 @@ Feature: admin/initial_state
7678
| signature_render_mode | GRAPHIC_AND_DESCRIPTION |
7779
| signature_width | 350 |
7880
| template_font_size | 10 |
79-
| tsa_url | |
80-
| tsa_policy_oid | |
81-
| tsa_auth_type | none |
82-
| tsa_username | |
8381
| docmdp_level | 2 |
8482
| policy.signature_flow.system | none |
8583
| signing_mode | sync |
@@ -112,10 +110,6 @@ Feature: admin/initial_state
112110
And the response should contain the initial state "libresign-config_path" with the following values:
113111
"""
114112
115-
"""
116-
And the response should contain the initial state "libresign-legal_information" with the following values:
117-
"""
118-
119113
"""
120114
And the response should contain the initial state "libresign-signature_available_variables" json that match with:
121115
| key | value |
@@ -124,10 +118,6 @@ Feature: admin/initial_state
124118
| (jq)has("{{ServerSignatureDate}}") | true |
125119
| (jq)has("{{SignerCommonName}}") | true |
126120
| (jq)has("{{SignerIP}}") | false |
127-
And the response should contain the initial state "libresign-signature_background_type" with the following values:
128-
"""
129-
default
130-
"""
131121
And the response should contain the initial state "libresign-signature_preview_zoom_level" with the following values:
132122
"""
133123
100
@@ -160,32 +150,21 @@ Feature: admin/initial_state
160150
"""
161151
JSignPdf
162152
"""
163-
And the response should contain the initial state "libresign-tsa_url" with the following values:
164-
"""
165-
166-
"""
167-
And the response should contain the initial state "libresign-tsa_policy_oid" with the following values:
168-
"""
169-
170-
"""
171-
And the response should contain the initial state "libresign-tsa_auth_type" with the following values:
172-
"""
173-
none
174-
"""
175-
And the response should contain the initial state "libresign-tsa_username" with the following values:
176-
"""
177-
178-
"""
179-
And the response should contain the initial state "libresign-tsa_password" with the following values:
180-
"""
181-
"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"
182-
"""
183153
And the response should contain the initial state "libresign-effective_policies" json that match with:
184-
| key | value |
185-
| (jq).policies.docmdp.effectiveValue | 2 |
186-
| (jq).policies.signature_flow.policyKey | signature_flow |
187-
| (jq).policies.signature_flow.effectiveValue | none |
188-
| (jq).policies.signature_flow.allowedValues | ["none","parallel","ordered_numeric"] |
154+
| key | value |
155+
| (jq).policies.docmdp.effectiveValue | 2 |
156+
| (jq).policies.legal_information.effectiveValue | |
157+
| (jq).policies.signature_flow.policyKey | signature_flow |
158+
| (jq).policies.signature_flow.effectiveValue | none |
159+
| (jq).policies.signature_flow.allowedValues | ["none","parallel","ordered_numeric"] |
160+
| (jq).policies.signature_background_type.effectiveValue | default |
161+
| (jq).policies.identification_documents.effectiveValue | false |
162+
| (jq)(.policies.approval_group.effectiveValue \| fromjson \| .[0]) | admin |
163+
| (jq).policies.envelope_enabled.effectiveValue | true |
164+
| (jq).policies.show_confetti_after_signing.effectiveValue | true |
165+
| (jq).policies.tsa_settings.policyKey | tsa_settings |
166+
| (jq).policies.tsa_settings.sourceScope | system |
167+
| (jq)(.policies.tsa_settings.effectiveValue \| fromjson).auth_type | none |
189168
And the response should contain the initial state "libresign-signing_mode" with the following values:
190169
"""
191170
sync
@@ -194,26 +173,10 @@ Feature: admin/initial_state
194173
"""
195174
local
196175
"""
197-
And the response should contain the initial state "libresign-identification_documents" with the following values:
198-
"""
199-
false
200-
"""
201-
And the response should contain the initial state "libresign-approval_group" with the following values:
202-
"""
203-
["admin"]
204-
"""
205-
And the response should contain the initial state "libresign-envelope_enabled" with the following values:
206-
"""
207-
true
208-
"""
209176
And the response should contain the initial state "libresign-parallel_workers" with the following values:
210177
"""
211178
"4"
212179
"""
213-
And the response should contain the initial state "libresign-show_confetti_after_signing" with the following values:
214-
"""
215-
true
216-
"""
217180
And the response should contain the initial state "libresign-crl_external_validation_enabled" with the following values:
218181
"""
219182
true
@@ -240,10 +203,6 @@ Feature: admin/initial_state
240203
| signature_text_template | Issuer: {{IssuerCommonName}} |
241204
| signature_width | 420 |
242205
| template_font_size | 12.5 |
243-
| tsa_url | https://tsa.example.test/tsr |
244-
| tsa_policy_oid | 1.2.3 |
245-
| tsa_auth_type | basic |
246-
| tsa_username | signer |
247206
| tsa_password | topsecret |
248207
| docmdp_level | 0 |
249208
| policy.signature_flow.system | ordered_numeric |
@@ -255,6 +214,13 @@ Feature: admin/initial_state
255214
| parallel_workers | 9 |
256215
| show_confetti_after_signing | false |
257216
| crl_external_validation_enabled | false |
217+
And sending "post" to ocs "/apps/libresign/api/v1/admin/tsa"
218+
| tsa_url | https://tsa.example.test/tsr |
219+
| tsa_policy_oid | 1.2.3 |
220+
| tsa_auth_type | basic |
221+
| tsa_username | signer |
222+
| tsa_password | topsecret |
223+
And the response should have a status code 200
258224
And sending "post" to ocs "/apps/libresign/api/v1/admin/footer-template"
259225
| template | Custom footer for {{ uuid }} |
260226
| width | 610 |
@@ -281,18 +247,10 @@ Feature: admin/initial_state
281247
"""
282248
"/tmp"
283249
"""
284-
And the response should contain the initial state "libresign-legal_information" with the following values:
285-
"""
286-
Custom legal information
287-
"""
288250
And the response should contain the initial state "libresign-signature_text_parsed" with the following values:
289251
"""
290252
Issuer: Acme Cooperative
291253
"""
292-
And the response should contain the initial state "libresign-signature_background_type" with the following values:
293-
"""
294-
deleted
295-
"""
296254
And the response should contain the initial state "libresign-signature_preview_zoom_level" with the following values:
297255
"""
298256
125
@@ -321,32 +279,25 @@ Feature: admin/initial_state
321279
"""
322280
PhpNative
323281
"""
324-
And the response should contain the initial state "libresign-tsa_url" with the following values:
325-
"""
326-
"https:\/\/tsa.example.test\/tsr"
327-
"""
328-
And the response should contain the initial state "libresign-tsa_policy_oid" with the following values:
329-
"""
330-
1.2.3
331-
"""
332-
And the response should contain the initial state "libresign-tsa_auth_type" with the following values:
333-
"""
334-
basic
335-
"""
336-
And the response should contain the initial state "libresign-tsa_username" with the following values:
337-
"""
338-
signer
339-
"""
340-
And the response should contain the initial state "libresign-tsa_password" with the following values:
341-
"""
342-
topsecret
343-
"""
344282
And the response should contain the initial state "libresign-effective_policies" json that match with:
345-
| key | value |
346-
| (jq).policies.docmdp.effectiveValue | 0 |
347-
| (jq).policies.signature_flow.policyKey | signature_flow |
348-
| (jq).policies.signature_flow.effectiveValue | ordered_numeric |
349-
| (jq).policies.signature_flow.allowedValues | ["ordered_numeric"] |
283+
| key | value |
284+
| (jq).policies.docmdp.effectiveValue | 0 |
285+
| (jq).policies.legal_information.effectiveValue | Custom legal information |
286+
| (jq).policies.signature_flow.policyKey | signature_flow |
287+
| (jq).policies.signature_flow.effectiveValue | ordered_numeric |
288+
| (jq).policies.signature_flow.allowedValues | ["ordered_numeric"] |
289+
| (jq).policies.signature_background_type.effectiveValue | deleted |
290+
| (jq).policies.identification_documents.effectiveValue | true |
291+
| (jq)(.policies.approval_group.effectiveValue \| fromjson \| .[0]) | admin |
292+
| (jq)(.policies.approval_group.effectiveValue \| fromjson \| .[1]) | staff |
293+
| (jq).policies.envelope_enabled.effectiveValue | false |
294+
| (jq).policies.show_confetti_after_signing.effectiveValue | false |
295+
| (jq).policies.tsa_settings.policyKey | tsa_settings |
296+
| (jq).policies.tsa_settings.sourceScope | global |
297+
| (jq)(.policies.tsa_settings.effectiveValue \| fromjson).url | https://tsa.example.test/tsr |
298+
| (jq)(.policies.tsa_settings.effectiveValue \| fromjson).policy_oid | 1.2.3 |
299+
| (jq)(.policies.tsa_settings.effectiveValue \| fromjson).auth_type | basic |
300+
| (jq)(.policies.tsa_settings.effectiveValue \| fromjson).username | signer |
350301
And the response should contain the initial state "libresign-signing_mode" with the following values:
351302
"""
352303
async
@@ -355,26 +306,10 @@ Feature: admin/initial_state
355306
"""
356307
external
357308
"""
358-
And the response should contain the initial state "libresign-identification_documents" with the following values:
359-
"""
360-
true
361-
"""
362-
And the response should contain the initial state "libresign-approval_group" with the following values:
363-
"""
364-
["admin","staff"]
365-
"""
366-
And the response should contain the initial state "libresign-envelope_enabled" with the following values:
367-
"""
368-
false
369-
"""
370309
And the response should contain the initial state "libresign-parallel_workers" with the following values:
371310
"""
372311
"9"
373312
"""
374-
And the response should contain the initial state "libresign-show_confetti_after_signing" with the following values:
375-
"""
376-
false
377-
"""
378313
And the response should contain the initial state "libresign-crl_external_validation_enabled" with the following values:
379314
"""
380315
false
@@ -395,10 +330,6 @@ Feature: admin/initial_state
395330
| signature_render_mode | GRAPHIC_AND_DESCRIPTION |
396331
| signature_width | 350 |
397332
| template_font_size | 10 |
398-
| tsa_url | |
399-
| tsa_policy_oid | |
400-
| tsa_auth_type | none |
401-
| tsa_username | |
402333
| docmdp_level | 2 |
403334
| policy.signature_flow.system | none |
404335
| signing_mode | sync |
@@ -409,6 +340,8 @@ Feature: admin/initial_state
409340
| parallel_workers | 4 |
410341
| show_confetti_after_signing | true |
411342
| crl_external_validation_enabled | true |
343+
And sending "delete" to ocs "/apps/libresign/api/v1/admin/tsa"
344+
And the response should have a status code 200
412345
And run the command "config:app:delete libresign signature_text_template" with result code 0
413346
And run the command "config:app:delete libresign footer_template" with result code 0
414347
And run the command "config:app:delete libresign config_path" with result code 0

0 commit comments

Comments
 (0)