chore: valdiate display name at API side

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
This commit is contained in:
Vitor Mattos 2025-10-13 15:47:47 -03:00
parent 3a994b9fd0
commit c0ed114657
No known key found for this signature in database
GPG key ID: 6FECE2AD4809003A
2 changed files with 62 additions and 0 deletions

View file

@ -522,9 +522,17 @@ class ValidateHelper {
throw new LibresignException($this->l10n->t('No signers'));
}
$this->validateSignerDisplayName($signer);
$this->validateSignerIdentifyMethods($signer);
}
private function validateSignerDisplayName(array $signer): void {
if (isset($signer['displayName']) && strlen($signer['displayName']) > 64) {
// It's an api error, don't translate
throw new LibresignException('Display name must not be longer than 64 characters');
}
}
private function validateSignerIdentifyMethods(array $signer): void {
$normalizedMethods = $this->normalizeIdentifyMethods($signer);

View file

@ -851,6 +851,60 @@ final class ValidateHelperTest extends \OCA\Libresign\Tests\Unit\TestCase {
true, // should throw
'Invalid identify method structure'
],
'valid displayName within 64 characters' => [
[
'users' => [
[
'displayName' => 'Valid Display Name',
'identify' => [
'account' => 'user@example.com'
]
]
]
],
false, // should not throw
],
'displayName exactly 64 characters' => [
[
'users' => [
[
'displayName' => str_repeat('A', 64),
'identify' => [
'account' => 'user@example.com'
]
]
]
],
false, // should not throw
],
'displayName too long - 65 characters' => [
[
'users' => [
[
'displayName' => str_repeat('A', 65),
'identify' => [
'account' => 'user@example.com'
]
]
]
],
true, // should throw
'Display name must not be longer than 64 characters'
],
'displayName too long - 100 characters' => [
[
'users' => [
[
'displayName' => str_repeat('B', 100),
'identify' => [
'account' => 'user@example.com'
]
]
]
],
true, // should throw
'Display name must not be longer than 64 characters'
],
];
}
}