summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-04-15 11:19:31 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-04-23 12:54:26 +0200
commit652d417a585ede1564456c446577aa1752253ccd (patch)
tree068b69d1996342739e1ccba556d83eed48195fb8 /apps/files_sharing
parentb712393e72fc22dc9d38f074b2eca848e6439bcf (diff)
downloadnextcloud-server-652d417a585ede1564456c446577aa1752253ccd.tar.gz
nextcloud-server-652d417a585ede1564456c446577aa1752253ccd.zip
we don't allow to share a folder if it contains a share mount point
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/cache.php7
-rw-r--r--apps/files_sharing/lib/sharedstorage.php5
-rw-r--r--apps/files_sharing/tests/api.php60
-rw-r--r--apps/files_sharing/tests/cache.php6
4 files changed, 72 insertions, 6 deletions
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php
index 7e44847e404..3d9fbcf4de9 100644
--- a/apps/files_sharing/lib/cache.php
+++ b/apps/files_sharing/lib/cache.php
@@ -411,7 +411,7 @@ class Shared_Cache extends Cache {
}
/**
- * get the path of a file on this storage by it's id
+ * get the path of a file on this storage relative to the mount point by it's id
*
* @param int $id
* @param string $pathEnd (optional) used internally for recursive calls
@@ -419,8 +419,9 @@ class Shared_Cache extends Cache {
*/
public function getPathById($id, $pathEnd = '') {
// direct shares are easy
- if ($path = $this->getShareById($id)) {
- return $path . $pathEnd;
+ $path = $this->getShareById($id);
+ if (is_string($path)) {
+ return ltrim($pathEnd, '/');
} else {
// if the item is a direct share we try and get the path of the parent and append the name of the item to it
list($parent, $name) = $this->getParentInfo($id);
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 25e6c0abd28..eedd279bf2b 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -347,6 +347,7 @@ class Shared extends \OC\Files\Storage\Common {
$mountManager->addMount($mount);
$mountManager->removeMount($sourcePath . '/');
$this->setUniqueName();
+ $this->setMountPoint($relTargetPath);
} else {
\OCP\Util::writeLog('file sharing',
@@ -500,6 +501,10 @@ class Shared extends \OC\Files\Storage\Common {
return $this->share['share_type'];
}
+ private function setMountPoint($path) {
+ $this->share['file_target'] = $path;
+ }
+
/**
* @brief does the group share already has a user specific unique name
* @return bool
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php
index 6354d1099bb..5975eb95882 100644
--- a/apps/files_sharing/tests/api.php
+++ b/apps/files_sharing/tests/api.php
@@ -866,6 +866,66 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
$this->assertTrue($result3->succeeded());
+ // cleanup
+ \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
+
+ $result = \OCP\Share::unshare('folder', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+
+ $this->assertTrue($result);
+
+
+
+ }
+
+ /**
+ * @brief share a folder which contains a share mount point, should be forbidden
+ */
+ public function testShareFolderWithAMountPoint() {
+ // user 1 shares a folder with user2
+ \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
+
+ $fileInfo = $this->view->getFileInfo($this->folder);
+
+ $result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
+
+ $this->assertTrue($result);
+
+ // user2 shares a file from the folder as link
+ \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
+
+ $view = new \OC\Files\View('/' . \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 . '/files');
+ $view->mkdir("localDir");
+
+ // move mount point to the folder "localDir"
+ $result = $view->rename($this->folder, 'localDir/'.$this->folder);
+ $this->assertTrue($result !== false);
+
+ // try to share "localDir"
+ $fileInfo2 = $view->getFileInfo('localDir');
+
+ $this->assertTrue($fileInfo2 instanceof \OC\Files\FileInfo);
+
+ try {
+ $result2 = \OCP\Share::shareItem('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER3, 31);
+ } catch (\Exception $e) {
+ $result2 = false;
+ }
+
+ $this->assertFalse($result2);
+
+ //cleanup
+
+ $result = $view->rename('localDir/' . $this->folder, $this->folder);
+ $this->assertTrue($result !== false);
+ $view->unlink('localDir');
+
+ \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
+
+ \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
+ \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
}
}
diff --git a/apps/files_sharing/tests/cache.php b/apps/files_sharing/tests/cache.php
index 7a52f403d8e..b8ebeab3c39 100644
--- a/apps/files_sharing/tests/cache.php
+++ b/apps/files_sharing/tests/cache.php
@@ -255,7 +255,7 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
*/
$sharedCache = $sharedStorage->getCache();
- $this->assertEquals('test.txt', $sharedCache->getPathById($info->getId()));
+ $this->assertEquals('', $sharedCache->getPathById($info->getId()));
}
public function testGetPathByIdShareSubFolder() {
@@ -276,7 +276,7 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
*/
$sharedCache = $sharedStorage->getCache();
- $this->assertEquals('foo', $sharedCache->getPathById($folderInfo->getId()));
- $this->assertEquals('foo/bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
+ $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
+ $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
}
}