From 0448f7ac22bb49d757d44092463fbcd012b39d22 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 15 Jan 2025 18:19:01 -0300 Subject: [PATCH 1/2] fix: validate with success when signer account was deleted Signed-off-by: Vitor Mattos --- .../features/file/validate.feature | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/integration/features/file/validate.feature diff --git a/tests/integration/features/file/validate.feature b/tests/integration/features/file/validate.feature new file mode 100644 index 0000000000..87e466d069 --- /dev/null +++ b/tests/integration/features/file/validate.feature @@ -0,0 +1,31 @@ +Feature: validate + Scenario: Sign with account, delete the account and validate + Given as user "admin" + And run the command "libresign:install --use-local-cert --java" with result code 0 + And run the command "libresign:install --use-local-cert --jsignpdf" with result code 0 + And run the command "libresign:install --use-local-cert --pdftk" with result code 0 + And run the command "libresign:configure:openssl --cn test" with result code 0 + And sending "post" to ocs "/apps/provisioning_api/api/v1/config/apps/libresign/identify_methods" + | value | (string)[{"name":"account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":true}}}] | + And user "signer1" exists + When sending "post" to ocs "/apps/libresign/api/v1/request-signature" + | file | {"url":"/apps/libresign/develop/pdf"} | + | users | [{"identify":{"account":"signer1"}}] | + | name | Document Name | + Then the response should have a status code 200 + And as user "signer1" + And sending "get" to ocs "/apps/libresign/api/v1/file/list" + Then the response should be a JSON array with the following mandatory values + | key | value | + | (jq).ocs.data.data[0].name | Document Name | + And fetch field "(SIGN_URL)ocs.data.data.0.url" from prevous JSON response + And fetch field "(SIGN_UUID)ocs.data.data.0.signers.0.sign_uuid" from prevous JSON response + And fetch field "(FILE_UUID)ocs.data.data.0.uuid" from prevous JSON response + When sending "post" to ocs "/apps/libresign/api/v1/sign/uuid/" + | key | value | + | method | clickToSign | + Then the response should have a status code 200 + When run the command "user:delete signer1" with result code 0 + And as user "" + And sending "get" to ocs "/apps/libresign/api/v1/file/validate/uuid/" + Then the response should have a status code 200 From 1afd2b236b95777594e1c51564a4ac9eb5dc3ed1 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 15 Jan 2025 18:52:55 -0300 Subject: [PATCH 2/2] chore: add method to say if is a sign request or isn't Signed-off-by: Vitor Mattos --- lib/Service/FileService.php | 4 +++- lib/Service/IdentifyMethodService.php | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index a40d0b1ba0..65cde493a9 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -304,7 +304,9 @@ private function loadLibreSignSigners(): void { } $signers = $this->signRequestMapper->getByFileId($this->file->getId()); foreach ($signers as $signer) { - $identifyMethods = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signer->getId()); + $identifyMethods = $this->identifyMethodService + ->setIsRequest(false) + ->getIdentifyMethodsFromSignRequestId($signer->getId()); if (!empty($this->fileData->signers)) { $found = array_filter($this->fileData->signers, function ($found) use ($identifyMethods) { if (!isset($found['uid'])) { diff --git a/lib/Service/IdentifyMethodService.php b/lib/Service/IdentifyMethodService.php index a1e690e1f4..efe2f47e44 100644 --- a/lib/Service/IdentifyMethodService.php +++ b/lib/Service/IdentifyMethodService.php @@ -35,6 +35,7 @@ class IdentifyMethodService { self::IDENTIFY_PASSWORD, self::IDENTIFY_CLICK_TO_SIGN, ]; + private bool $isRequest = true; private ?IdentifyMethod $currentIdentifyMethod = null; private array $identifyMethodsSettings = []; /** @@ -51,6 +52,11 @@ public function __construct( ) { } + public function setIsRequest(bool $isRequest): self { + $this->isRequest = $isRequest; + return $this; + } + public function getInstanceOfIdentifyMethod(string $name, ?string $identifyValue = null): IIdentifyMethod { if ($identifyValue && isset($this->identifyMethods[$name])) { foreach ($this->identifyMethods[$name] as $identifyMethod) { @@ -67,7 +73,7 @@ public function getInstanceOfIdentifyMethod(string $name, ?string $identifyValue $entity->setIdentifierValue($identifyValue); $entity->setMandatory($this->isMandatoryMethod($name) ? 1 : 0); } - if ($identifyValue) { + if ($identifyValue && $this->isRequest) { $identifyMethod->validateToRequest(); }