0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-01-31 06:43:12 +00:00
nextcloud_server/apps/federatedfilesharing/tests/TokenHandlerTest.php
Andy Scherzinger 5b7dcc1427
chore: Add SPDX header
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
2024-05-29 08:58:16 +02:00

42 lines
1 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() {
$this->secureRandom->expects($this->once())->method('generate')
->with(
$this->expectedTokenLength,
ISecureRandom::CHAR_ALPHANUMERIC
)
->willReturn('mytoken');
$this->assertSame('mytoken', $this->tokenHandler->generateToken());
}
}