Skip to content

Commit cded452

Browse files
authored
Merge pull request #5562 from LibreSign/fix/validate-display-name
chore: valdiate display name at API side
2 parents 3a994b9 + c0ed114 commit cded452

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

lib/Helper/ValidateHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,17 @@ private function validateSignerData(mixed $signer): void {
522522
throw new LibresignException($this->l10n->t('No signers'));
523523
}
524524

525+
$this->validateSignerDisplayName($signer);
525526
$this->validateSignerIdentifyMethods($signer);
526527
}
527528

529+
private function validateSignerDisplayName(array $signer): void {
530+
if (isset($signer['displayName']) && strlen($signer['displayName']) > 64) {
531+
// It's an api error, don't translate
532+
throw new LibresignException('Display name must not be longer than 64 characters');
533+
}
534+
}
535+
528536
private function validateSignerIdentifyMethods(array $signer): void {
529537
$normalizedMethods = $this->normalizeIdentifyMethods($signer);
530538

tests/php/Unit/Helper/ValidateHelperTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,60 @@ public static function providerValidateIdentifySigners(): array {
851851
true, // should throw
852852
'Invalid identify method structure'
853853
],
854+
'valid displayName within 64 characters' => [
855+
[
856+
'users' => [
857+
[
858+
'displayName' => 'Valid Display Name',
859+
'identify' => [
860+
'account' => 'user@example.com'
861+
]
862+
]
863+
]
864+
],
865+
false, // should not throw
866+
],
867+
'displayName exactly 64 characters' => [
868+
[
869+
'users' => [
870+
[
871+
'displayName' => str_repeat('A', 64),
872+
'identify' => [
873+
'account' => 'user@example.com'
874+
]
875+
]
876+
]
877+
],
878+
false, // should not throw
879+
],
880+
'displayName too long - 65 characters' => [
881+
[
882+
'users' => [
883+
[
884+
'displayName' => str_repeat('A', 65),
885+
'identify' => [
886+
'account' => 'user@example.com'
887+
]
888+
]
889+
]
890+
],
891+
true, // should throw
892+
'Display name must not be longer than 64 characters'
893+
],
894+
'displayName too long - 100 characters' => [
895+
[
896+
'users' => [
897+
[
898+
'displayName' => str_repeat('B', 100),
899+
'identify' => [
900+
'account' => 'user@example.com'
901+
]
902+
]
903+
]
904+
],
905+
true, // should throw
906+
'Display name must not be longer than 64 characters'
907+
],
854908
];
855909
}
856910
}

0 commit comments

Comments
 (0)