]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix user agent trimming on installation 32420/head
authorJoas Schilling <coding@schilljs.com>
Mon, 9 May 2022 06:36:34 +0000 (08:36 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Mon, 16 May 2022 10:16:17 +0000 (10:16 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Authentication/Token/PublicKeyTokenProvider.php
tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php

index ddf477b346323bf7a2b5d190380d27ecadd459bd..c74cf960cb1dac0fc9d65ed7f1780cbf1261b93d 100644 (file)
@@ -85,7 +85,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);
index 767e7897c588d4eb492d44aca9c068fbb21ed96f..a587944a93070a8d6fe4129364f189cd44b95f0c 100644 (file)
@@ -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() {