From 6b85fe819c4c944ae27a1588d809f4dfeb0d0259 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Jun 2014 09:29:11 +0200 Subject: [PATCH 1/2] always use '/' as directory seperator --- apps/files_encryption/lib/keymanager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 28cd9e52f9..07ac1a7bd5 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -527,7 +527,7 @@ class Keymanager { isset($path_parts['dirname']) && !$view->file_exists($basePath . '/' . $path_parts['dirname']) ) { - $sub_dirs = explode(DIRECTORY_SEPARATOR, $basePath . '/' . $path_parts['dirname']); + $sub_dirs = explode('/', $basePath . '/' . $path_parts['dirname']); $dir = ''; foreach ($sub_dirs as $sub_dir) { $dir .= '/' . $sub_dir; From 9c45a3196bff4ae0658cb26e7011589bd17b5454 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 24 Jun 2014 10:43:07 +0200 Subject: [PATCH 2/2] add unit tests --- apps/files_encryption/lib/keymanager.php | 2 +- apps/files_encryption/tests/keymanager.php | 30 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 07ac1a7bd5..98986d1486 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -516,7 +516,7 @@ class Keymanager { * @param string|boolean $path * @param string $basePath */ - public static function keySetPreparation(\OC\Files\View $view, $path, $basePath, $userId) { + protected static function keySetPreparation(\OC\Files\View $view, $path, $basePath, $userId) { $targetPath = ltrim($path, '/'); diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php index 2bd2ddc8e6..0c025443cd 100644 --- a/apps/files_encryption/tests/keymanager.php +++ b/apps/files_encryption/tests/keymanager.php @@ -239,11 +239,30 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase { \OC_FileProxy::$enabled = true; // cleanup - $this->view->unlink('/admin/files/folder1'); + $this->view->deleteAll('/admin/files/folder1'); // change encryption proxy to previous state \OC_FileProxy::$enabled = $proxyStatus; } + + function testKeySetPreperation() { + $basePath = '/'.Test_Encryption_Keymanager::TEST_USER.'/files'; + $path = '/folder1/subfolder/subsubfolder'; + + $this->assertFalse($this->view->is_dir($basePath . '/testKeySetPreperation')); + + $result = TestProtectedKeymanagerMethods::testKeySetPreperation($this->view, $path, $basePath); + + // return path without leading slash + $this->assertSame('folder1/subfolder/subsubfolder', $result); + + // check if directory structure was created + $this->assertTrue($this->view->is_dir($basePath . '/folder1/subfolder/subsubfolder')); + + // cleanup + $this->view->deleteAll($basePath . '/folder1'); + + } } /** @@ -257,4 +276,13 @@ class TestProtectedKeymanagerMethods extends \OCA\Encryption\Keymanager { public static function testGetFilenameFromShareKey($sharekey) { return self::getFilenameFromShareKey($sharekey); } + + /** + * @param \OC\Files\View $view relative to data/ + * @param string $path + * @param string $basePath + */ + public static function testKeySetPreperation($view, $path, $basePath) { + return self::keySetPreparation($view, $path, $basePath, ''); + } }