2014-02-20 14:21:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 16:13:36 +00:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2014-02-20 14:21:53 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* @license AGPL-3.0
|
2014-02-20 14:21:53 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00: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-02-20 14:21:53 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-02-20 14:21:53 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 10:44:34 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-02-20 14:21:53 +00:00
|
|
|
*
|
2015-03-26 10:44:34 +00: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-02-20 14:21:53 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2016-05-17 09:42:03 +00:00
|
|
|
namespace OCA\Files_Sharing\Tests;
|
2015-02-26 10:37:37 +00:00
|
|
|
|
|
|
|
/**
|
2016-05-17 09:42:03 +00:00
|
|
|
* Class UpdaterTest
|
2015-11-03 00:52:41 +00:00
|
|
|
*
|
|
|
|
* @group DB
|
2015-02-26 10:37:37 +00:00
|
|
|
*/
|
2016-05-17 09:42:03 +00:00
|
|
|
class UpdaterTest extends TestCase {
|
2014-04-30 14:56:09 +00:00
|
|
|
|
2014-06-25 13:20:52 +00:00
|
|
|
const TEST_FOLDER_NAME = '/folder_share_updater_test';
|
|
|
|
|
|
|
|
public static function setUpBeforeClass() {
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
\OCA\Files_Sharing\Helper::registerHooks();
|
|
|
|
}
|
2014-02-20 14:21:53 +00:00
|
|
|
|
2014-11-10 21:28:12 +00:00
|
|
|
protected function setUp() {
|
2014-04-30 14:56:09 +00:00
|
|
|
parent::setUp();
|
2014-02-27 12:27:24 +00:00
|
|
|
|
2014-04-30 14:56:09 +00:00
|
|
|
$this->folder = self::TEST_FOLDER_NAME;
|
2014-03-25 19:18:58 +00:00
|
|
|
|
2014-06-25 13:20:52 +00:00
|
|
|
$this->filename = '/share-updater-test.txt';
|
2014-04-30 14:56:09 +00:00
|
|
|
|
|
|
|
// save file with content
|
|
|
|
$this->view->file_put_contents($this->filename, $this->data);
|
|
|
|
$this->view->mkdir($this->folder);
|
|
|
|
$this->view->file_put_contents($this->folder . '/' . $this->filename, $this->data);
|
2014-02-20 14:21:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 21:28:12 +00:00
|
|
|
protected function tearDown() {
|
2015-12-02 13:49:27 +00:00
|
|
|
if ($this->view) {
|
|
|
|
$this->view->unlink($this->filename);
|
|
|
|
$this->view->deleteAll($this->folder);
|
|
|
|
}
|
2014-04-30 14:56:09 +00:00
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test deletion of a folder which contains share mount points. Share mount
|
2014-07-02 12:40:22 +00:00
|
|
|
* points should be unshared before the folder gets deleted so
|
2014-04-30 14:56:09 +00:00
|
|
|
* that the mount point doesn't end up at the trash bin
|
|
|
|
*/
|
2017-07-24 05:44:09 +00:00
|
|
|
public function testDeleteParentFolder() {
|
2017-10-23 21:31:17 +00:00
|
|
|
$status = \OC::$server->getAppManager()->isEnabledForUser('files_trashbin');
|
2016-10-27 18:13:15 +00:00
|
|
|
(new \OC_App())->enable('files_trashbin');
|
|
|
|
|
2014-04-30 14:56:09 +00:00
|
|
|
|
|
|
|
\OCA\Files_Trashbin\Trashbin::registerHooks();
|
|
|
|
|
|
|
|
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
|
|
|
$this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);
|
|
|
|
|
2016-04-15 07:02:17 +00:00
|
|
|
$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:56:09 +00:00
|
|
|
|
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
|
|
|
|
// check if user2 can see the shared folder
|
|
|
|
$this->assertTrue($view->file_exists($this->folder));
|
|
|
|
|
2017-08-15 12:29:26 +00:00
|
|
|
$foldersShared = \OC\Share\Share::getItemsSharedWith('folder');
|
2014-07-02 12:40:22 +00:00
|
|
|
$this->assertSame(1, count($foldersShared));
|
|
|
|
|
2017-07-24 05:44:09 +00:00
|
|
|
$view->mkdir('localFolder');
|
|
|
|
$view->file_put_contents('localFolder/localFile.txt', 'local file');
|
2014-04-30 14:56:09 +00:00
|
|
|
|
|
|
|
$view->rename($this->folder, 'localFolder/' . $this->folder);
|
|
|
|
|
|
|
|
// share mount point should now be moved to the subfolder
|
|
|
|
$this->assertFalse($view->file_exists($this->folder));
|
|
|
|
$this->assertTrue($view->file_exists('localFolder/' .$this->folder));
|
|
|
|
|
|
|
|
$view->unlink('localFolder');
|
|
|
|
|
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
2014-07-02 12:40:22 +00:00
|
|
|
// shared folder should be unshared
|
2017-08-15 12:29:26 +00:00
|
|
|
$foldersShared = \OC\Share\Share::getItemsSharedWith('folder');
|
2014-07-02 12:40:22 +00:00
|
|
|
$this->assertTrue(empty($foldersShared));
|
2014-04-30 14:56:09 +00:00
|
|
|
|
|
|
|
// trashbin should contain the local file but not the mount point
|
|
|
|
$rootView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
|
2015-01-14 20:06:26 +00:00
|
|
|
$trashContent = \OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->assertSame(1, count($trashContent));
|
|
|
|
$firstElement = reset($trashContent);
|
|
|
|
$timestamp = $firstElement['mtime'];
|
|
|
|
$this->assertTrue($rootView->file_exists('files_trashbin/files/localFolder.d' . $timestamp . '/localFile.txt'));
|
|
|
|
$this->assertFalse($rootView->file_exists('files_trashbin/files/localFolder.d' . $timestamp . '/' . $this->folder));
|
2014-04-30 14:56:09 +00:00
|
|
|
|
|
|
|
//cleanup
|
|
|
|
$rootView->deleteAll('files_trashin');
|
|
|
|
|
|
|
|
if ($status === false) {
|
2018-02-13 07:03:06 +00:00
|
|
|
\OC::$server->getAppManager()->disableApp('files_trashbin');
|
2014-04-30 14:56:09 +00:00
|
|
|
}
|
2015-01-23 14:22:06 +00:00
|
|
|
|
|
|
|
\OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
|
2014-06-24 15:04:27 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 14:32:05 +00:00
|
|
|
public function shareFolderProvider() {
|
|
|
|
return [
|
|
|
|
['/'],
|
|
|
|
['/my_shares'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2014-06-24 15:04:27 +00:00
|
|
|
/**
|
|
|
|
* if a file gets shared the etag for the recipients root should change
|
2015-06-26 14:32:05 +00:00
|
|
|
*
|
|
|
|
* @dataProvider shareFolderProvider
|
|
|
|
*
|
|
|
|
* @param string $shareFolder share folder to use
|
2014-06-24 15:04:27 +00:00
|
|
|
*/
|
2015-06-26 14:32:05 +00:00
|
|
|
public function testShareFile($shareFolder) {
|
|
|
|
$config = \OC::$server->getConfig();
|
|
|
|
$oldShareFolder = $config->getSystemValue('share_folder');
|
|
|
|
$config->setSystemValue('share_folder', $shareFolder);
|
|
|
|
|
2014-06-24 15:04:27 +00:00
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
2015-06-26 14:32:05 +00:00
|
|
|
$beforeShareRoot = \OC\Files\Filesystem::getFileInfo('');
|
|
|
|
$etagBeforeShareRoot = $beforeShareRoot->getEtag();
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::mkdir($shareFolder);
|
|
|
|
|
|
|
|
$beforeShareDir = \OC\Files\Filesystem::getFileInfo($shareFolder);
|
|
|
|
$etagBeforeShareDir = $beforeShareDir->getEtag();
|
2014-06-24 15:04:27 +00:00
|
|
|
|
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2016-04-15 07:02:17 +00: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-06-24 15:04:27 +00:00
|
|
|
|
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
2015-06-26 14:32:05 +00:00
|
|
|
$afterShareRoot = \OC\Files\Filesystem::getFileInfo('');
|
|
|
|
$etagAfterShareRoot = $afterShareRoot->getEtag();
|
|
|
|
|
|
|
|
$afterShareDir = \OC\Files\Filesystem::getFileInfo($shareFolder);
|
|
|
|
$etagAfterShareDir = $afterShareDir->getEtag();
|
2014-06-24 15:04:27 +00:00
|
|
|
|
2015-06-26 14:32:05 +00:00
|
|
|
$this->assertTrue(is_string($etagBeforeShareRoot));
|
|
|
|
$this->assertTrue(is_string($etagBeforeShareDir));
|
|
|
|
$this->assertTrue(is_string($etagAfterShareRoot));
|
|
|
|
$this->assertTrue(is_string($etagAfterShareDir));
|
|
|
|
$this->assertTrue($etagBeforeShareRoot !== $etagAfterShareRoot);
|
|
|
|
$this->assertTrue($etagBeforeShareDir !== $etagAfterShareDir);
|
2014-06-24 15:04:27 +00:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2016-04-15 07:02:17 +00:00
|
|
|
$this->shareManager->deleteShare($share);
|
2015-06-26 14:32:05 +00:00
|
|
|
|
|
|
|
$config->setSystemValue('share_folder', $oldShareFolder);
|
2014-06-24 15:04:27 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 13:35:15 +00:00
|
|
|
/**
|
|
|
|
* if a folder gets renamed all children mount points should be renamed too
|
|
|
|
*/
|
2017-07-24 05:44:09 +00:00
|
|
|
public function testRename() {
|
2014-07-02 13:35:15 +00:00
|
|
|
|
|
|
|
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
2016-04-15 07:02:17 +00: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-07-02 13:35:15 +00:00
|
|
|
|
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
// make sure that the shared folder exists
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::mkdir('oldTarget');
|
|
|
|
\OC\Files\Filesystem::mkdir('oldTarget/subfolder');
|
|
|
|
\OC\Files\Filesystem::mkdir('newTarget');
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
|
|
|
|
|
|
|
|
// re-login to make sure that the new mount points are initialized
|
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
|
|
|
|
|
|
|
|
// re-login to make sure that the new mount points are initialized
|
|
|
|
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
|
|
|
|
|
|
|
|
// cleanup
|
2016-04-15 07:02:17 +00:00
|
|
|
$this->shareManager->deleteShare($share);
|
2014-07-02 13:35:15 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 14:21:53 +00:00
|
|
|
}
|