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.

LockingTest.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. /**
  31. * Class LockingTest
  32. *
  33. * @group DB
  34. *
  35. * @package OCA\Files_Sharing\Tests
  36. */
  37. class LockingTest extends TestCase {
  38. /**
  39. * @var \Test\Util\User\Dummy
  40. */
  41. private $userBackend;
  42. private $ownerUid;
  43. private $recipientUid;
  44. protected function setUp(): void {
  45. parent::setUp();
  46. $this->userBackend = new \Test\Util\User\Dummy();
  47. \OC::$server->getUserManager()->registerBackend($this->userBackend);
  48. $this->ownerUid = $this->getUniqueID('owner_');
  49. $this->recipientUid = $this->getUniqueID('recipient_');
  50. $this->userBackend->createUser($this->ownerUid, '');
  51. $this->userBackend->createUser($this->recipientUid, '');
  52. $this->loginAsUser($this->ownerUid);
  53. Filesystem::mkdir('/foo');
  54. Filesystem::file_put_contents('/foo/bar.txt', 'asd');
  55. $fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
  56. $this->share(
  57. \OCP\Share::SHARE_TYPE_USER,
  58. '/foo/bar.txt',
  59. $this->ownerUid,
  60. $this->recipientUid,
  61. \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
  62. );
  63. $this->loginAsUser($this->recipientUid);
  64. $this->assertTrue(Filesystem::file_exists('bar.txt'));
  65. }
  66. protected function tearDown(): void {
  67. \OC::$server->getUserManager()->removeBackend($this->userBackend);
  68. parent::tearDown();
  69. }
  70. public function testLockAsRecipient() {
  71. $this->expectException(\OCP\Lock\LockedException::class);
  72. $this->loginAsUser($this->ownerUid);
  73. Filesystem::initMountPoints($this->recipientUid);
  74. $recipientView = new View('/' . $this->recipientUid . '/files');
  75. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  76. Filesystem::rename('/foo', '/asd');
  77. }
  78. public function testUnLockAsRecipient() {
  79. $this->loginAsUser($this->ownerUid);
  80. Filesystem::initMountPoints($this->recipientUid);
  81. $recipientView = new View('/' . $this->recipientUid . '/files');
  82. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  83. $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  84. $this->assertTrue(Filesystem::rename('/foo', '/asd'));
  85. }
  86. public function testChangeLock() {
  87. Filesystem::initMountPoints($this->recipientUid);
  88. $recipientView = new View('/' . $this->recipientUid . '/files');
  89. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED);
  90. $recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  91. $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  92. $this->addToAssertionCount(1);
  93. }
  94. }