LockdownManagerTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\Lockdown;
  7. use OC\Authentication\Token\PublicKeyToken;
  8. use OC\Lockdown\LockdownManager;
  9. use OCP\Authentication\Token\IToken;
  10. use OCP\ISession;
  11. use Test\TestCase;
  12. class LockdownManagerTest extends TestCase {
  13. private $sessionCallback;
  14. protected function setUp(): void {
  15. parent::setUp();
  16. $this->sessionCallback = function () {
  17. return $this->createMock(ISession::class);
  18. };
  19. }
  20. public function testCanAccessFilesystemDisabled(): void {
  21. $manager = new LockdownManager($this->sessionCallback);
  22. $this->assertTrue($manager->canAccessFilesystem());
  23. }
  24. public function testCanAccessFilesystemAllowed(): void {
  25. $token = new PublicKeyToken();
  26. $token->setScope([IToken::SCOPE_FILESYSTEM => true]);
  27. $manager = new LockdownManager($this->sessionCallback);
  28. $manager->setToken($token);
  29. $this->assertTrue($manager->canAccessFilesystem());
  30. }
  31. public function testCanAccessFilesystemNotAllowed(): void {
  32. $token = new PublicKeyToken();
  33. $token->setScope([IToken::SCOPE_FILESYSTEM => false]);
  34. $manager = new LockdownManager($this->sessionCallback);
  35. $manager->setToken($token);
  36. $this->assertFalse($manager->canAccessFilesystem());
  37. }
  38. }