From 17f4160f05505fe338095efb29a8b668f8db0bea Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 9 May 2022 08:36:34 +0200 Subject: [PATCH] Fix user agent trimming on installation Signed-off-by: Joas Schilling --- .../Authentication/Token/PublicKeyTokenProvider.php | 2 +- .../Authentication/Token/PublicKeyTokenProviderTest.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php index fd9e8336cc2..cb776d6d757 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php +++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php @@ -86,7 +86,7 @@ class PublicKeyTokenProvider 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) . '…'; } $dbToken = $this->newToken($token, $uid, $loginName, $password, $name, $type, $remember); diff --git a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php index 9503a5e4501..0c2ab5a8969 100644 --- a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php +++ b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php @@ -96,8 +96,6 @@ class PublicKeyTokenProviderTest extends TestCase { } public function testGenerateTokenInvalidName() { - $this->expectException(\OC\Authentication\Exceptions\InvalidTokenException::class); - $token = 'token'; $uid = 'user'; $user = 'User'; @@ -109,6 +107,13 @@ class PublicKeyTokenProviderTest extends TestCase { $type = IToken::PERMANENT_TOKEN; $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER); + + $this->assertInstanceOf(PublicKeyToken::class, $actual); + $this->assertSame($uid, $actual->getUID()); + $this->assertSame($user, $actual->getLoginName()); + $this->assertSame('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12User-Agent: Mozill…', $actual->getName()); + $this->assertSame(IToken::DO_NOT_REMEMBER, $actual->getRemember()); + $this->assertSame($password, $this->tokenProvider->getPassword($actual, $token)); } public function testUpdateToken() { -- 2.39.5