2014-05-27 23:51:23 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2014-05-27 23:51:23 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Test_Files_Sharing_Api
|
|
|
|
*/
|
2014-10-30 19:20:40 +03:00
|
|
|
class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
2014-05-27 23:51:23 +04:00
|
|
|
|
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
|
|
|
|
$this->view->file_put_contents($this->filename, "root file");
|
|
|
|
$this->view->file_put_contents($this->folder . $this->filename, "file in subfolder");
|
|
|
|
}
|
|
|
|
|
2014-11-11 00:28:12 +03:00
|
|
|
protected function tearDown() {
|
2014-05-27 23:51:23 +04:00
|
|
|
$this->view->unlink($this->folder);
|
|
|
|
$this->view->unlink($this->filename);
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test if the mount point moves up if the parent folder no longer exists
|
|
|
|
*/
|
|
|
|
function testShareMountLoseParentFolder() {
|
|
|
|
|
|
|
|
// share to user
|
|
|
|
$fileinfo = $this->view->getFileInfo($this->folder);
|
|
|
|
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
|
|
|
self::TEST_FILES_SHARING_API_USER2, 31);
|
|
|
|
|
|
|
|
$statement = "UPDATE `*PREFIX*share` SET `file_target` = ? where `share_with` = ?";
|
|
|
|
$query = \OC_DB::prepare($statement);
|
|
|
|
$arguments = array('/foo/bar' . $this->folder, self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$query->execute($arguments);
|
|
|
|
|
|
|
|
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
|
|
|
|
$result = $query->execute();
|
|
|
|
|
|
|
|
$shares = $result->fetchAll();
|
|
|
|
|
|
|
|
$this->assertSame(1, count($shares));
|
|
|
|
|
|
|
|
$share = reset($shares);
|
|
|
|
$this->assertSame('/foo/bar' . $this->folder, $share['file_target']);
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
// share should have moved up
|
|
|
|
|
|
|
|
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
|
|
|
|
$result = $query->execute();
|
|
|
|
|
|
|
|
$shares = $result->fetchAll();
|
|
|
|
|
|
|
|
$this->assertSame(1, count($shares));
|
|
|
|
|
|
|
|
$share = reset($shares);
|
|
|
|
$this->assertSame($this->folder, $share['file_target']);
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$this->view->unlink($this->folder);
|
|
|
|
}
|
|
|
|
|
2014-06-03 21:29:00 +04:00
|
|
|
/**
|
2014-05-27 23:51:23 +04:00
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
function testDeleteParentOfMountPoint() {
|
|
|
|
|
|
|
|
// share to user
|
|
|
|
$fileinfo = $this->view->getFileInfo($this->folder);
|
|
|
|
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
|
|
|
self::TEST_FILES_SHARING_API_USER2, 31);
|
|
|
|
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-06-03 21:29:00 +04:00
|
|
|
function testMoveSharedFile() {
|
|
|
|
$fileinfo = $this->view->getFileInfo($this->filename);
|
|
|
|
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
|
|
|
self::TEST_FILES_SHARING_API_USER2, 31);
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::rename($this->filename, "newFileName");
|
|
|
|
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists('newFileName'));
|
|
|
|
$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));
|
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName"));
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* share file with a group if a user renames the file the filename should not change
|
|
|
|
* for the other users
|
|
|
|
*/
|
|
|
|
function testMoveGroupShare () {
|
|
|
|
\OC_Group::createGroup('testGroup');
|
|
|
|
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
|
|
|
|
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
|
|
|
|
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
|
|
|
|
|
|
|
|
$fileinfo = $this->view->getFileInfo($this->filename);
|
|
|
|
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
|
|
|
|
"testGroup", 31);
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::rename($this->filename, "newFileName");
|
|
|
|
|
|
|
|
$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));
|
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName"));
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
|
|
|
$this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName"));
|
|
|
|
|
|
|
|
//cleanup
|
2015-01-14 23:06:26 +03:00
|
|
|
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
2014-06-03 21:29:00 +04:00
|
|
|
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
|
|
|
|
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
|
|
|
|
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
|
|
|
|
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
|
|
|
|
}
|
|
|
|
|
2014-09-29 13:13:01 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider dataProviderTestStripUserFilesPath
|
|
|
|
* @param string $path
|
|
|
|
* @param string $expectedResult
|
|
|
|
* @param bool $exception if a exception is expected
|
|
|
|
*/
|
|
|
|
function testStripUserFilesPath($path, $expectedResult, $exception) {
|
|
|
|
$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 {
|
|
|
|
$this->assertTrue(false, "Exception catched, but expected: " . $expectedResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dataProviderTestStripUserFilesPath() {
|
|
|
|
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),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|