]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix check if a file is excluded from encryption or not
authorBjoern Schiessle <schiessle@owncloud.com>
Fri, 27 Mar 2015 10:46:07 +0000 (11:46 +0100)
committerBjoern Schiessle <schiessle@owncloud.com>
Fri, 27 Mar 2015 10:51:50 +0000 (11:51 +0100)
lib/private/encryption/util.php
lib/private/files/storage/wrapper/encryption.php
tests/lib/encryption/utiltest.php

index 2c6ff266841fccee32a2653486a23cf20f789dd3..85e852ec2c9ee89ee99e8622d17091b99772ab0b 100644 (file)
@@ -389,9 +389,22 @@ class Util {
         * @return boolean
         */
        public function isExcluded($path) {
-               $root = explode('/', $path, 2);
-               if (isset($root[0])) {
-                       if (in_array($root[0], $this->excludedPaths)) {
+               $normalizedPath = \OC\Files\Filesystem::normalizePath($path);
+               $root = explode('/', $normalizedPath, 4);
+               if (count($root) > 2) {
+
+                       //detect system wide folders
+                       if (in_array($root[1], $this->excludedPaths)) {
+                               return true;
+                       }
+
+                       $v1 = $this->userManager->userExists($root[1]);
+                       $v2 = in_array($root[2], $this->excludedPaths);
+
+                       // detect user specific folders
+                       if ($this->userManager->userExists($root[1])
+                               && in_array($root[2], $this->excludedPaths)) {
+
                                return true;
                        }
                }
index 44fc2124f7a1828db6e60761666ce814eb3bc38f..0e70c99c8d73d3649357e87297c3578e7b4df981 100644 (file)
@@ -254,7 +254,7 @@ class Encryption extends Wrapper {
                                '" not found, file will be stored unencrypted');
                }
 
-               if($shouldEncrypt === true && !$this->util->isExcluded($path) && $encryptionModule !== null) {
+               if($shouldEncrypt === true && !$this->util->isExcluded($fullPath) && $encryptionModule !== null) {
                        $source = $this->storage->fopen($path, $mode);
                        $handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header,
                                $this->uid, $encryptionModule, $this->storage, $this, $this->util, $mode,
index 00a9ab9c578745f286fe929d13a133b5cb6d5c40..672f9ff5e9786464fc8519f6855ab60f54d05dfa 100644 (file)
@@ -98,4 +98,39 @@ class UtilTest extends TestCase {
                $u->createHeader($header, $em);
        }
 
+       /**
+        * @dataProvider providePathsForTestIsExcluded
+        */
+       public function testIsEcluded($path, $expected) {
+               $this->userManager
+                       ->expects($this->any())
+                       ->method('userExists')
+                       ->will($this->returnCallback(array($this, 'isExcludedCallback')));
+
+               $u = new Util($this->view, $this->userManager);
+
+               $this->assertSame($expected,
+                       $u->isExcluded($path)
+               );
+       }
+
+       public function providePathsForTestIsExcluded() {
+               return array(
+                       array('files_encryption/foo.txt', true),
+                       array('test/foo.txt', false),
+                       array('/user1/files_encryption/foo.txt', true),
+                       array('/user1/files/foo.txt', false),
+
+               );
+       }
+
+       public function isExcludedCallback() {
+               $args = func_get_args();
+               if ($args[0] === 'user1') {
+                       return true;
+               }
+
+               return false;
+       }
+
 }