Skip to content

Commit fd576b5

Browse files
Merge pull request #32305 from nextcloud/bugfix/32302/fix-browser-agent-trimming
Fix user agent trimming on installation
2 parents 6084d69 + 7b3e221 commit fd576b5

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib/private/Authentication/Token/PublicKeyTokenProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function generateToken(string $token,
8585
int $type = IToken::TEMPORARY_TOKEN,
8686
int $remember = IToken::DO_NOT_REMEMBER): IToken {
8787
if (mb_strlen($name) > 128) {
88-
throw new InvalidTokenException('The given name is too long');
88+
$name = mb_substr($name, 0, 120) . '';
8989
}
9090

9191
$dbToken = $this->newToken($token, $uid, $loginName, $password, $name, $type, $remember);

tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ public function testGenerateToken() {
9494
}
9595

9696
public function testGenerateTokenInvalidName() {
97-
$this->expectException(\OC\Authentication\Exceptions\InvalidTokenException::class);
98-
9997
$token = 'token';
10098
$uid = 'user';
10199
$user = 'User';
@@ -107,6 +105,13 @@ public function testGenerateTokenInvalidName() {
107105
$type = IToken::PERMANENT_TOKEN;
108106

109107
$actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER);
108+
109+
$this->assertInstanceOf(PublicKeyToken::class, $actual);
110+
$this->assertSame($uid, $actual->getUID());
111+
$this->assertSame($user, $actual->getLoginName());
112+
$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());
113+
$this->assertSame(IToken::DO_NOT_REMEMBER, $actual->getRemember());
114+
$this->assertSame($password, $this->tokenProvider->getPassword($actual, $token));
110115
}
111116

112117
public function testUpdateToken() {

0 commit comments

Comments
 (0)