Skip to content

Commit c8bad6f

Browse files
test(signature-text): add regression for invalid dimensions rejection
Add 24 data-provider entries covering zero, negative, fractional, subnormal, scientific, NaN and Inf values as both width-only, height-only and combined inputs. Add testGetFullSignatureDimensionsShouldFallbackToDefaultsWhenConfigIsInvalid covering stored 0, -1, NaN and Inf configs triggering auto-repair. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 3e266a1 commit c8bad6f

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/php/Unit/Service/SignatureTextServiceTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Imagick;
1313
use OCA\Libresign\AppInfo\Application;
14+
use OCA\Libresign\Exception\LibresignException;
1415
use OCA\Libresign\Service\SignatureTextService;
1516
use OCP\IAppConfig;
1617
use OCP\IDateTimeZone;
@@ -218,4 +219,60 @@ public static function providerSignerNameImage(): array {
218219
public function testHasFont(): void {
219220
$this->assertFileExists($fallbackFond = __DIR__ . '/../../../../3rdparty/composer/mpdf/mpdf/ttfonts/DejaVuSerifCondensed.ttf');
220221
}
222+
223+
#[DataProvider('providerInvalidSignatureDimensions')]
224+
public function testSaveShouldRejectInvalidSignatureDimensions(float $signatureWidth, float $signatureHeight): void {
225+
$this->expectException(LibresignException::class);
226+
227+
$this->getClass()->save(
228+
template: 'valid',
229+
signatureWidth: $signatureWidth,
230+
signatureHeight: $signatureHeight,
231+
);
232+
}
233+
234+
public static function providerInvalidSignatureDimensions(): array {
235+
return [
236+
'zero width' => [0.0, 100.0],
237+
'fractional width below minimum' => [0.9999, 100.0],
238+
'subnormal width' => [1.0E-320, 100.0],
239+
'scientific width below minimum' => [1.0E-6, 100.0],
240+
'negative width' => [-1.0, 100.0],
241+
'very small negative width' => [-0.0001, 100.0],
242+
'NaN width' => [NAN, 100.0],
243+
'INF width' => [INF, 100.0],
244+
'-INF width' => [-INF, 100.0],
245+
'zero height' => [350.0, 0.0],
246+
'fractional height below minimum' => [350.0, 0.9999],
247+
'subnormal height' => [350.0, 1.0E-320],
248+
'scientific height below minimum' => [350.0, 1.0E-6],
249+
'negative height' => [350.0, -1.0],
250+
'very small negative height' => [350.0, -0.0001],
251+
'NaN height' => [350.0, NAN],
252+
'INF height' => [350.0, INF],
253+
'-INF height' => [350.0, -INF],
254+
'both dimensions zero' => [0.0, 0.0],
255+
'both dimensions negative' => [-1.0, -1.0],
256+
'both dimensions fractional below minimum' => [0.5, 0.5],
257+
'both dimensions NaN' => [NAN, NAN],
258+
'both dimensions INF' => [INF, INF],
259+
'mixed NaN and -INF' => [NAN, -INF],
260+
];
261+
}
262+
263+
public function testGetFullSignatureDimensionsShouldFallbackToDefaultsWhenConfigIsInvalid(): void {
264+
$this->appConfig->setValueFloat(Application::APP_ID, 'signature_width', 0.0);
265+
$this->appConfig->setValueFloat(Application::APP_ID, 'signature_height', -1.0);
266+
267+
$class = $this->getClass();
268+
269+
$this->assertEquals(SignatureTextService::DEFAULT_SIGNATURE_WIDTH, $class->getFullSignatureWidth());
270+
$this->assertEquals(SignatureTextService::DEFAULT_SIGNATURE_HEIGHT, $class->getFullSignatureHeight());
271+
272+
$this->appConfig->setValueFloat(Application::APP_ID, 'signature_width', NAN);
273+
$this->appConfig->setValueFloat(Application::APP_ID, 'signature_height', INF);
274+
275+
$this->assertEquals(SignatureTextService::DEFAULT_SIGNATURE_WIDTH, $class->getFullSignatureWidth());
276+
$this->assertEquals(SignatureTextService::DEFAULT_SIGNATURE_HEIGHT, $class->getFullSignatureHeight());
277+
}
221278
}

0 commit comments

Comments
 (0)