2016-02-04 03:59:52 -05:00
|
|
|
<?php
|
2024-05-28 10:42:42 -04:00
|
|
|
|
2025-05-29 05:50:46 -04:00
|
|
|
declare(strict_types=1);
|
2016-02-04 03:59:52 -05:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-02-04 03:59:52 -05:00
|
|
|
*/
|
2016-02-04 10:08:35 -05:00
|
|
|
namespace OCA\FederatedFileSharing\Tests;
|
2016-02-04 03:59:52 -05:00
|
|
|
|
|
|
|
|
use OCA\FederatedFileSharing\TokenHandler;
|
|
|
|
|
use OCP\Security\ISecureRandom;
|
2025-05-29 05:50:46 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2016-02-04 03:59:52 -05:00
|
|
|
|
2016-05-04 09:26:30 -04:00
|
|
|
class TokenHandlerTest extends \Test\TestCase {
|
2025-05-29 05:50:46 -04:00
|
|
|
private TokenHandler $tokenHandler;
|
|
|
|
|
private ISecureRandom&MockObject $secureRandom;
|
|
|
|
|
private int $expectedTokenLength = 15;
|
2016-02-04 03:59:52 -05:00
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2016-02-04 03:59:52 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2017-10-26 07:46:16 -04:00
|
|
|
$this->secureRandom = $this->getMockBuilder(ISecureRandom::class)->getMock();
|
2016-02-04 03:59:52 -05:00
|
|
|
|
|
|
|
|
$this->tokenHandler = new TokenHandler($this->secureRandom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGenerateToken(): void {
|
|
|
|
|
$this->secureRandom->expects($this->once())->method('generate')
|
|
|
|
|
->with(
|
|
|
|
|
$this->expectedTokenLength,
|
2021-07-07 11:52:46 -04:00
|
|
|
ISecureRandom::CHAR_ALPHANUMERIC
|
2016-02-04 03:59:52 -05:00
|
|
|
)
|
2018-01-14 05:33:53 -05:00
|
|
|
->willReturn('mytoken');
|
2016-02-04 03:59:52 -05:00
|
|
|
|
2018-01-14 05:33:53 -05:00
|
|
|
$this->assertSame('mytoken', $this->tokenHandler->generateToken());
|
2016-02-04 03:59:52 -05:00
|
|
|
}
|
|
|
|
|
}
|