]> source.dussan.org Git - nextcloud-server.git/commitdiff
we also encrypt/decrypt files in the versions folder for previews and if encryption...
authorBjoern Schiessle <schiessle@owncloud.com>
Thu, 2 Oct 2014 10:55:46 +0000 (12:55 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Mon, 6 Oct 2014 10:02:08 +0000 (12:02 +0200)
apps/files_encryption/lib/proxy.php
apps/files_encryption/tests/proxy.php

index b406404a688678a2950781f77a6b50677f2ce709..3b9dcbe77675952a14b5417af8a3bbfa9ed81041 100644 (file)
@@ -49,12 +49,17 @@ class Proxy extends \OC_FileProxy {
         * @param string $uid user
         * @return boolean
         */
-       private function isExcludedPath($path, $uid) {
+       protected function isExcludedPath($path, $uid) {
 
                $view = new \OC\Files\View();
 
-               // files outside of the files-folder are excluded
-               if(strpos($path, '/' . $uid . '/files/') !== 0) {
+               $path = \OC\Files\Filesystem::normalizePath($path);
+
+               // we only encrypt/decrypt files in the files and files_versions folder
+               if(
+                       strpos($path, '/' . $uid . '/files/') !== 0 &&
+                       strpos($path, '/' . $uid . '/files_versions/') !== 0) {
+
                        return true;
                }
 
index 9ec1f940edd9685ef5c251422b9de855d5947178..42637a52e041849720ca8b22d3726eda7a5c90d5 100644 (file)
@@ -136,4 +136,42 @@ class Test_Encryption_Proxy extends \PHPUnit_Framework_TestCase {
 
        }
 
+       /**
+        * @dataProvider isExcludedPathProvider
+        */
+       function testIsExcludedPath($path, $expected) {
+               $this->view->mkdir(dirname($path));
+               $this->view->file_put_contents($path, "test");
+
+               $testClass = new DummyProxy();
+
+               $result = $testClass->isExcludedPathTesting($path, $this->userId);
+               $this->assertSame($expected, $result);
+
+               $this->view->deleteAll(dirname($path));
+
+       }
+
+       public function isExcludedPathProvider() {
+               return array(
+                       array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files/test.txt', false),
+                       array (\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files/test.txt', false),
+                       array ('/files/test.txt', true),
+                       array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files/versions/test.txt', false),
+                       array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files_versions/test.txt', false),
+                       array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/files_trashbin/test.txt', true),
+                       array ('/' . \Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1 . '/file/test.txt', true),
+               );
+       }
+
+}
+
+
+/**
+ * Dummy class to make protected methods available for testing
+ */
+class DummyProxy extends \OCA\Encryption\Proxy {
+       public function isExcludedPathTesting($path, $uid) {
+               return $this->isExcludedPath($path, $uid);
+       }
 }