2014-04-30 14:49:16 +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>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
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>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2014-04-30 14:49:16 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2014-04-30 14:49:16 +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-04-30 14:49:16 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-04-30 14:49:16 +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-04-30 14:49:16 +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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-04-30 14:49:16 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-05-17 12:42:03 +03:00
|
|
|
namespace OCA\Files_Sharing\Tests;
|
2014-04-30 14:49:16 +04:00
|
|
|
|
2017-01-25 14:22:09 +03:00
|
|
|
use OC\Files\View;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\Files_Sharing\SharedStorage;
|
2017-01-25 14:22:09 +03:00
|
|
|
use OCP\Files\NotFoundException;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Share\IShare;
|
2017-01-25 14:22:09 +03:00
|
|
|
|
2014-04-30 14:49:16 +04:00
|
|
|
/**
|
2016-05-17 12:42:03 +03:00
|
|
|
* Class SharedStorageTest
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
2014-04-30 14:49:16 +04:00
|
|
|
*/
|
2016-05-17 12:42:03 +03:00
|
|
|
class SharedStorageTest extends TestCase {
|
2014-04-30 14:49:16 +04:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-04-30 14:49:16 +04:00
|
|
|
parent::setUp();
|
2015-01-14 23:06:26 +03:00
|
|
|
\OCA\Files_Trashbin\Trashbin::registerHooks();
|
2014-04-30 14:49:16 +04:00
|
|
|
$this->folder = '/folder_share_storage_test';
|
|
|
|
|
|
|
|
$this->filename = '/share-api-storage.txt';
|
|
|
|
|
2014-05-26 14:37:43 +04:00
|
|
|
|
2014-04-30 14:49:16 +04:00
|
|
|
$this->view->mkdir($this->folder);
|
2014-05-26 14:37:43 +04:00
|
|
|
|
|
|
|
// save file with content
|
|
|
|
$this->view->file_put_contents($this->filename, "root file");
|
|
|
|
$this->view->file_put_contents($this->folder . $this->filename, "file in subfolder");
|
2014-04-30 14:49:16 +04:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2015-10-12 18:21:54 +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-10-12 18:21:54 +03:00
|
|
|
}
|
2014-04-30 14:49:16 +04:00
|
|
|
|
2015-01-23 17:22:06 +03:00
|
|
|
\OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
|
|
|
|
|
2014-04-30 14:49:16 +04:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2014-04-30 18:56:09 +04:00
|
|
|
/**
|
2014-08-14 19:21:52 +04:00
|
|
|
* if the parent of the mount point is gone then the mount point should move up
|
|
|
|
*
|
2014-04-30 18:56:09 +04:00
|
|
|
* @medium
|
|
|
|
*/
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testParentOfMountPointIsGone() {
|
2014-04-30 18:56:09 +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-04-30 18:56:09 +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
|
2015-10-12 18:27:26 +03:00
|
|
|
/** @var \OC\Files\Storage\Storage $storage */
|
|
|
|
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder');
|
|
|
|
$storage->rmdir($internalPath);
|
2014-04-30 18:56:09 +04:00
|
|
|
|
|
|
|
//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);
|
|
|
|
}
|
|
|
|
|
2014-04-30 14:49:16 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testRenamePartFile() {
|
2014-04-30 14:49:16 +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-04-30 14:49:16 +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 part file
|
2015-01-19 15:44:37 +03:00
|
|
|
$result = $user2View->file_put_contents($this->folder . '/foo.txt.part', 'some test data');
|
2014-04-30 14:49:16 +04:00
|
|
|
|
|
|
|
$this->assertTrue(is_int($result));
|
|
|
|
// rename part file to real file
|
2015-01-19 15:44:37 +03:00
|
|
|
$result = $user2View->rename($this->folder . '/foo.txt.part', $this->folder . '/foo.txt');
|
2014-04-30 14:49:16 +04:00
|
|
|
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
// check if the new file really exists
|
2015-01-19 15:44:37 +03:00
|
|
|
$this->assertTrue($user2View->file_exists($this->folder . '/foo.txt'));
|
2014-04-30 14:49:16 +04:00
|
|
|
|
|
|
|
// check if the rename also affected the owner
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
|
2015-01-19 15:44:37 +03:00
|
|
|
$this->assertTrue($this->view->file_exists($this->folder . '/foo.txt'));
|
2014-04-30 18:56:09 +04:00
|
|
|
|
|
|
|
//cleanup
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2014-05-26 14:37:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFilesize() {
|
|
|
|
$folderSize = $this->view->filesize($this->folder);
|
2015-01-19 15:44:37 +03:00
|
|
|
$file1Size = $this->view->filesize($this->folder . $this->filename);
|
2014-05-26 14:37:43 +04:00
|
|
|
$file2Size = $this->view->filesize($this->filename);
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share1 = $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
|
|
|
|
);
|
|
|
|
|
|
|
|
$share2 = $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-05-26 14:37:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
// compare file size between user1 and user2, should always be the same
|
|
|
|
$this->assertSame($folderSize, \OC\Files\Filesystem::filesize($this->folder));
|
|
|
|
$this->assertSame($file1Size, \OC\Files\Filesystem::filesize($this->folder . $this->filename));
|
|
|
|
$this->assertSame($file2Size, \OC\Files\Filesystem::filesize($this->filename));
|
|
|
|
|
|
|
|
//cleanup
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share1);
|
|
|
|
$this->shareManager->deleteShare($share2);
|
2014-04-30 14:49:16 +04:00
|
|
|
}
|
2014-04-30 18:56:09 +04:00
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testGetPermissions() {
|
|
|
|
$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_READ
|
|
|
|
);
|
2014-06-24 16:00:15 +04:00
|
|
|
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::is_dir($this->folder));
|
|
|
|
|
|
|
|
// for the share root we expect:
|
2017-05-15 20:43:25 +03:00
|
|
|
// the read permissions (1)
|
|
|
|
// the delete permission (8), to enable unshare
|
2014-06-24 16:00:15 +04:00
|
|
|
$rootInfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
2017-05-15 20:43:25 +03:00
|
|
|
$this->assertSame(9, $rootInfo->getPermissions());
|
2014-06-24 16:00:15 +04:00
|
|
|
|
|
|
|
// for the file within the shared folder we expect:
|
2016-12-02 19:59:02 +03:00
|
|
|
// the read permissions (1)
|
2014-06-24 16:00:15 +04:00
|
|
|
$subfileInfo = \OC\Files\Filesystem::getFileInfo($this->folder . $this->filename);
|
|
|
|
$this->assertSame(1, $subfileInfo->getPermissions());
|
|
|
|
|
|
|
|
|
|
|
|
//cleanup
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2014-06-24 16:00:15 +04:00
|
|
|
}
|
|
|
|
|
2015-03-20 13:30:51 +03:00
|
|
|
public function testFopenWithReadOnlyPermission() {
|
2015-01-30 16:19:23 +03:00
|
|
|
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
|
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_READ
|
|
|
|
);
|
2015-01-30 16:19:23 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
|
|
|
|
// part file should be forbidden
|
|
|
|
$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
|
|
|
|
$this->assertFalse($handle);
|
|
|
|
|
|
|
|
// regular file forbidden
|
|
|
|
$handle = $user2View->fopen($this->folder . '/test.txt', 'w');
|
|
|
|
$this->assertFalse($handle);
|
|
|
|
|
|
|
|
// rename forbidden
|
|
|
|
$this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
|
|
|
|
|
|
|
|
// delete forbidden
|
|
|
|
$this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
|
|
|
|
|
|
|
|
//cleanup
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2015-01-30 16:19:23 +03:00
|
|
|
}
|
|
|
|
|
2015-03-20 13:30:51 +03:00
|
|
|
public function testFopenWithCreateOnlyPermission() {
|
2015-01-30 16:19:23 +03:00
|
|
|
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
|
|
|
|
$fileinfoFolder = $this->view->getFileInfo($this->folder);
|
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_READ | \OCP\Constants::PERMISSION_CREATE
|
|
|
|
);
|
2015-01-30 16:19:23 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
|
|
|
|
// create part file allowed
|
|
|
|
$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
|
|
|
|
$this->assertNotFalse($handle);
|
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
// create regular file allowed
|
|
|
|
$handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
|
|
|
|
$this->assertNotFalse($handle);
|
|
|
|
fclose($handle);
|
|
|
|
|
2015-03-20 13:30:51 +03:00
|
|
|
// rename file never allowed
|
|
|
|
$this->assertFalse($user2View->rename($this->folder . '/test-create.txt', $this->folder . '/newtarget.txt'));
|
|
|
|
$this->assertFalse($user2View->file_exists($this->folder . '/newtarget.txt'));
|
2015-01-30 16:19:23 +03:00
|
|
|
|
2019-11-19 18:09:26 +03:00
|
|
|
// rename file not allowed if target exists
|
2015-01-30 16:19:23 +03:00
|
|
|
$this->assertFalse($user2View->rename($this->folder . '/newtarget.txt', $this->folder . '/existing.txt'));
|
|
|
|
|
|
|
|
// overwriting file not allowed
|
|
|
|
$handle = $user2View->fopen($this->folder . '/existing.txt', 'w');
|
|
|
|
$this->assertFalse($handle);
|
|
|
|
|
|
|
|
// overwrite forbidden (no update permission)
|
|
|
|
$this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
|
|
|
|
|
|
|
|
// delete forbidden
|
|
|
|
$this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2017-08-15 15:29:26 +03:00
|
|
|
$result = \OC\Share\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
2015-01-30 16:19:23 +03:00
|
|
|
self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
2015-03-20 13:30:51 +03:00
|
|
|
public function testFopenWithUpdateOnlyPermission() {
|
2015-01-30 16:19:23 +03:00
|
|
|
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
|
|
|
|
|
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_READ | \OCP\Constants::PERMISSION_UPDATE
|
|
|
|
);
|
2015-01-30 16:19:23 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
|
|
|
|
// create part file allowed
|
|
|
|
$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
|
|
|
|
$this->assertNotFalse($handle);
|
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
// create regular file not allowed
|
|
|
|
$handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
|
|
|
|
$this->assertFalse($handle);
|
|
|
|
|
|
|
|
// rename part file not allowed to non-existing file
|
|
|
|
$this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/nonexist.txt'));
|
|
|
|
|
|
|
|
// rename part file allowed to target existing file
|
|
|
|
$this->assertTrue($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
|
|
|
|
$this->assertTrue($user2View->file_exists($this->folder . '/existing.txt'));
|
|
|
|
|
2015-03-20 13:30:51 +03:00
|
|
|
// rename regular file allowed
|
|
|
|
$this->assertTrue($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing-renamed.txt'));
|
|
|
|
$this->assertTrue($user2View->file_exists($this->folder . '/existing-renamed.txt'));
|
|
|
|
|
2015-01-30 16:19:23 +03:00
|
|
|
// overwriting file directly is allowed
|
2015-03-20 13:30:51 +03:00
|
|
|
$handle = $user2View->fopen($this->folder . '/existing-renamed.txt', 'w');
|
2015-01-30 16:19:23 +03:00
|
|
|
$this->assertNotFalse($handle);
|
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
// delete forbidden
|
2015-03-20 13:30:51 +03:00
|
|
|
$this->assertFalse($user2View->unlink($this->folder . '/existing-renamed.txt'));
|
2015-01-30 16:19:23 +03:00
|
|
|
|
|
|
|
//cleanup
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2015-01-30 16:19:23 +03:00
|
|
|
}
|
|
|
|
|
2015-03-20 13:30:51 +03:00
|
|
|
public function testFopenWithDeleteOnlyPermission() {
|
2015-01-30 16:19:23 +03:00
|
|
|
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
|
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_READ | \OCP\Constants::PERMISSION_DELETE
|
|
|
|
);
|
2015-01-30 16:19:23 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
|
|
|
|
// part file should be forbidden
|
|
|
|
$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
|
|
|
|
$this->assertFalse($handle);
|
|
|
|
|
|
|
|
// regular file forbidden
|
|
|
|
$handle = $user2View->fopen($this->folder . '/test.txt', 'w');
|
|
|
|
$this->assertFalse($handle);
|
|
|
|
|
|
|
|
// rename forbidden
|
|
|
|
$this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
|
|
|
|
|
|
|
|
// delete allowed
|
|
|
|
$this->assertTrue($user2View->unlink($this->folder . '/existing.txt'));
|
|
|
|
|
|
|
|
//cleanup
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2015-01-30 16:19:23 +03:00
|
|
|
}
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
public function testMountSharesOtherUser() {
|
2014-11-04 17:16:58 +03:00
|
|
|
$rootView = new \OC\Files\View('');
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
|
|
|
|
// share 2 different files with 2 different users
|
2016-04-15 10:02:17 +03:00
|
|
|
$share1 = $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
|
|
|
|
);
|
|
|
|
$share2 = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_USER,
|
|
|
|
$this->filename,
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3,
|
|
|
|
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
|
|
|
);
|
2014-11-04 17:16:58 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
|
2015-03-27 16:57:56 +03:00
|
|
|
|
|
|
|
$mountConfigManager = \OC::$server->getMountProviderCollection();
|
|
|
|
$mounts = $mountConfigManager->getMountsForUser(\OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER3));
|
2020-03-26 11:30:18 +03:00
|
|
|
array_walk($mounts, [\OC\Files\Filesystem::getMountManager(), 'addMount']);
|
2014-11-04 17:16:58 +03:00
|
|
|
|
|
|
|
$this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename));
|
|
|
|
|
|
|
|
// make sure we didn't double setup shares for user 2 or mounted the shares for user 3 in user's 2 home
|
2015-01-19 15:44:37 +03:00
|
|
|
$this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder . ' (2)'));
|
2014-11-04 17:16:58 +03:00
|
|
|
$this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename));
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$this->view->unlink($this->folder);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
$this->shareManager->deleteShare($share1);
|
|
|
|
$this->shareManager->deleteShare($share2);
|
2014-11-04 17:16:58 +03:00
|
|
|
}
|
2015-01-19 15:44:37 +03:00
|
|
|
|
|
|
|
public function testCopyFromStorage() {
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
|
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
|
|
|
|
);
|
2015-01-19 15:44:37 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
$this->assertTrue($view->file_exists($this->folder));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OCP\Files\Storage $sharedStorage
|
|
|
|
*/
|
|
|
|
list($sharedStorage,) = $view->resolvePath($this->folder);
|
2015-01-19 18:23:33 +03:00
|
|
|
$this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage'));
|
2015-01-19 15:44:37 +03:00
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$sourceStorage = new \OC\Files\Storage\Temporary([]);
|
2015-01-19 15:44:37 +03:00
|
|
|
$sourceStorage->file_put_contents('foo.txt', 'asd');
|
|
|
|
|
|
|
|
$sharedStorage->copyFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
|
|
|
|
$this->assertTrue($sharedStorage->file_exists('bar.txt'));
|
|
|
|
$this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
|
2015-01-19 18:23:33 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$this->view->unlink($this->folder);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2015-01-19 15:44:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMoveFromStorage() {
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
|
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
|
|
|
|
);
|
2015-01-19 15:44:37 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
$this->assertTrue($view->file_exists($this->folder));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OCP\Files\Storage $sharedStorage
|
|
|
|
*/
|
|
|
|
list($sharedStorage,) = $view->resolvePath($this->folder);
|
2015-01-19 18:23:33 +03:00
|
|
|
$this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage'));
|
2015-01-19 15:44:37 +03:00
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$sourceStorage = new \OC\Files\Storage\Temporary([]);
|
2015-01-19 15:44:37 +03:00
|
|
|
$sourceStorage->file_put_contents('foo.txt', 'asd');
|
|
|
|
|
|
|
|
$sharedStorage->moveFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
|
|
|
|
$this->assertTrue($sharedStorage->file_exists('bar.txt'));
|
|
|
|
$this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
|
2015-01-19 18:23:33 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$this->view->unlink($this->folder);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->shareManager->deleteShare($share);
|
2015-01-19 15:44:37 +03:00
|
|
|
}
|
2015-08-05 16:41:03 +03:00
|
|
|
|
|
|
|
public function testNameConflict() {
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$view1 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
|
|
|
|
$view1->mkdir('foo');
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
$view3 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
|
|
|
|
$view3->mkdir('foo');
|
|
|
|
|
|
|
|
// share a folder with the same name from two different users to the same user
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share1 = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_GROUP,
|
|
|
|
'foo',
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
self::TEST_FILES_SHARING_API_GROUP1,
|
|
|
|
\OCP\Constants::PERMISSION_ALL
|
|
|
|
);
|
2019-11-19 18:09:26 +03:00
|
|
|
$this->shareManager->acceptShare($share1, self::TEST_FILES_SHARING_API_USER2);
|
2015-08-05 16:41:03 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share2 = $this->share(
|
|
|
|
\OCP\Share::SHARE_TYPE_GROUP,
|
|
|
|
'foo',
|
|
|
|
self::TEST_FILES_SHARING_API_USER3,
|
|
|
|
self::TEST_FILES_SHARING_API_GROUP1,
|
|
|
|
\OCP\Constants::PERMISSION_ALL
|
|
|
|
);
|
2019-11-19 18:09:26 +03:00
|
|
|
$this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER2);
|
2015-08-05 16:41:03 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$view2 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
|
|
|
|
$this->assertTrue($view2->file_exists('/foo'));
|
|
|
|
$this->assertTrue($view2->file_exists('/foo (2)'));
|
|
|
|
|
|
|
|
$mount = $view2->getMount('/foo');
|
|
|
|
$this->assertInstanceOf('\OCA\Files_Sharing\SharedMount', $mount);
|
2016-06-01 15:29:31 +03:00
|
|
|
/** @var \OCA\Files_Sharing\SharedStorage $storage */
|
2015-08-05 16:41:03 +03:00
|
|
|
$storage = $mount->getStorage();
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $storage->getOwner(''));
|
|
|
|
|
|
|
|
$this->shareManager->deleteShare($share1);
|
|
|
|
$this->shareManager->deleteShare($share2);
|
2015-08-05 16:41:03 +03:00
|
|
|
}
|
2016-12-14 16:35:45 +03:00
|
|
|
|
|
|
|
public function testOwnerPermissions() {
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
|
|
|
|
$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 - \OCP\Constants::PERMISSION_DELETE
|
|
|
|
);
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
$this->assertTrue($view->file_exists($this->folder));
|
|
|
|
|
|
|
|
$view->file_put_contents($this->folder . '/newfile.txt', 'asd');
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
|
|
|
|
$this->assertTrue($this->view->file_exists($this->folder . '/newfile.txt'));
|
|
|
|
$this->assertEquals(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
|
|
|
|
$this->view->getFileInfo($this->folder . '/newfile.txt')->getPermissions());
|
|
|
|
|
|
|
|
$this->view->unlink($this->folder);
|
|
|
|
$this->shareManager->deleteShare($share);
|
|
|
|
|
|
|
|
}
|
2017-01-25 14:22:09 +03:00
|
|
|
|
|
|
|
public function testInitWithNonExistingUser() {
|
|
|
|
$share = $this->createMock(IShare::class);
|
|
|
|
$share->method('getShareOwner')->willReturn('unexist');
|
|
|
|
$ownerView = $this->createMock(View::class);
|
|
|
|
$storage = new SharedStorage([
|
|
|
|
'ownerView' => $ownerView,
|
|
|
|
'superShare' => $share,
|
|
|
|
'groupedShares' => [$share],
|
|
|
|
'user' => 'user1',
|
|
|
|
]);
|
|
|
|
|
|
|
|
// trigger init
|
|
|
|
$this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
|
2017-03-23 17:01:23 +03:00
|
|
|
$this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
|
2017-01-25 14:22:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInitWithNotFoundSource() {
|
|
|
|
$share = $this->createMock(IShare::class);
|
|
|
|
$share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$ownerView = $this->createMock(View::class);
|
|
|
|
$ownerView->method('getPath')->will($this->throwException(new NotFoundException()));
|
|
|
|
$storage = new SharedStorage([
|
|
|
|
'ownerView' => $ownerView,
|
|
|
|
'superShare' => $share,
|
|
|
|
'groupedShares' => [$share],
|
|
|
|
'user' => 'user1',
|
|
|
|
]);
|
|
|
|
|
|
|
|
// trigger init
|
|
|
|
$this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
|
2017-03-23 17:01:23 +03:00
|
|
|
$this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
|
2017-01-25 14:22:09 +03:00
|
|
|
}
|
2014-04-30 14:49:16 +04:00
|
|
|
}
|