[Pkg-owncloud-commits] [owncloud] 17/123: Validate the quota value to be a correct value

David Prévot taffit at moszumanska.debian.org
Tue May 19 23:55:08 UTC 2015


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

taffit pushed a commit to branch stable8
in repository owncloud.

commit 15d134124bde5fa8693c640a3db000a9bc47d51f
Author: Thomas Müller <thomas.mueller at tmit.eu>
Date:   Thu May 7 17:56:13 2015 +0200

    Validate the quota value to be a correct value
---
 apps/provisioning_api/lib/users.php       |  9 ++++++++-
 apps/provisioning_api/tests/userstest.php | 30 +++++++++++++++++++++++-------
 lib/private/helper.php                    |  2 ++
 tests/lib/helper.php                      | 19 ++++++++++---------
 4 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/apps/provisioning_api/lib/users.php b/apps/provisioning_api/lib/users.php
index 505a141..43cf22b 100644
--- a/apps/provisioning_api/lib/users.php
+++ b/apps/provisioning_api/lib/users.php
@@ -155,7 +155,14 @@ class Users {
 			case 'quota':
 				$quota = $parameters['_put']['value'];
 				if($quota !== 'none' and $quota !== 'default') {
-					$quota = OC_Helper::computerFileSize($quota);
+					if (is_numeric($quota)) {
+						$quota = floatval($quota);
+					} else {
+						$quota = OC_Helper::computerFileSize($quota);
+					}
+					if ($quota === false) {
+						return new OC_OCS_Result(null, 103, "Invalid quota value {$parameters['_put']['value']}");
+					}
 					if($quota == 0) {
 						$quota = 'default';
 					}else if($quota == -1){
diff --git a/apps/provisioning_api/tests/userstest.php b/apps/provisioning_api/tests/userstest.php
index b7e83a3..c6a6133 100644
--- a/apps/provisioning_api/tests/userstest.php
+++ b/apps/provisioning_api/tests/userstest.php
@@ -187,20 +187,36 @@ class UsersTest extends TestCase {
 
 	}
 
-	public function testEditOwnQuota() {
+	/**
+	 * @dataProvider providesQuotas
+	 * @param $expected
+	 * @param $quota
+	 */
+	public function testEditOwnQuota($expected, $quota) {
 		$user = $this->generateUsers();
+		\OC_Group::addToGroup($user, 'admin');
 		\OC_User::setUserId($user);
 		$result = \OCA\provisioning_API\Users::editUser(
-			array(
+			[
 				'userid' => $user,
-				'_put' => array(
+				'_put' => [
 					'key' => 'quota',
-					'value' => '20G',
-					),
-				)
+					'value' => $quota,
+				],
+			]
 			);
 		$this->assertInstanceOf('OC_OCS_Result', $result);
-		$this->assertFalse($result->succeeded());
+		$this->assertEquals($expected, $result->succeeded());
+	}
+
+	public function providesQuotas() {
+		return [
+			[true, '20G'],
+			[true, '1234567'],
+			[true, 'none'],
+			[true, 'default'],
+			[false, 'qwertzu'],
+		];
 	}
 
 	public function testAdminEditOwnQuota() {
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 144ccbf..ec79881 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -413,6 +413,8 @@ class OC_Helper {
 
 		if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) {
 			$bytes *= $bytes_array[$matches[1]];
+		} else {
+			return false;
 		}
 
 		$bytes = round($bytes);
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index ed15a67..b7aa185 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -53,21 +53,22 @@ class Test_Helper extends \Test\TestCase {
 	}
 
 	/**
-	 * @dataProvider computerFileSizeProvider
+	 * @dataProvider providesComputerFileSize
 	 */
 	function testComputerFileSize($expected, $input) {
 		$result = OC_Helper::computerFileSize($input);
 		$this->assertEquals($expected, $result);
 	}
 
-	function computerFileSizeProvider(){
-		return array(
-			array(0.0, "0 B"),
-			array(1024.0, "1 kB"),
-			array(1395864371.0, '1.3 GB'),
-			array(9961472.0, "9.5 MB"),
-			array(500041567437.0, "465.7 GB"),
-		);
+	function providesComputerFileSize(){
+		return [
+			[0.0, "0 B"],
+			[1024.0, "1 kB"],
+			[1395864371.0, '1.3 GB'],
+			[9961472.0, "9.5 MB"],
+			[500041567437.0, "465.7 GB"],
+			[false, "12 GB etfrhzui"]
+		];
 	}
 
 	function testGetMimeType() {

-- 
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