You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.5 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Files_Sharing\Tests;
  27. use OC\Files\Filesystem;
  28. use OC\Files\View;
  29. use OCP\Lock\ILockingProvider;
  30. use OCP\Share\IShare;
  31. /**
  32. * Class LockingTest
  33. *
  34. * @group DB
  35. *
  36. * @package OCA\Files_Sharing\Tests
  37. */
  38. class LockingTest extends TestCase {
  39. /**
  40. * @var \Test\Util\User\Dummy
  41. */
  42. private $userBackend;
  43. private $ownerUid;
  44. private $recipientUid;
  45. protected function setUp(): void {
  46. parent::setUp();
  47. $this->userBackend = new \Test\Util\User\Dummy();
  48. \OC::$server->getUserManager()->registerBackend($this->userBackend);
  49. $this->ownerUid = $this->getUniqueID('owner_');
  50. $this->recipientUid = $this->getUniqueID('recipient_');
  51. $this->userBackend->createUser($this->ownerUid, '');
  52. $this->userBackend->createUser($this->recipientUid, '');
  53. $this->loginAsUser($this->ownerUid);
  54. Filesystem::mkdir('/foo');
  55. Filesystem::file_put_contents('/foo/bar.txt', 'asd');
  56. $fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
  57. $this->share(
  58. IShare::TYPE_USER,
  59. '/foo/bar.txt',
  60. $this->ownerUid,
  61. $this->recipientUid,
  62. \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
  63. );
  64. $this->loginAsUser($this->recipientUid);
  65. $this->assertTrue(Filesystem::file_exists('bar.txt'));
  66. }
  67. protected function tearDown(): void {
  68. \OC::$server->getUserManager()->removeBackend($this->userBackend);
  69. parent::tearDown();
  70. }
  71. public function testLockAsRecipient() {
  72. $this->expectException(\OCP\Lock\LockedException::class);
  73. $this->loginAsUser($this->ownerUid);
  74. Filesystem::initMountPoints($this->recipientUid);
  75. $recipientView = new View('/' . $this->recipientUid . '/files');
  76. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  77. Filesystem::rename('/foo', '/asd');
  78. }
  79. public function testUnLockAsRecipient() {
  80. $this->loginAsUser($this->ownerUid);
  81. Filesystem::initMountPoints($this->recipientUid);
  82. $recipientView = new View('/' . $this->recipientUid . '/files');
  83. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  84. $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  85. $this->assertTrue(Filesystem::rename('/foo', '/asd'));
  86. }
  87. public function testChangeLock() {
  88. Filesystem::initMountPoints($this->recipientUid);
  89. $recipientView = new View('/' . $this->recipientUid . '/files');
  90. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED);
  91. $recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  92. $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  93. $this->addToAssertionCount(1);
  94. }
  95. }