Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/Service/SignFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,10 @@ private function signSequentially(array $signRequests): ?DateTimeInterface {
continue;
}
$this->signRequest = $signRequestData['signRequest'];
if ($this->signRequest->getSigned()) {
// Never sign a child twice for the same signer: a retried request would stack signatures
continue;
}
$this->engine = null;
$this->setVisibleElements($this->elementsInput);
$this->fileToSign = null;
Expand Down Expand Up @@ -1664,8 +1668,15 @@ public function getNextcloudFiles(FileEntity $fileData): array {
]), AppFrameworkHttp::STATUS_NOT_FOUND);
}
$storageUserId = $this->fileMapper->getStorageUserIdByUuid($fileData->getUuid());
$previousUserId = $this->folderService->getUserId();
$this->folderService->setUserId($storageUserId);
$fileToSign = $this->folderService->getFileByNodeId($nodeId);
try {
$fileToSign = $this->folderService->getFileByNodeId($nodeId);
} finally {
// Restore the signer context, otherwise later lookups (e.g. visible elements of the next
// envelope child) run as the file owner
$this->folderService->setUserId($previousUserId);
}
if (!$fileToSign instanceof File) {
throw new LibresignException(json_encode([
'action' => JSActions::ACTION_DO_NOTHING,
Expand Down
21 changes: 21 additions & 0 deletions tests/php/Unit/Service/SignFileServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3163,4 +3163,25 @@ public function testCleanupUnsignedSignedFile(bool $hasFile, ?\Exception $delete

$this->assertNull(self::invokePrivate($service, 'createdSignedFile'));
}

public function testGetNextcloudFilesRestoresFolderServiceUserId(): void {
$fileData = new \OCA\Libresign\Db\File();
$fileData->setNodeId(42);
$fileData->setUuid('file-uuid');

$this->fileMapper->method('getStorageUserIdByUuid')->with('file-uuid')->willReturn('owner');
$userIds = [];
$this->folderService->method('getUserId')->willReturn('signer');
$this->folderService->method('setUserId')
->willReturnCallback(function (?string $userId) use (&$userIds): void {
$userIds[] = $userId;
});
$this->folderService->method('getFileByNodeId')->with(42)
->willReturn($this->createMock(\OCP\Files\File::class));

$service = $this->getService();
$service->getNextcloudFiles($fileData);

$this->assertSame(['owner', 'signer'], $userIds);
}
}