LockdownManagerTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Test\Lockdown;
  22. use OC\Authentication\Token\DefaultToken;
  23. use OC\Lockdown\LockdownManager;
  24. use OCP\ISession;
  25. use Test\TestCase;
  26. class LockdownManagerTest extends TestCase {
  27. private $sessionCallback;
  28. public function setUp() {
  29. parent::setUp();
  30. $this->sessionCallback = function() {
  31. return $this->createMock(ISession::class);
  32. };
  33. }
  34. public function testCanAccessFilesystemDisabled() {
  35. $manager = new LockdownManager($this->sessionCallback);
  36. $this->assertTrue($manager->canAccessFilesystem());
  37. }
  38. public function testCanAccessFilesystemAllowed() {
  39. $token = new DefaultToken();
  40. $token->setScope(['filesystem' => true]);
  41. $manager = new LockdownManager($this->sessionCallback);
  42. $manager->setToken($token);
  43. $this->assertTrue($manager->canAccessFilesystem());
  44. }
  45. public function testCanAccessFilesystemNotAllowed() {
  46. $token = new DefaultToken();
  47. $token->setScope(['filesystem' => false]);
  48. $manager = new LockdownManager($this->sessionCallback);
  49. $manager->setToken($token);
  50. $this->assertFalse($manager->canAccessFilesystem());
  51. }
  52. }