Skip to content

Commit 53cbf76

Browse files
test: enforce java requirement for footer stamping
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 006429d commit 53cbf76

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

tests/php/Unit/Service/SignFileServiceTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,70 @@ public function testEnqueueParallelSigningJobsStoresCredentialsWhenPasswordless(
366366
$this->assertSame(1, $enqueued);
367367
}
368368

369+
public function testGetPdfToSignThrowsWhenPhpNativeAndJavaPathIsMissing(): void {
370+
$this->appConfig->setValueString('libresign', 'signature_engine', 'PhpNative');
371+
372+
$service = $this->getService(['getSignedFile', 'getSigners']);
373+
$libreSignFile = new File();
374+
$libreSignFile->setId(10);
375+
$libreSignFile->setUuid('file-uuid');
376+
377+
$originalFile = $this->createMock(\OCP\Files\File::class);
378+
$originalFile->method('getContent')->willReturn('%PDF-original-content%');
379+
$originalFile->method('getExtension')->willReturn('pdf');
380+
$originalFile->method('getPath')->willReturn('/Documents/source.pdf');
381+
$originalFile->method('getParentId')->willReturn(300);
382+
383+
$owner = $this->createMock(\OCP\IUser::class);
384+
$owner->method('getUID')->willReturn('signer1');
385+
$originalFile->method('getOwner')->willReturn($owner);
386+
387+
$this->pdfSignatureDetectionService
388+
->expects($this->once())
389+
->method('hasSignatures')
390+
->with('%PDF-original-content%')
391+
->willReturn(false);
392+
393+
$this->footerHandler
394+
->expects($this->once())
395+
->method('getMetadata')
396+
->with($originalFile, $libreSignFile)
397+
->willReturn(['d' => [['w' => 210.0, 'h' => 297.0]]]);
398+
399+
$this->footerHandler
400+
->expects($this->exactly(2))
401+
->method('setTemplateVar')
402+
->willReturnSelf();
403+
404+
$this->footerHandler
405+
->expects($this->once())
406+
->method('getFooter')
407+
->with([['w' => 210.0, 'h' => 297.0]])
408+
->willReturn('%PDF-footer%');
409+
410+
$this->tempManager
411+
->expects($this->exactly(2))
412+
->method('getTemporaryFile')
413+
->willReturnOnConsecutiveCalls('/tmp/libresign-test-stamp.pdf', '/tmp/libresign-test-input.pdf');
414+
415+
$this->pdf
416+
->expects($this->once())
417+
->method('applyStamp')
418+
->willThrowException(new \RuntimeException('Java path not set.'));
419+
420+
$service->method('getSignedFile')->willReturn(null);
421+
$service->method('getSigners')->willReturn([]);
422+
423+
$this->expectException(\OCA\Libresign\Exception\LibresignException::class);
424+
$this->expectExceptionMessage('Java path not set.');
425+
426+
self::invokePrivate(
427+
$service->setLibreSignFile($libreSignFile),
428+
'getPdfToSign',
429+
[$originalFile],
430+
);
431+
}
432+
369433
private function getService(array $methods = []): SignFileService|MockObject {
370434
if ($methods) {
371435
return $this->getMockBuilder(SignFileService::class)

0 commit comments

Comments
 (0)