Files
Peter Ringelmann 538aa1aec9 fix(auth): WebAuthn switch, OAuth state and token name handling
Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
2026-12-03 11:46:39 +01:00

51 lines
1.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Authentication\Token;
use OC\Authentication\Token\PublicKeyToken;
use OCP\Authentication\Token\IToken;
use Test\TestCase;
class PublicKeyTokenTest extends TestCase {
public function testSetScopeAsArray(): void {
$scope = [IToken::SCOPE_FILESYSTEM => false];
$token = new PublicKeyToken();
$token->setScope($scope);
$this->assertEquals(json_encode($scope), $token->getScope());
$this->assertEquals($scope, $token->getScopeAsArray());
}
public function testDefaultScope(): void {
$scope = [IToken::SCOPE_FILESYSTEM => true];
$token = new PublicKeyToken();
$this->assertEquals($scope, $token->getScopeAsArray());
}
public function testSetNameScrubsInvalidUtf8(): void {
$token = new PublicKeyToken();
$token->setName("Spy\xff");
$this->assertTrue(mb_check_encoding($token->getName(), 'UTF-8'));
$this->assertStringStartsWith('Spy', $token->getName());
}
public function testSetNameKeepsValidUtf8(): void {
$token = new PublicKeyToken();
$token->setName('Müller’s iPhone');
$this->assertSame('Müller’s iPhone', $token->getName());
}
public function testStoredInvalidNameSerializesToJson(): void {
$token = PublicKeyToken::fromRow(['id' => 1, 'name' => "Spy\xff", 'type' => IToken::PERMANENT_TOKEN]);
$this->assertIsString(json_encode($token->jsonSerialize(), JSON_THROW_ON_ERROR));
}
}