]> source.dussan.org Git - nextcloud-server.git/commitdiff
tests added
authorBjoern Schiessle <schiessle@owncloud.com>
Thu, 19 Dec 2013 10:15:59 +0000 (11:15 +0100)
committerBjoern Schiessle <schiessle@owncloud.com>
Thu, 19 Dec 2013 18:43:57 +0000 (19:43 +0100)
apps/files_encryption/lib/helper.php
apps/files_encryption/tests/helper.php
apps/files_encryption/tests/util.php

index f176c7714fd3908685a21e32dbdd2771c3d77008..08941077258adb896ae226d860eb69edd6b7f58f 100755 (executable)
@@ -274,7 +274,7 @@ class Helper {
                $split = explode('/', $trimmed);
 
                // it is not a file relative to data/user/files
-               if (count($split) < 2 || $split[1] !== 'files' || $split[1] !== 'cache') {
+               if (count($split) < 2 || ($split[1] !== 'files' && $split[1] !== 'cache')) {
                        return false;
                }
 
index cd2be70a8fee7388047d14e846134619ff9ec28a..4b46e976b8164f498f57be6ddff4ff9d4fab9ed8 100644 (file)
@@ -8,6 +8,7 @@
 
 
 require_once __DIR__ . '/../lib/helper.php';
+require_once __DIR__ . '/util.php';
 
 use OCA\Encryption;
 
@@ -16,6 +17,18 @@ use OCA\Encryption;
  */
 class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase {
 
+       const TEST_ENCRYPTION_HELPER_USER1 = "test-helper-user1";
+
+       public static function setUpBeforeClass() {
+               // create test user
+               \Test_Encryption_Util::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1, true);
+       }
+
+       public static function tearDownAfterClass() {
+               // cleanup test user
+               \OC_User::deleteUser(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1);
+       }
+
        /**
         * @medium
         */
@@ -64,4 +77,28 @@ class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase {
                $this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($cachePath));
        }
 
+       function testGetUser() {
+
+               $path1 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/files/foo/bar.txt";
+               $path2 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/cache/foo/bar.txt";
+               $path3 = "/" . self::TEST_ENCRYPTION_HELPER_USER1 . "/thumbnails/foo";
+               $path4 ="/" . "/" . self::TEST_ENCRYPTION_HELPER_USER1;
+
+               // if we are logged-in every path should return the currently logged-in user
+               $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path3));
+
+               // now log out
+               \Test_Encryption_Util::logoutHelper();
+
+               // now we should only get the user from /user/files and user/cache paths
+               $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path1));
+               $this->assertEquals(self::TEST_ENCRYPTION_HELPER_USER1, Encryption\Helper::getUser($path2));
+
+               $this->assertFalse(Encryption\Helper::getUser($path3));
+               $this->assertFalse(Encryption\Helper::getUser($path4));
+
+               // Log-in again
+               \Test_Encryption_Util::loginHelper(\Test_Encryption_Helper::TEST_ENCRYPTION_HELPER_USER1);
+       }
+
 }
index e8dfb74f3f398c12022ae7dc0a671f30453fbf18..c83c3836157fdf449b0afebb141a824359e0a54a 100755 (executable)
@@ -416,6 +416,12 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
                OCA\Encryption\Hooks::login($params);
        }
 
+       public static function logoutHelper() {
+               \OC_Util::tearDownFS();
+               \OC_User::setUserId('');
+               \OC\Files\Filesystem::tearDown();
+       }
+
        /**
         * helper function to set migration status to the right value
         * to be able to test the migration path