1
0

TokenHandlerTest.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\FederatedFileSharing\Tests;
  8. use OCA\FederatedFileSharing\TokenHandler;
  9. use OCP\Security\ISecureRandom;
  10. class TokenHandlerTest extends \Test\TestCase {
  11. /** @var TokenHandler */
  12. private $tokenHandler;
  13. /** @var ISecureRandom | \PHPUnit\Framework\MockObject\MockObject */
  14. private $secureRandom;
  15. /** @var int */
  16. private $expectedTokenLength = 15;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->secureRandom = $this->getMockBuilder(ISecureRandom::class)->getMock();
  20. $this->tokenHandler = new TokenHandler($this->secureRandom);
  21. }
  22. public function testGenerateToken(): void {
  23. $this->secureRandom->expects($this->once())->method('generate')
  24. ->with(
  25. $this->expectedTokenLength,
  26. ISecureRandom::CHAR_ALPHANUMERIC
  27. )
  28. ->willReturn('mytoken');
  29. $this->assertSame('mytoken', $this->tokenHandler->generateToken());
  30. }
  31. }