mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Automatically cut the token name on the first level
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
c1215f573a
commit
d683e0d3d1
3 changed files with 34 additions and 3 deletions
|
|
@ -44,7 +44,7 @@ interface IProvider {
|
|||
* @param string $uid
|
||||
* @param string $loginName
|
||||
* @param string|null $password
|
||||
* @param string $name
|
||||
* @param string $name Name will be trimmed to 120 chars when longer
|
||||
* @param int $type token type
|
||||
* @param int $remember whether the session token should be used for remember-me
|
||||
* @return IToken
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Manager implements IProvider {
|
|||
* @param string $uid
|
||||
* @param string $loginName
|
||||
* @param string|null $password
|
||||
* @param string $name
|
||||
* @param string $name Name will be trimmed to 120 chars when longer
|
||||
* @param int $type token type
|
||||
* @param int $remember whether the session token should be used for remember-me
|
||||
* @return IToken
|
||||
|
|
@ -62,7 +62,7 @@ class Manager implements IProvider {
|
|||
int $type = IToken::TEMPORARY_TOKEN,
|
||||
int $remember = IToken::DO_NOT_REMEMBER): IToken {
|
||||
if (mb_strlen($name) > 128) {
|
||||
throw new InvalidTokenException('The given name is too long');
|
||||
$name = mb_substr($name, 0, 120) . '…';
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -114,6 +114,37 @@ class ManagerTest extends TestCase {
|
|||
$this->assertSame($token, $actual);
|
||||
}
|
||||
|
||||
public function testGenerateTokenTooLongName() {
|
||||
$token = $this->createMock(IToken::class);
|
||||
$token->method('getName')
|
||||
->willReturn(str_repeat('a', 120) . '…');
|
||||
|
||||
|
||||
$this->publicKeyTokenProvider->expects($this->once())
|
||||
->method('generateToken')
|
||||
->with(
|
||||
'token',
|
||||
'uid',
|
||||
'loginName',
|
||||
'password',
|
||||
str_repeat('a', 120) . '…',
|
||||
IToken::TEMPORARY_TOKEN,
|
||||
IToken::REMEMBER
|
||||
)->willReturn($token);
|
||||
|
||||
$actual = $this->manager->generateToken(
|
||||
'token',
|
||||
'uid',
|
||||
'loginName',
|
||||
'password',
|
||||
str_repeat('a', 200),
|
||||
IToken::TEMPORARY_TOKEN,
|
||||
IToken::REMEMBER
|
||||
);
|
||||
|
||||
$this->assertSame(121, mb_strlen($actual->getName()));
|
||||
}
|
||||
|
||||
public function tokenData(): array {
|
||||
return [
|
||||
[new PublicKeyToken()],
|
||||
|
|
|
|||
Loading…
Reference in a new issue