0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-03-12 15:37:27 +00:00
nextcloud_server/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php
Andy Scherzinger 1f7e2ba599
chore: Add SPDX header
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
2024-05-13 17:41:36 +02:00

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() {
$this->random
->expects($this->once())
->method('generate')
->with(3)
->willReturn('abc');
$this->assertSame('abc', $this->csrfTokenGenerator->generateToken(3));
}
public function testGenerateTokenWithDefault() {
$this->random
->expects($this->once())
->method('generate')
->with(32)
->willReturn('12345678901234567890123456789012');
$this->assertSame('12345678901234567890123456789012', $this->csrfTokenGenerator->generateToken(32));
}
}