Skip to content

Commit 13d1c4a

Browse files
authored
Merge pull request #7535 from LibreSign/backport/7534/stable33
[stable33] fix: return 404 when pdf node is missing
2 parents 2ad7114 + d34a6e3 commit 13d1c4a

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

lib/Service/AccountService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ public function getPdfByUuid(string $uuid): File {
342342

343343
$userId = $this->fileMapper->getStorageUserIdByUuid($uuid);
344344
$this->folderService->setUserId($userId);
345-
return $this->folderService->getFileByNodeId($nodeId);
345+
try {
346+
return $this->folderService->getFileByNodeId($nodeId);
347+
} catch (NotFoundException) {
348+
throw new DoesNotExistException('Not found');
349+
}
346350
}
347351

348352
public function getFileByNodeId(int $nodeId): File {

tests/php/Unit/Service/AccountServiceTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,46 @@ public function testGetPdfByUuidWithSuccessAndUnignedFile():void {
307307
$this->assertInstanceOf(\OCP\Files\File::class, $actual);
308308
}
309309

310+
public function testGetPdfByUuidThrowsDoesNotExistWhenNodeNotFound(): void {
311+
$libresignFile = $this->createMock(\OCA\Libresign\Db\File::class);
312+
$libresignFile->method('__call')
313+
->willReturnCallback(fn ($method)
314+
=> match ($method) {
315+
'getSignedNodeId' => null,
316+
'getNodeId' => 123,
317+
'getStatus' => \OCA\Libresign\Enum\FileStatus::DRAFT->value,
318+
}
319+
);
320+
321+
$this->fileMapper
322+
->expects($this->once())
323+
->method('getByUuid')
324+
->with('uuid')
325+
->willReturn($libresignFile);
326+
327+
$this->fileMapper
328+
->expects($this->once())
329+
->method('getStorageUserIdByUuid')
330+
->with('uuid')
331+
->willReturn('guest-user');
332+
333+
$this->folderService
334+
->expects($this->once())
335+
->method('setUserId')
336+
->with('guest-user');
337+
338+
$this->folderService
339+
->expects($this->once())
340+
->method('getFileByNodeId')
341+
->with(123)
342+
->willThrowException(new NotFoundException('Invalid node'));
343+
344+
$this->expectException(DoesNotExistException::class);
345+
$this->expectExceptionMessage('Not found');
346+
347+
$this->getService()->getPdfByUuid('uuid');
348+
}
349+
310350
public function testCanRequestSignWithUnexistentUser():void {
311351
$actual = $this->getService()->canRequestSign();
312352
$this->assertFalse($actual);

0 commit comments

Comments
 (0)