LockingTest.php 3.4 KB

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. public function setUp() {
  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. public function tearDown() {
  67. \OC::$server->getUserManager()->removeBackend($this->userBackend);
  68. parent::tearDown();
  69. }
  70. /**
  71. * @expectedException \OCP\Lock\LockedException
  72. */
  73. public function testLockAsRecipient() {
  74. $this->loginAsUser($this->ownerUid);
  75. Filesystem::initMountPoints($this->recipientUid);
  76. $recipientView = new View('/' . $this->recipientUid . '/files');
  77. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  78. Filesystem::rename('/foo', '/asd');
  79. }
  80. public function testUnLockAsRecipient() {
  81. $this->loginAsUser($this->ownerUid);
  82. Filesystem::initMountPoints($this->recipientUid);
  83. $recipientView = new View('/' . $this->recipientUid . '/files');
  84. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  85. $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  86. $this->assertTrue(Filesystem::rename('/foo', '/asd'));
  87. }
  88. public function testChangeLock() {
  89. Filesystem::initMountPoints($this->recipientUid);
  90. $recipientView = new View('/' . $this->recipientUid . '/files');
  91. $recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED);
  92. $recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  93. $recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
  94. $this->addToAssertionCount(1);
  95. }
  96. }