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.

permissions.php 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Vincent Petry
  6. * @copyright 2013 Vincent Petry <pvince81@owncloud.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. require_once __DIR__ . '/base.php';
  23. class Test_Files_Sharing_Permissions extends Test_Files_Sharing_Base {
  24. private $sharedStorageRestrictedShare;
  25. private $sharedCacheRestrictedShare;
  26. function setUp() {
  27. parent::setUp();
  28. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  29. // prepare user1's dir structure
  30. $textData = "dummy file data\n";
  31. $this->view->mkdir('container');
  32. $this->view->mkdir('container/shareddir');
  33. $this->view->mkdir('container/shareddir/subdir');
  34. $this->view->mkdir('container/shareddirrestricted');
  35. $this->view->mkdir('container/shareddirrestricted/subdir');
  36. $this->view->file_put_contents('container/shareddir/textfile.txt', $textData);
  37. $this->view->file_put_contents('container/shareddirrestricted/textfile1.txt', $textData);
  38. list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
  39. $this->ownerCache = $this->ownerStorage->getCache();
  40. $this->ownerStorage->getScanner()->scan('');
  41. // share "shareddir" with user2
  42. $fileinfo = $this->view->getFileInfo('container/shareddir');
  43. \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
  44. self::TEST_FILES_SHARING_API_USER2, 31);
  45. $fileinfo2 = $this->view->getFileInfo('container/shareddirrestricted');
  46. \OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
  47. self::TEST_FILES_SHARING_API_USER2, 7);
  48. // login as user2
  49. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  50. // retrieve the shared storage
  51. $this->secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
  52. list($this->sharedStorage, $internalPath) = $this->secondView->resolvePath('files/shareddir');
  53. list($this->sharedStorageRestrictedShare, $internalPath) = $this->secondView->resolvePath('files/shareddirrestricted');
  54. $this->sharedCache = $this->sharedStorage->getCache();
  55. $this->sharedCacheRestrictedShare = $this->sharedStorageRestrictedShare->getCache();
  56. }
  57. function tearDown() {
  58. $this->sharedCache->clear();
  59. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  60. $fileinfo = $this->view->getFileInfo('container/shareddir');
  61. \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
  62. self::TEST_FILES_SHARING_API_USER2);
  63. $fileinfo2 = $this->view->getFileInfo('container/shareddirrestricted');
  64. \OCP\Share::unshare('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
  65. self::TEST_FILES_SHARING_API_USER2);
  66. $this->view->deleteAll('container');
  67. $this->ownerCache->clear();
  68. parent::tearDown();
  69. }
  70. /**
  71. * Test that the permissions of shared directory are returned correctly
  72. */
  73. function testGetPermissions() {
  74. $sharedDirPerms = $this->sharedStorage->getPermissions('shareddir');
  75. $this->assertEquals(31, $sharedDirPerms);
  76. $sharedDirPerms = $this->sharedStorage->getPermissions('shareddir/textfile.txt');
  77. $this->assertEquals(31, $sharedDirPerms);
  78. $sharedDirRestrictedPerms = $this->sharedStorageRestrictedShare->getPermissions('shareddirrestricted');
  79. $this->assertEquals(7, $sharedDirRestrictedPerms);
  80. $sharedDirRestrictedPerms = $this->sharedStorageRestrictedShare->getPermissions('shareddirrestricted/textfile.txt');
  81. $this->assertEquals(7, $sharedDirRestrictedPerms);
  82. }
  83. /**
  84. * Test that the permissions of shared directory are returned correctly
  85. */
  86. function testGetDirectoryPermissions() {
  87. $contents = $this->secondView->getDirectoryContent('files/shareddir');
  88. $this->assertEquals('subdir', $contents[0]['name']);
  89. $this->assertEquals(31, $contents[0]['permissions']);
  90. $this->assertEquals('textfile.txt', $contents[1]['name']);
  91. $this->assertEquals(31, $contents[1]['permissions']);
  92. $contents = $this->secondView->getDirectoryContent('files/shareddirrestricted');
  93. $this->assertEquals('subdir', $contents[0]['name']);
  94. $this->assertEquals(7, $contents[0]['permissions']);
  95. $this->assertEquals('textfile1.txt', $contents[1]['name']);
  96. $this->assertEquals(7, $contents[1]['permissions']);
  97. }
  98. }