diff --git a/lib/Handler/SignEngine/JSignPdf/HashAlgorithmResolver.php b/lib/Handler/SignEngine/JSignPdf/HashAlgorithmResolver.php new file mode 100644 index 0000000000..c9b1d231cf --- /dev/null +++ b/lib/Handler/SignEngine/JSignPdf/HashAlgorithmResolver.php @@ -0,0 +1,86 @@ +getConfiguredAlgorithm(); + /** + * Need to respect the follow code: + * https://github.com/intoolswetrust/jsignpdf/blob/JSignPdf_2_2_2/jsignpdf/src/main/java/net/sf/jsignpdf/types/HashAlgorithm.java#L46-L47 + */ + if ($pdfVersion === null) { + return $this->validate($configuredAlgorithm); + } + + return $this->forPdfVersion($pdfVersion, $configuredAlgorithm); + } + + /** + * PDFs older than 1.6 have to be upgraded before JSignPdf accepts SHA-256. + */ + public function requiresPdfVersionUpgradeForSha256(float $pdfVersion): bool { + if ($pdfVersion >= self::MIN_PDF_VERSION_SHA256) { + return false; + } + + return $this->getConfiguredAlgorithm() === self::DEFAULT_ALGORITHM; + } + + private function forPdfVersion(float $pdfVersion, string $configuredAlgorithm): string { + // Legacy compatibility: JSignPdf still requires SHA1 for very old PDFs (< 1.6). + // The policy still exposes SHA1 for supported legacy workflows, and the runtime + // must continue enforcing this fallback for ancient PDFs that JSignPdf cannot sign otherwise. + if ($pdfVersion < self::MIN_PDF_VERSION_SHA256) { + return 'SHA1'; + } + if ($pdfVersion < self::MIN_PDF_VERSION_SHA1_REJECT) { + return self::DEFAULT_ALGORITHM; + } + if ($configuredAlgorithm === 'SHA1') { + return self::DEFAULT_ALGORITHM; + } + + return $this->validate($configuredAlgorithm); + } + + private function validate(string $algorithm): string { + return in_array($algorithm, self::SUPPORTED_ALGORITHMS, true) ? $algorithm : self::DEFAULT_ALGORITHM; + } + + private function getConfiguredAlgorithm(): string { + return (string)$this->policyService->resolve(SignatureHashAlgorithmPolicy::KEY)->getEffectiveValue(); + } +} diff --git a/lib/Handler/SignEngine/JSignPdfHandler.php b/lib/Handler/SignEngine/JSignPdf/JSignPdfHandler.php similarity index 91% rename from lib/Handler/SignEngine/JSignPdfHandler.php rename to lib/Handler/SignEngine/JSignPdf/JSignPdfHandler.php index 0becbc5ee5..dfbd76952c 100644 --- a/lib/Handler/SignEngine/JSignPdfHandler.php +++ b/lib/Handler/SignEngine/JSignPdf/JSignPdfHandler.php @@ -6,17 +6,17 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\Libresign\Handler\SignEngine; +namespace OCA\Libresign\Handler\SignEngine\JSignPdf; use Imagick; use ImagickPixel; use OCA\Libresign\AppInfo\Application; use OCA\Libresign\Exception\LibresignException; use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory; +use OCA\Libresign\Handler\SignEngine\Pkcs12Handler; use OCA\Libresign\Helper\JavaHelper; use OCA\Libresign\Service\DocMdp\ConfigService as DocMdpConfigService; use OCA\Libresign\Service\Policy\PolicyService; -use OCA\Libresign\Service\Policy\Provider\SignatureHashAlgorithm\SignatureHashAlgorithmPolicy; use OCA\Libresign\Service\Policy\Provider\SignatureText\SignatureTextPolicyValue; use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicy; use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicyValue; @@ -33,9 +33,7 @@ class JSignPdfHandler extends Pkcs12Handler { private const float MIN_PDF_VERSION = 1.2; private const string TARGET_OLD_PDF_VERSION = '1.3'; - private const float MIN_PDF_VERSION_SHA256 = 1.6; private const string TARGET_PDF_VERSION_SHA256 = '1.6'; - private const float MIN_PDF_VERSION_SHA1_REJECT = 1.7; private const int PAGE_FIRST = 1; private const int SCALE_FACTOR_MIN = 5; @@ -55,6 +53,7 @@ public function __construct( protected CertificateEngineFactory $certificateEngineFactory, protected JavaHelper $javaHelper, private DocMdpConfigService $docMdpConfigService, + private HashAlgorithmResolver $hashAlgorithmResolver, ) { } @@ -151,21 +150,6 @@ private function createEmptyFile(string $path): void { fclose($file); } - private function getHashAlgorithm(string $pdfContent): string { - $configuredAlgorithm = (string)$this->policyService->resolve(SignatureHashAlgorithmPolicy::KEY)->getEffectiveValue(); - /** - * Need to respect the follow code: - * https://github.com/intoolswetrust/jsignpdf/blob/JSignPdf_2_2_2/jsignpdf/src/main/java/net/sf/jsignpdf/types/HashAlgorithm.java#L46-L47 - */ - $pdfVersion = $this->extractPdfVersion($pdfContent); - - if ($pdfVersion === null) { - return $this->validateHashAlgorithm($configuredAlgorithm); - } - - return $this->getHashAlgorithmForPdfVersion($pdfVersion, $configuredAlgorithm); - } - private function extractPdfVersion(string $content): ?float { if (!preg_match('/^%PDF-(?\d+(\.\d+)?)/', $content, $match)) { return null; @@ -173,27 +157,6 @@ private function extractPdfVersion(string $content): ?float { return (float)$match['version']; } - private function getHashAlgorithmForPdfVersion(float $pdfVersion, string $configuredAlgorithm): string { - // Legacy compatibility: JSignPdf still requires SHA1 for very old PDFs (< 1.6). - // The policy still exposes SHA1 for supported legacy workflows, and the runtime - // must continue enforcing this fallback for ancient PDFs that JSignPdf cannot sign otherwise. - if ($pdfVersion < 1.6) { - return 'SHA1'; - } - if ($pdfVersion < self::MIN_PDF_VERSION_SHA1_REJECT) { - return 'SHA256'; - } - if ($pdfVersion >= self::MIN_PDF_VERSION_SHA1_REJECT && $configuredAlgorithm === 'SHA1') { - return 'SHA256'; - } - return $this->validateHashAlgorithm($configuredAlgorithm); - } - - private function validateHashAlgorithm(string $algorithm): string { - $supportedAlgorithms = ['SHA1', 'SHA256', 'SHA384', 'SHA512', 'RIPEMD160']; - return in_array($algorithm, $supportedAlgorithms) ? $algorithm : 'SHA256'; - } - /** * Normalizes very old PDFs (1.0/1.1) to 1.3. * Rationale: JSignPDF enum PdfVersion only defines 1.2+; for 1.0/1.1, @@ -213,7 +176,7 @@ private function normalizePdfVersion(string $content): string { // Convert PDFs < 1.6 to 1.6 if using SHA-256 (the default hash algorithm) // This prevents "The chosen hash algorithm (SHA-256) requires a newer PDF version" error - if ($this->requiresPdfVersionUpgradeForSha256($version)) { + if ($this->hashAlgorithmResolver->requiresPdfVersionUpgradeForSha256($version)) { return $this->replacePdfVersion($content, self::TARGET_PDF_VERSION_SHA256); } @@ -224,14 +187,6 @@ private function isVeryOldPdfVersion(float $version): bool { return $version > 0 && $version < self::MIN_PDF_VERSION; } - private function requiresPdfVersionUpgradeForSha256(float $version): bool { - if ($version >= self::MIN_PDF_VERSION_SHA256) { - return false; - } - $hashAlgorithm = (string)$this->policyService->resolve(SignatureHashAlgorithmPolicy::KEY)->getEffectiveValue(); - return $hashAlgorithm === 'SHA256'; - } - private function replacePdfVersion(string $content, string $newVersion): string { return (string)preg_replace('/^%PDF-\d+(\.\d+)?/', '%PDF-' . $newVersion, $content, 1); } @@ -256,7 +211,7 @@ public function sign(): File { #[\Override] public function getSignedContent(): string { $normalizedPdf = $this->normalizePdfVersion($this->getInputFile()->getContent()); - $hashAlgorithm = $this->getHashAlgorithm($normalizedPdf); + $hashAlgorithm = $this->hashAlgorithmResolver->forSignature($this->extractPdfVersion($normalizedPdf)); $param = $this->getJSignParam(); $param->setCertificate($this->getCertificate()) ->setPdf($normalizedPdf) diff --git a/lib/Handler/SignEngine/Pkcs12Handler.php b/lib/Handler/SignEngine/Pkcs12Handler.php index 1259881921..498ae23b27 100644 --- a/lib/Handler/SignEngine/Pkcs12Handler.php +++ b/lib/Handler/SignEngine/Pkcs12Handler.php @@ -14,6 +14,7 @@ use OCA\Libresign\Handler\CertificateEngine\OrderCertificatesTrait; use OCA\Libresign\Handler\DocMdpHandler; use OCA\Libresign\Handler\FooterHandler; +use OCA\Libresign\Handler\SignEngine\JSignPdf\JSignPdfHandler; use OCA\Libresign\Service\CaIdentifierService; use OCA\Libresign\Service\Crl\CrlService; use OCA\Libresign\Service\FolderService; @@ -30,6 +31,11 @@ class Pkcs12Handler extends SignEngineHandler { use OrderCertificatesTrait; protected string $certificate = ''; + /** @var array> */ + private const ENGINE_HANDLERS = [ + 'jSignPdfHandler' => JSignPdfHandler::class, + 'phpNativeHandler' => PhpNativeHandler::class, + ]; private ?JSignPdfHandler $jSignPdfHandler = null; private ?PhpNativeHandler $phpNativeHandler = null; private string $rootCertificatePem = ''; @@ -379,11 +385,13 @@ private function enrichLeafWithNativeData( private function getHandler(): SignEngineHandler { $sign_engine = $this->appConfig->getValueString(Application::APP_ID, 'signature_engine', 'JSignPdf'); $property = lcfirst($sign_engine) . 'Handler'; - if (!property_exists($this, $property)) { + // Resolved through a class map instead of a name built at runtime, so + // moving a handler to another namespace cannot break this silently. + if (!isset(self::ENGINE_HANDLERS[$property])) { // TRANSLATORS API/config error when LibreSign's signature_engine setting names a backend that is not available (for example a mistyped JSignPdf/native engine). throw new LibresignException($this->l10n->t('Invalid Sign engine.'), 400); } - $classHandler = 'OCA\\Libresign\\Handler\\SignEngine\\' . ucfirst($property); + $classHandler = self::ENGINE_HANDLERS[$property]; if (!$this->$property instanceof $classHandler) { $this->$property = \OCP\Server::get($classHandler); } diff --git a/lib/SetupCheck/JSignPdfSetupCheck.php b/lib/SetupCheck/JSignPdfSetupCheck.php index 873a51eb47..53c9ab56cd 100644 --- a/lib/SetupCheck/JSignPdfSetupCheck.php +++ b/lib/SetupCheck/JSignPdfSetupCheck.php @@ -9,7 +9,7 @@ namespace OCA\Libresign\SetupCheck; use OCA\Libresign\AppInfo\Application; -use OCA\Libresign\Handler\SignEngine\JSignPdfHandler; +use OCA\Libresign\Handler\SignEngine\JSignPdf\JSignPdfHandler; use OCA\Libresign\Helper\JavaHelper; use OCA\Libresign\Service\Install\InstallService; use OCA\Libresign\Service\Install\SignSetupService; diff --git a/tests/php/Unit/Handler/SignEngine/JSignPdf/HashAlgorithmResolverTest.php b/tests/php/Unit/Handler/SignEngine/JSignPdf/HashAlgorithmResolverTest.php new file mode 100644 index 0000000000..754eaf5247 --- /dev/null +++ b/tests/php/Unit/Handler/SignEngine/JSignPdf/HashAlgorithmResolverTest.php @@ -0,0 +1,90 @@ +policyService = $this->createMock(PolicyService::class); + } + + private function getInstance(mixed $configuredAlgorithm): HashAlgorithmResolver { + $this->policyService + ->method('resolve') + ->with(SignatureHashAlgorithmPolicy::KEY) + ->willReturn( + (new ResolvedPolicy()) + ->setPolicyKey(SignatureHashAlgorithmPolicy::KEY) + ->setEffectiveValue($configuredAlgorithm) + ); + + return new HashAlgorithmResolver($this->policyService); + } + + #[DataProvider('providerSignatureHashAlgorithm')] + public function testForSignature(mixed $configuredAlgorithm, ?float $pdfVersion, string $expected): void { + $resolver = $this->getInstance($configuredAlgorithm); + + $this->assertSame($expected, $resolver->forSignature($pdfVersion)); + } + + public static function providerSignatureHashAlgorithm(): array { + return [ + // Unknown PDF version: only the configured algorithm decides. + 'unknown version keeps a supported algorithm' => ['SHA384', null, 'SHA384'], + 'unknown version keeps RIPEMD160' => ['RIPEMD160', null, 'RIPEMD160'], + 'unknown version falls back on an empty algorithm' => ['', null, 'SHA256'], + 'unknown version falls back on an unsupported algorithm' => ['XYZ', null, 'SHA256'], + 'unknown version falls back on an unset policy' => [null, null, 'SHA256'], + // JSignPdf only accepts SHA1 in PDFs older than 1.6. + 'PDF 1.0 is signed with SHA1' => ['SHA256', 1.0, 'SHA1'], + 'PDF 1.5 is signed with SHA1' => ['SHA512', 1.5, 'SHA1'], + // Between 1.6 and 1.7 JSignPdf only accepts SHA256. + 'PDF 1.6 is signed with SHA256' => ['SHA384', 1.6, 'SHA256'], + 'PDF 1.6 ignores an unsupported algorithm' => ['XYZ', 1.6, 'SHA256'], + // From 1.7 on the configured algorithm is used, except SHA1. + 'PDF 1.7 keeps the configured SHA384' => ['SHA384', 1.7, 'SHA384'], + 'PDF 1.7 keeps the configured SHA512' => ['SHA512', 1.7, 'SHA512'], + 'PDF 1.7 keeps the configured RIPEMD160' => ['RIPEMD160', 1.7, 'RIPEMD160'], + 'PDF 1.7 replaces SHA1 with SHA256' => ['SHA1', 1.7, 'SHA256'], + 'PDF 2.0 replaces SHA1 with SHA256' => ['SHA1', 2.0, 'SHA256'], + 'PDF 2.0 falls back on an unsupported algorithm' => ['XYZ', 2.0, 'SHA256'], + 'PDF 2.0 keeps the configured SHA512' => ['SHA512', 2.0, 'SHA512'], + ]; + } + + #[DataProvider('providerPdfVersionUpgrade')] + public function testRequiresPdfVersionUpgradeForSha256(mixed $configuredAlgorithm, float $pdfVersion, bool $expected): void { + $resolver = $this->getInstance($configuredAlgorithm); + + $this->assertSame($expected, $resolver->requiresPdfVersionUpgradeForSha256($pdfVersion)); + } + + public static function providerPdfVersionUpgrade(): array { + return [ + 'SHA256 in a PDF 1.2 needs the upgrade' => ['SHA256', 1.2, true], + 'SHA256 in a PDF 1.5 needs the upgrade' => ['SHA256', 1.5, true], + 'SHA256 in a PDF 1.6 does not need the upgrade' => ['SHA256', 1.6, false], + 'SHA256 in a PDF 1.7 does not need the upgrade' => ['SHA256', 1.7, false], + 'SHA1 in a PDF 1.5 does not need the upgrade' => ['SHA1', 1.5, false], + 'SHA512 in a PDF 1.5 does not need the upgrade' => ['SHA512', 1.5, false], + 'an unset policy in a PDF 1.5 does not need the upgrade' => [null, 1.5, false], + ]; + } +} diff --git a/tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php b/tests/php/Unit/Handler/SignEngine/JSignPdf/JSignPdfHandlerTest.php similarity index 94% rename from tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php rename to tests/php/Unit/Handler/SignEngine/JSignPdf/JSignPdfHandlerTest.php index 2bfb503345..8c2f2ab2dc 100644 --- a/tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php +++ b/tests/php/Unit/Handler/SignEngine/JSignPdf/JSignPdfHandlerTest.php @@ -6,7 +6,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\Libresign\Tests\Unit\Handler\SignEngine; +namespace OCA\Libresign\Tests\Unit\Handler\SignEngine\JSignPdf; use OCA\Libresign\AppInfo\Application; use OCA\Libresign\DataObjects\VisibleElementAssoc; @@ -14,7 +14,8 @@ use OCA\Libresign\Enum\DocMdpLevel; use OCA\Libresign\Exception\LibresignException; use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory; -use OCA\Libresign\Handler\SignEngine\JSignPdfHandler; +use OCA\Libresign\Handler\SignEngine\JSignPdf\HashAlgorithmResolver; +use OCA\Libresign\Handler\SignEngine\JSignPdf\JSignPdfHandler; use OCA\Libresign\Helper\JavaHelper; use OCA\Libresign\Service\CaIdentifierService; use OCA\Libresign\Service\DocMdp\ConfigService as DocMdpConfigService; @@ -132,6 +133,7 @@ private function getInstance(array $methods = []): JSignPdfHandler|MockObject { // Create mock factory if initialization failed in setUpBeforeClass $certificateEngineFactory = self::$certificateEngineFactory ?? $this->createMock(CertificateEngineFactory::class); + $hashAlgorithmResolver = new HashAlgorithmResolver($policyService); if (empty($methods)) { return new JSignPdfHandler( @@ -144,6 +146,7 @@ private function getInstance(array $methods = []): JSignPdfHandler|MockObject { $certificateEngineFactory, $this->javaHelper, $this->createMock(DocMdpConfigService::class), + $hashAlgorithmResolver, ); } return $this->getMockBuilder(JSignPdfHandler::class) @@ -157,6 +160,7 @@ private function getInstance(array $methods = []): JSignPdfHandler|MockObject { $certificateEngineFactory, $this->javaHelper, $this->createMock(DocMdpConfigService::class), + $hashAlgorithmResolver, ]) ->onlyMethods($methods) ->getMock(); @@ -198,40 +202,6 @@ private function setDocMdpConfigService(JSignPdfHandler $handler, DocMdpConfigSe $reflection->setValue($handler, $docMdpConfigService); } - #[DataProvider('providerGetHashAlgorithm')] - public function testGetHashAlgorithm(string $setting, string $content, string $expected): void { - if (self::$certificateEngineFactory === null || empty(self::$certificateContent)) { - $this->markTestSkipped('Certificate initialization failed'); - } - - $this->persistHashAlgorithmPolicy($setting); - $instance = $this->getInstance(['getInputFile']); - $file = $this->createMock(\OCP\Files\File::class); - $file->method('getContent')->willReturn($content); - $instance->method('getInputFile')->willReturn($file); - $actual = self::invokePrivate($instance, 'getHashAlgorithm', [$content]); - $this->assertEquals($expected, $actual); - } - - public static function providerGetHashAlgorithm(): array { - return [ - 'empty setting, PDF 1.6' => ['', '%PDF-1.6', 'SHA256'], - 'invalid PDF header' => ['', 'random data', 'SHA256'], - 'invalid setting, fallback to SHA256 on PDF 1.7' => ['XYZ', '%PDF-1.7', 'SHA256'], - 'null-like setting, PDF 1.5' => ['0', '%PDF-1.5', 'SHA1'], - 'default with PDF 1.0' => ['', '%PDF-1', 'SHA1'], - 'SHA1 with PDF 1.5' => ['', '%PDF-1.5', 'SHA1'], - 'SHA1 with PDF 1.6' => ['', '%PDF-1.6', 'SHA256'], - 'SHA1 with PDF 1.7' => ['', '%PDF-1.7', 'SHA256'], - 'SHA1 with PDF 2.0' => ['', '%PDF-2.0', 'SHA256'], - 'SHA384, PDF 1.6 (fallback)' => ['SHA384', '%PDF-1.6', 'SHA256'], - 'SHA384, PDF 1.7' => ['SHA384', '%PDF-1.7', 'SHA384'], - 'SHA512, PDF 1.6' => ['SHA512', '%PDF-1.6', 'SHA256'], - 'RIPEMD160, PDF 1.6 (unsupported)' => ['RIPEMD160', '%PDF-1.6', 'SHA256'], - 'RIPEMD160, PDF 1.7 (supported)' => ['RIPEMD160', '%PDF-1.7', 'RIPEMD160'], - ]; - } - #[DataProvider('providerExtractPdfVersion')] public function testExtractPdfVersion(string $content, ?float $expected): void { if (self::$certificateEngineFactory === null || empty(self::$certificateContent)) { @@ -345,7 +315,7 @@ public function testSignAffectedParams( ); $this->signatureBackgroundService->method('getImagePath')->willReturn( - realpath(__DIR__ . '/../../../../../img/LibreSign.png') + realpath(__DIR__ . '/../../../../../../img/LibreSign.png') ); $this->persistSignatureStampPolicy( @@ -416,7 +386,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 0, 'urx' => 0, 'ury' => 0, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 100, 'signatureHeight' => 100, 'template' => '', @@ -434,7 +404,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => '', @@ -452,7 +422,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => 'aaaaa', @@ -470,7 +440,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => 'aaaaa', @@ -488,7 +458,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => 'aaaaa', @@ -506,7 +476,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => 'a"b $c \'d e', @@ -524,7 +494,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => '', @@ -542,7 +512,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => 'aaaaa', @@ -560,7 +530,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 100, 'urx' => 351, 'ury' => 200, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 350, 'signatureHeight' => 100, 'template' => 'aaaaa', @@ -578,7 +548,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => 'aaaaa', @@ -635,7 +605,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 20, 'signatureHeight' => 20, 'template' => '', @@ -653,7 +623,7 @@ public static function providerSignAffectedParams(): array { 'lly' => 20, 'urx' => 30, 'ury' => 40, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png'))], + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png'))], 'signatureWidth' => 0, 'signatureHeight' => 0, 'template' => '', @@ -677,7 +647,7 @@ public function testDocMdpAppliedOnlyOnFirstVisibleElement(): void { $this->signatureBackgroundService->method('getSignatureBackgroundType')->willReturn('deleted'); $this->signatureBackgroundService->method('getImagePath')->willReturn( - realpath(__DIR__ . '/../../../../../img/LibreSign.png') + realpath(__DIR__ . '/../../../../../../img/LibreSign.png') ); $this->persistSignatureStampPolicy('', SignerElementsService::RENDER_MODE_DESCRIPTION_ONLY, 10, SignatureTextPolicyValue::DEFAULT_SIGNATURE_FONT_SIZE, 100, 100); @@ -708,14 +678,14 @@ public function testDocMdpAppliedOnlyOnFirstVisibleElement(): void { 'lly' => 10, 'urx' => 110, 'ury' => 60, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png')), + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png')), self::getElement([ 'page' => 1, 'llx' => 120, 'lly' => 10, 'urx' => 220, 'ury' => 60, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png')), + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png')), ]); $jSignPdfHandler->setJSignPdf($mock); $jSignPdfHandler->setInputFile($inputFile); @@ -740,7 +710,7 @@ public function testDocMdpSkippedWhenSignatureExists(): void { $this->signatureBackgroundService->method('getSignatureBackgroundType')->willReturn('deleted'); $this->signatureBackgroundService->method('getImagePath')->willReturn( - realpath(__DIR__ . '/../../../../../img/LibreSign.png') + realpath(__DIR__ . '/../../../../../../img/LibreSign.png') ); $this->persistSignatureStampPolicy('', SignerElementsService::RENDER_MODE_DESCRIPTION_ONLY, 10, SignatureTextPolicyValue::DEFAULT_SIGNATURE_FONT_SIZE, 100, 100); @@ -771,7 +741,7 @@ public function testDocMdpSkippedWhenSignatureExists(): void { 'lly' => 10, 'urx' => 110, 'ury' => 60, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png')), + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png')), ]); $jSignPdfHandler->setJSignPdf($mock); $jSignPdfHandler->setInputFile($inputFile); @@ -1220,7 +1190,7 @@ public static function providerCertificationLevelWithoutVisibleElements(): array 'lly' => 10, 'urx' => 110, 'ury' => 60, - ], realpath(__DIR__ . '/../../../../../img/app-dark.png')); + ], realpath(__DIR__ . '/../../../../../../img/app-dark.png')); $tsa = ['url' => 'https://tsa.example.test/tsr']; return [ 'certification before the TSA options when the PDF has no signature' => [ diff --git a/tests/php/Unit/SetupCheck/JSignPdfSetupCheckTest.php b/tests/php/Unit/SetupCheck/JSignPdfSetupCheckTest.php index 9e56a4fdf3..efbdf37c6b 100644 --- a/tests/php/Unit/SetupCheck/JSignPdfSetupCheckTest.php +++ b/tests/php/Unit/SetupCheck/JSignPdfSetupCheckTest.php @@ -22,7 +22,7 @@ function is_dir(string $filename): bool { namespace OCA\Libresign\Tests\Unit\SetupCheck; -use OCA\Libresign\Handler\SignEngine\JSignPdfHandler; +use OCA\Libresign\Handler\SignEngine\JSignPdf\JSignPdfHandler; use OCA\Libresign\Helper\JavaHelper; use OCA\Libresign\Service\Install\InstallService; use OCA\Libresign\Service\Install\JSignPdfRelease;