[Pkg-owncloud-commits] [owncloud] 170/258: throw a exception if we can't handle the provided path

David Prévot taffit at moszumanska.debian.org
Sat Oct 11 17:22:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit bb703006da0ac60abefaedbaf3b61245cc07d4c4
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Mon Sep 29 11:13:01 2014 +0200

    throw a exception if we can't handle the provided path
---
 apps/files_sharing/appinfo/app.php       |  3 +++
 apps/files_sharing/lib/exceptions.php    | 32 +++++++++++++++++++++++++++
 apps/files_sharing/lib/sharedmount.php   |  6 +++---
 apps/files_sharing/tests/sharedmount.php | 37 ++++++++++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index b22c553..ec42952 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -12,6 +12,9 @@ OC::$CLASSPATH['OCA\Files\Share\Api'] = 'files_sharing/lib/api.php';
 OC::$CLASSPATH['OCA\Files\Share\Maintainer'] = 'files_sharing/lib/maintainer.php';
 OC::$CLASSPATH['OCA\Files\Share\Proxy'] = 'files_sharing/lib/proxy.php';
 
+// Exceptions
+OC::$CLASSPATH['OCA\Files_Sharing\Exceptions\BrokenPath'] = 'files_sharing/lib/exceptions.php';
+
 \OCP\App::registerAdmin('files_sharing', 'settings-admin');
 
 \OCA\Files_Sharing\Helper::registerHooks();
diff --git a/apps/files_sharing/lib/exceptions.php b/apps/files_sharing/lib/exceptions.php
new file mode 100644
index 0000000..2a57a69
--- /dev/null
+++ b/apps/files_sharing/lib/exceptions.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2014 Bjoern Schiessle <schiessle at owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Exceptions;
+
+/**
+ * Expected path with a different root
+ * Possible Error Codes:
+ * 10 - Path not relative to data/ and point to the users file directory
+
+ */
+class BrokenPath extends \Exception {
+}
diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php
index 1717a4b..4ad2d4e 100644
--- a/apps/files_sharing/lib/sharedmount.php
+++ b/apps/files_sharing/lib/sharedmount.php
@@ -91,7 +91,7 @@ class SharedMount extends Mount implements MoveableMount {
 	 * @param string $path the absolute path
 	 * @return string e.g. turns '/admin/files/test.txt' into '/test.txt'
 	 */
-	private function stripUserFilesPath($path) {
+	protected function stripUserFilesPath($path) {
 		$trimmed = ltrim($path, '/');
 		$split = explode('/', $trimmed);
 
@@ -99,8 +99,8 @@ class SharedMount extends Mount implements MoveableMount {
 		if (count($split) < 3 || $split[1] !== 'files') {
 			\OCP\Util::writeLog('file sharing',
 				'Can not strip userid and "files/" from path: ' . $path,
-				\OCP\Util::DEBUG);
-			return false;
+				\OCP\Util::ERROR);
+			throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10);
 		}
 
 		// skip 'user' and 'files'
diff --git a/apps/files_sharing/tests/sharedmount.php b/apps/files_sharing/tests/sharedmount.php
index f8c6573..ac91094 100644
--- a/apps/files_sharing/tests/sharedmount.php
+++ b/apps/files_sharing/tests/sharedmount.php
@@ -194,4 +194,41 @@ class Test_Files_Sharing_Mount extends Test_Files_Sharing_Base {
 		\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
 	}
 
+	/**
+	 * @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 {
+	public function stripUserFilesPathDummy($path) {
+		return $this->stripUserFilesPath($path);
+	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list