mirror of
https://github.com/nextcloud/server.git
synced 2024-12-29 00:18:42 +00:00
49dd79eabb
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
namespace OCA\FederatedFileSharing\Tests;
|
|
|
|
use OCA\FederatedFileSharing\TokenHandler;
|
|
use OCP\Security\ISecureRandom;
|
|
|
|
class TokenHandlerTest extends \Test\TestCase {
|
|
|
|
/** @var TokenHandler */
|
|
private $tokenHandler;
|
|
|
|
/** @var ISecureRandom | \PHPUnit\Framework\MockObject\MockObject */
|
|
private $secureRandom;
|
|
|
|
/** @var int */
|
|
private $expectedTokenLength = 15;
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->secureRandom = $this->getMockBuilder(ISecureRandom::class)->getMock();
|
|
|
|
$this->tokenHandler = new TokenHandler($this->secureRandom);
|
|
}
|
|
|
|
public function testGenerateToken(): void {
|
|
$this->secureRandom->expects($this->once())->method('generate')
|
|
->with(
|
|
$this->expectedTokenLength,
|
|
ISecureRandom::CHAR_ALPHANUMERIC
|
|
)
|
|
->willReturn('mytoken');
|
|
|
|
$this->assertSame('mytoken', $this->tokenHandler->generateToken());
|
|
}
|
|
}
|