2014-05-27 23:51:23 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2014-05-27 23:51:23 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2014-05-27 23:51:23 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2014-05-27 23:51:23 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-05-27 23:51:23 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-05-27 23:51:23 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-05-27 23:51:23 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-05-17 12:42:03 +03:00
|
|
|
namespace OCA\Files_Sharing\Tests;
|
2016-11-04 15:07:16 +03:00
|
|
|
use OCP\IGroupManager;
|
|
|
|
use OCP\IUserManager;
|
2016-05-17 12:42:03 +03:00
|
|
|
|
2015-02-26 13:37:37 +03:00
|
|
|
/**
|
2016-05-17 12:42:03 +03:00
|
|
|
* Class SharedMountTest
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
2016-09-29 01:53:53 +03:00
|
|
|
* @group SLOWDB
|
2015-02-26 13:37:37 +03:00
|
|
|
*/
|
2016-05-17 12:42:03 +03:00
|
|
|
class SharedMountTest extends TestCase {
|
2014-05-27 23:51:23 +04:00
|
|
|
|
2016-11-04 15:07:16 +03:00
|
|
|
/** @var IGroupManager */
|
|
|
|
private $groupManager;
|
|
|
|
|
|
|
|
/** @var IUserManager */
|
|
|
|
private $userManager;
|
|
|
|
|
2014-11-11 00:28:12 +03:00
|
|
|
protected function setUp() {
|
2014-05-27 23:51:23 +04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->folder = '/folder_share_storage_test';
|
|
|
|
|
|
|
|
$this->filename = '/share-api-storage.txt';
|
|
|
|
|
|
|
|
|
|
|
|
$this->view->mkdir($this->folder);
|
|
|
|
|
|
|
|
// save file with content
|
2017-07-24 08:44:09 +03:00
|
|
|
$this->view->file_put_contents($this->filename, 'root file');
|
|
|
|
$this->view->file_put_contents($this->folder . $this->filename, 'file in subfolder');
|
2016-11-04 15:07:16 +03:00
|
|
|
|
|
|
|
$this->groupManager = \OC::$server->getGroupManager();
|
|
|
|
$this->userManager = \OC::$server->getUserManager();
|
2014-05-27 23:51:23 +04:00
|
|
|
}
|
|
|
|
|
2014-11-11 00:28:12 +03:00
|
|
|
protected function tearDown() {
|
2015-12-02 16:49:27 +03:00
|
|
|
if ($this->view) {
|
2016-04-15 10:02:17 +03:00
|
|
|
if ($this->view->file_exists($this->folder)) {
|
|
|
|
$this->view->unlink($this->folder);
|
|
|
|
}
|
|
|
|
if ($this->view->file_exists($this->filename)) {
|
|
|
|
$this->view->unlink($this->filename);
|
|
|
|
}
|
2015-12-02 16:49:27 +03:00
|
|
|
}
|
2014-05-27 23:51:23 +04:00
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test if the mount point moves up if the parent folder no longer exists
|
|
|
|
*/
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testShareMountLoseParentFolder() {
|
2014-05-27 23:51:23 +04:00
|
|
|
|
|
|
|
// share to user
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_USER,
|
|
|
|
$this->folder,
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
\OCP\Constants::PERMISSION_ALL);
|
2019-11-19 18:09:26 +03:00
|
|
|
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
|
2014-05-27 23:51:23 +04:00
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share->setTarget('/foo/bar' . $this->folder);
|
|
|
|
$this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
|
2014-05-27 23:51:23 +04:00
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $this->shareManager->getShareById($share->getFullId());
|
|
|
|
$this->assertSame('/foo/bar' . $this->folder, $share->getTarget());
|
2014-05-27 23:51:23 +04:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
// share should have moved up
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $this->shareManager->getShareById($share->getFullId());
|
|
|
|
$this->assertSame($this->folder, $share->getTarget());
|
2014-05-27 23:51:23 +04:00
|
|
|
|
|
|
|
//cleanup
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2014-05-27 23:51:23 +04:00
|
|
|
$this->view->unlink($this->folder);
|
|
|
|
}
|
|
|
|
|
2014-06-03 21:29:00 +04:00
|
|
|
/**
|
2014-05-27 23:51:23 +04:00
|
|
|
* @medium
|
|
|
|
*/
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testDeleteParentOfMountPoint() {
|
2014-05-27 23:51:23 +04:00
|
|
|
// share to user
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_USER,
|
|
|
|
$this->folder,
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
\OCP\Constants::PERMISSION_ALL
|
|
|
|
);
|
2014-05-27 23:51:23 +04:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
$this->assertTrue($user2View->file_exists($this->folder));
|
|
|
|
|
|
|
|
// create a local folder
|
|
|
|
$result = $user2View->mkdir('localfolder');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
// move mount point to local folder
|
|
|
|
$result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
// mount point in the root folder should no longer exist
|
|
|
|
$this->assertFalse($user2View->is_dir($this->folder));
|
|
|
|
|
|
|
|
// delete the local folder
|
|
|
|
$result = $user2View->unlink('/localfolder');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
//enforce reload of the mount points
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
//mount point should be back at the root
|
|
|
|
$this->assertTrue($user2View->is_dir($this->folder));
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$this->view->unlink($this->folder);
|
|
|
|
}
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testMoveSharedFile() {
|
|
|
|
$share = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_USER,
|
|
|
|
$this->filename,
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
|
|
|
);
|
2014-06-03 21:29:00 +04:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
2015-04-13 13:36:47 +03:00
|
|
|
\OC\Files\Filesystem::rename($this->filename, $this->filename . '_renamed');
|
2014-06-03 21:29:00 +04:00
|
|
|
|
2015-04-13 13:36:47 +03:00
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
|
2014-06-03 21:29:00 +04:00
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
2015-04-13 13:36:47 +03:00
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
|
|
|
|
|
|
|
|
// rename back to original name
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
\OC\Files\Filesystem::rename($this->filename . '_renamed', $this->filename);
|
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
2014-06-03 21:29:00 +04:00
|
|
|
|
|
|
|
//cleanup
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2014-06-03 21:29:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* share file with a group if a user renames the file the filename should not change
|
|
|
|
* for the other users
|
|
|
|
*/
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testMoveGroupShare () {
|
2016-11-04 15:07:16 +03:00
|
|
|
$testGroup = $this->groupManager->createGroup('testGroup');
|
|
|
|
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
$testGroup->addUser($user1);
|
|
|
|
$testGroup->addUser($user2);
|
|
|
|
$testGroup->addUser($user3);
|
2014-06-03 21:29:00 +04:00
|
|
|
|
|
|
|
$fileinfo = $this->view->getFileInfo($this->filename);
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_GROUP,
|
|
|
|
$this->filename,
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
'testGroup',
|
|
|
|
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
|
|
|
);
|
2019-11-19 18:09:26 +03:00
|
|
|
$this->shareManager->acceptShare($share, $user1->getUID());
|
|
|
|
$this->shareManager->acceptShare($share, $user2->getUID());
|
|
|
|
$this->shareManager->acceptShare($share, $user3->getUID());
|
2014-06-03 21:29:00 +04:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
|
|
|
|
2017-07-24 08:44:09 +03:00
|
|
|
\OC\Files\Filesystem::rename($this->filename, 'newFileName');
|
2014-06-03 21:29:00 +04:00
|
|
|
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists('newFileName'));
|
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
2017-07-24 08:44:09 +03:00
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists('newFileName'));
|
2014-06-03 21:29:00 +04:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
2017-07-24 08:44:09 +03:00
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists('newFileName'));
|
2014-06-03 21:29:00 +04:00
|
|
|
|
|
|
|
//cleanup
|
2015-01-14 23:06:26 +03:00
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2016-11-04 15:07:16 +03:00
|
|
|
$testGroup->removeUser($user1);
|
|
|
|
$testGroup->removeUser($user2);
|
|
|
|
$testGroup->removeUser($user3);
|
2014-06-03 21:29:00 +04:00
|
|
|
}
|
|
|
|
|
2014-09-29 13:13:01 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider dataProviderTestStripUserFilesPath
|
|
|
|
* @param string $path
|
|
|
|
* @param string $expectedResult
|
|
|
|
* @param bool $exception if a exception is expected
|
|
|
|
*/
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testStripUserFilesPath($path, $expectedResult, $exception) {
|
2014-09-29 13:13:01 +04:00
|
|
|
$testClass = new DummyTestClassSharedMount(null, null);
|
|
|
|
try {
|
|
|
|
$result = $testClass->stripUserFilesPathDummy($path);
|
|
|
|
$this->assertSame($expectedResult, $result);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
if ($exception) {
|
|
|
|
$this->assertSame(10, $e->getCode());
|
|
|
|
} else {
|
2017-07-24 08:44:09 +03:00
|
|
|
$this->assertTrue(false, 'Exception catched, but expected: ' . $expectedResult);
|
2014-09-29 13:13:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
public function dataProviderTestStripUserFilesPath() {
|
2014-09-29 13:13:01 +04:00
|
|
|
return array(
|
|
|
|
array('/user/files/foo.txt', '/foo.txt', false),
|
|
|
|
array('/user/files/folder/foo.txt', '/folder/foo.txt', false),
|
|
|
|
array('/data/user/files/foo.txt', null, true),
|
|
|
|
array('/data/user/files/', null, true),
|
|
|
|
array('/files/foo.txt', null, true),
|
|
|
|
array('/foo.txt', null, true),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
public function dataPermissionMovedGroupShare() {
|
2015-10-09 12:57:10 +03:00
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$powerset = function($permissions) {
|
|
|
|
$results = [\OCP\Constants::PERMISSION_READ];
|
|
|
|
|
|
|
|
foreach ($permissions as $permission) {
|
|
|
|
foreach ($results as $combination) {
|
|
|
|
$results[] = $permission | $combination;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $results;
|
|
|
|
};
|
|
|
|
|
|
|
|
//Generate file permissions
|
|
|
|
$permissions = [
|
|
|
|
\OCP\Constants::PERMISSION_UPDATE,
|
|
|
|
\OCP\Constants::PERMISSION_SHARE,
|
|
|
|
];
|
|
|
|
|
|
|
|
$allPermissions = $powerset($permissions);
|
|
|
|
|
|
|
|
foreach ($allPermissions as $before) {
|
|
|
|
foreach ($allPermissions as $after) {
|
|
|
|
if ($before === $after) { continue; }
|
|
|
|
|
|
|
|
$data[] = [
|
2019-11-19 18:09:26 +03:00
|
|
|
'file',
|
2015-10-09 12:57:10 +03:00
|
|
|
$before,
|
|
|
|
$after,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Generate folder permissions
|
|
|
|
$permissions = [
|
|
|
|
\OCP\Constants::PERMISSION_UPDATE,
|
|
|
|
\OCP\Constants::PERMISSION_CREATE,
|
|
|
|
\OCP\Constants::PERMISSION_SHARE,
|
2015-10-27 12:22:59 +03:00
|
|
|
\OCP\Constants::PERMISSION_DELETE,
|
2015-10-09 12:57:10 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$allPermissions = $powerset($permissions);
|
|
|
|
|
|
|
|
foreach ($allPermissions as $before) {
|
|
|
|
foreach ($allPermissions as $after) {
|
|
|
|
if ($before === $after) { continue; }
|
|
|
|
|
|
|
|
$data[] = [
|
|
|
|
'folder',
|
|
|
|
$before,
|
|
|
|
$after,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* moved mountpoints of a group share should keep the same permission as their parent group share.
|
|
|
|
* See #15253
|
|
|
|
*
|
|
|
|
* @dataProvider dataPermissionMovedGroupShare
|
|
|
|
*/
|
2017-07-24 08:44:09 +03:00
|
|
|
public function testPermissionMovedGroupShare($type, $beforePerm, $afterPerm) {
|
2015-10-09 12:57:10 +03:00
|
|
|
|
|
|
|
if ($type === 'file') {
|
|
|
|
$path = $this->filename;
|
|
|
|
} else if ($type === 'folder') {
|
|
|
|
$path = $this->folder;
|
|
|
|
}
|
|
|
|
|
2016-11-04 15:07:16 +03:00
|
|
|
$testGroup = $this->groupManager->createGroup('testGroup');
|
|
|
|
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
$testGroup->addUser($user1);
|
|
|
|
$testGroup->addUser($user2);
|
|
|
|
$testGroup->addUser($user3);
|
2015-10-09 12:57:10 +03:00
|
|
|
|
|
|
|
// Share item with group
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_GROUP,
|
|
|
|
$path,
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
'testGroup',
|
|
|
|
$beforePerm
|
2015-10-09 12:57:10 +03:00
|
|
|
);
|
2019-11-19 18:09:26 +03:00
|
|
|
$this->shareManager->acceptShare($share, $user1->getUID());
|
|
|
|
$this->shareManager->acceptShare($share, $user2->getUID());
|
|
|
|
$this->shareManager->acceptShare($share, $user3->getUID());
|
2015-10-09 12:57:10 +03:00
|
|
|
|
|
|
|
// Login as user 2 and verify the item exists
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($path));
|
2016-04-15 10:02:17 +03:00
|
|
|
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertEquals($beforePerm, $result->getPermissions());
|
2015-10-09 12:57:10 +03:00
|
|
|
|
|
|
|
// Now move the item forcing a new entry in the share table
|
2017-07-24 08:44:09 +03:00
|
|
|
\OC\Files\Filesystem::rename($path, 'newPath');
|
2015-10-09 12:57:10 +03:00
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists('newPath'));
|
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists($path));
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
// change permissions
|
|
|
|
$share->setPermissions($afterPerm);
|
|
|
|
$this->shareManager->updateShare($share);
|
2015-10-09 12:57:10 +03:00
|
|
|
|
|
|
|
// Login as user 3 and verify that the permissions are changed
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
2016-04-15 10:02:17 +03:00
|
|
|
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER3);
|
2015-10-09 12:57:10 +03:00
|
|
|
$this->assertNotEmpty($result);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->assertEquals($afterPerm, $result->getPermissions());
|
2015-10-09 12:57:10 +03:00
|
|
|
|
|
|
|
// Login as user 2 and verify that the permissions are changed
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
2016-04-15 10:02:17 +03:00
|
|
|
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
2015-10-09 12:57:10 +03:00
|
|
|
$this->assertNotEmpty($result);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->assertEquals($afterPerm, $result->getPermissions());
|
|
|
|
$this->assertEquals('/newPath', $result->getTarget());
|
2015-10-09 12:57:10 +03:00
|
|
|
|
|
|
|
//cleanup
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2016-11-04 15:07:16 +03:00
|
|
|
$testGroup->removeUser($user1);
|
|
|
|
$testGroup->removeUser($user2);
|
|
|
|
$testGroup->removeUser($user3);
|
2015-10-09 12:57:10 +03:00
|
|
|
}
|
|
|
|
|
2015-10-23 14:57:09 +03:00
|
|
|
/**
|
2019-11-19 18:09:26 +03:00
|
|
|
* If the permissions on a group share are upgraded be sure to still respect
|
2015-10-23 14:57:09 +03:00
|
|
|
* removed shares by a member of that group
|
|
|
|
*/
|
2017-07-24 08:44:09 +03:00
|
|
|
public function testPermissionUpgradeOnUserDeletedGroupShare() {
|
2016-11-04 15:07:16 +03:00
|
|
|
$testGroup = $this->groupManager->createGroup('testGroup');
|
|
|
|
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
$testGroup->addUser($user1);
|
|
|
|
$testGroup->addUser($user2);
|
|
|
|
$testGroup->addUser($user3);
|
2015-10-23 14:57:09 +03:00
|
|
|
|
|
|
|
$connection = \OC::$server->getDatabaseConnection();
|
|
|
|
|
|
|
|
// Share item with group
|
|
|
|
$fileinfo = $this->view->getFileInfo($this->folder);
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_GROUP,
|
|
|
|
$this->folder,
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
'testGroup',
|
|
|
|
\OCP\Constants::PERMISSION_READ
|
2015-10-23 14:57:09 +03:00
|
|
|
);
|
2019-11-19 18:09:26 +03:00
|
|
|
$this->shareManager->acceptShare($share, $user1->getUID());
|
|
|
|
$this->shareManager->acceptShare($share, $user2->getUID());
|
|
|
|
$this->shareManager->acceptShare($share, $user3->getUID());
|
2015-10-23 14:57:09 +03:00
|
|
|
|
|
|
|
// Login as user 2 and verify the item exists
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
|
2016-04-15 10:02:17 +03:00
|
|
|
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
2015-10-23 14:57:09 +03:00
|
|
|
$this->assertNotEmpty($result);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->assertEquals(\OCP\Constants::PERMISSION_READ, $result->getPermissions());
|
2015-10-23 14:57:09 +03:00
|
|
|
|
|
|
|
// Delete the share
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::rmdir($this->folder));
|
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
|
|
|
|
|
|
|
|
// Verify we do not get a share
|
2016-04-15 10:02:17 +03:00
|
|
|
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertEquals(0, $result->getPermissions());
|
2015-10-23 14:57:09 +03:00
|
|
|
|
|
|
|
// Login as user 1 again and change permissions
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2016-04-15 10:02:17 +03:00
|
|
|
$share->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
|
|
|
$share = $this->shareManager->updateShare($share);
|
2015-10-23 14:57:09 +03:00
|
|
|
|
2019-11-19 18:09:26 +03:00
|
|
|
// Login as user 2 and verify
|
2015-10-23 14:57:09 +03:00
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
|
2016-04-15 10:02:17 +03:00
|
|
|
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertEquals(0, $result->getPermissions());
|
2015-10-23 14:57:09 +03:00
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2015-10-23 14:57:09 +03:00
|
|
|
|
|
|
|
//cleanup
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2016-11-04 15:07:16 +03:00
|
|
|
$testGroup->removeUser($user1);
|
|
|
|
$testGroup->removeUser($user2);
|
|
|
|
$testGroup->removeUser($user3);
|
2015-10-23 14:57:09 +03:00
|
|
|
}
|
|
|
|
|
2014-09-29 13:13:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class DummyTestClassSharedMount extends \OCA\Files_Sharing\SharedMount {
|
2014-11-06 20:31:33 +03:00
|
|
|
public function __construct($storage, $mountpoint, $arguments = null, $loader = null){
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
|
2014-09-29 13:13:01 +04:00
|
|
|
public function stripUserFilesPathDummy($path) {
|
|
|
|
return $this->stripUserFilesPath($path);
|
|
|
|
}
|
2014-05-27 23:51:23 +04:00
|
|
|
}
|