mirror of
https://github.com/LibreSign/libresign.git
synced 2025-12-18 05:20:45 +01:00
chore: valdiate display name at API side
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
This commit is contained in:
parent
3a994b9fd0
commit
c0ed114657
2 changed files with 62 additions and 0 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue