summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-12-19 11:09:41 -0800
committerBjörn Schießle <schiessle@owncloud.com>2013-12-19 11:09:41 -0800
commit6a3e38266f5fa427136b7d4af587892b0d7214ed (patch)
tree5b9acbef5b85da5e4d12f4752e22755a5767a4e8 /apps/files_encryption/tests
parentf0da7b20c12c14e0fbd9cddfbe7c5c26d43e2607 (diff)
parent517a55a437b5c5f455a3b294a80709345e7625ec (diff)
downloadnextcloud-server-6a3e38266f5fa427136b7d4af587892b0d7214ed.tar.gz
nextcloud-server-6a3e38266f5fa427136b7d4af587892b0d7214ed.zip
Merge pull request #6507 from owncloud/enc_fix_getUser
[encryption] fix getUser Helper
Diffstat (limited to 'apps/files_encryption/tests')
-rw-r--r--apps/files_encryption/tests/helper.php37
-rwxr-xr-xapps/files_encryption/tests/util.php6
2 files changed, 43 insertions, 0 deletions
diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php
index cd2be70a8fe..4b46e976b81 100644
--- a/apps/files_encryption/tests/helper.php
+++ b/apps/files_encryption/tests/helper.php
@@ -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);
+ }
+
}
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index 7d425dc122a..b1904cbadc7 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -451,6 +451,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