mirror of
https://github.com/nextcloud/server.git
synced 2025-01-16 08:09:00 +00:00
49dd79eabb
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
namespace Test\Security\CSRF;
|
|
|
|
class CsrfTokenGeneratorTest extends \Test\TestCase {
|
|
/** @var \OCP\Security\ISecureRandom */
|
|
private $random;
|
|
/** @var \OC\Security\CSRF\CsrfTokenGenerator */
|
|
private $csrfTokenGenerator;
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
$this->random = $this->getMockBuilder('\OCP\Security\ISecureRandom')
|
|
->disableOriginalConstructor()->getMock();
|
|
$this->csrfTokenGenerator = new \OC\Security\CSRF\CsrfTokenGenerator($this->random);
|
|
}
|
|
|
|
public function testGenerateTokenWithCustomNumber(): void {
|
|
$this->random
|
|
->expects($this->once())
|
|
->method('generate')
|
|
->with(3)
|
|
->willReturn('abc');
|
|
$this->assertSame('abc', $this->csrfTokenGenerator->generateToken(3));
|
|
}
|
|
|
|
public function testGenerateTokenWithDefault(): void {
|
|
$this->random
|
|
->expects($this->once())
|
|
->method('generate')
|
|
->with(32)
|
|
->willReturn('12345678901234567890123456789012');
|
|
$this->assertSame('12345678901234567890123456789012', $this->csrfTokenGenerator->generateToken(32));
|
|
}
|
|
}
|