Skip to content

Commit

Permalink
Merge pull request #32305 from nextcloud/bugfix/32302/fix-browser-age…
Browse files Browse the repository at this point in the history
…nt-trimming

Fix user agent trimming on installation
  • Loading branch information
nickvergessen authored May 16, 2022
2 parents 6084d69 + 7b3e221 commit fd576b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function generateToken(string $token,
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);
Expand Down
9 changes: 7 additions & 2 deletions tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ public function testGenerateToken() {
}

public function testGenerateTokenInvalidName() {
$this->expectException(\OC\Authentication\Exceptions\InvalidTokenException::class);

$token = 'token';
$uid = 'user';
$user = 'User';
Expand All @@ -107,6 +105,13 @@ public function testGenerateTokenInvalidName() {
$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() {
Expand Down

0 comments on commit fd576b5

Please sign in to comment.