summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/tests/keymanager.php
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-06-23 17:13:56 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-06-25 12:27:30 +0200
commit3d0805f27d1d84399ed87403f33cfbde556ae69a (patch)
treeb368d3a1c70a63bc505583b688a25720566b80c6 /apps/files_encryption/tests/keymanager.php
parent709691548dbf72c5763879136f3a0ba4e8a0c135 (diff)
downloadnextcloud-server-3d0805f27d1d84399ed87403f33cfbde556ae69a.tar.gz
nextcloud-server-3d0805f27d1d84399ed87403f33cfbde556ae69a.zip
always use a \OC\Files\View
Diffstat (limited to 'apps/files_encryption/tests/keymanager.php')
-rw-r--r--apps/files_encryption/tests/keymanager.php65
1 files changed, 33 insertions, 32 deletions
diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php
index 0c025443cd6..7c36a4689b0 100644
--- a/apps/files_encryption/tests/keymanager.php
+++ b/apps/files_encryption/tests/keymanager.php
@@ -206,43 +206,44 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
*/
function testRecursiveDelShareKeys() {
- // generate filename
- $filename = '/tmp-' . uniqid() . '.txt';
-
// create folder structure
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/subfolder');
- $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/subfolder/subsubfolder');
-
- // enable encryption proxy
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = true;
-
- // save file with content
- $cryptedFile = file_put_contents('crypt:///'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/subfolder/subsubfolder' . $filename, $this->dataShort);
-
- // test that data was successfully written
- $this->assertTrue(is_int($cryptedFile));
-
- // change encryption proxy to previous state
- \OC_FileProxy::$enabled = $proxyStatus;
-
- // recursive delete keys
- Encryption\Keymanager::delShareKey($this->view, array('admin'), '/folder1/');
-
- // check if share key not exists
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder');
+ $this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder');
+
+ // create some dummy share keys
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user2.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user3.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/file2.user3.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1.user1.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user2.shareKey', 'data');
+ $this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user3.shareKey', 'data');
+
+ // recursive delete share keys from user1 and user2
+ Encryption\Keymanager::delShareKey($this->view, array('user1', 'user2'), '/folder1/');
+
+ // check if share keys from user1 and user2 are deleted
+ $this->assertFalse($this->view->file_exists(
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user2.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1.user1.shareKey'));
$this->assertFalse($this->view->file_exists(
- '/admin/files_encryption/share-keys/folder1/subfolder/subsubfolder/' . $filename . '.admin.shareKey'));
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user2.shareKey'));
- // enable encryption proxy
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = true;
+ // check if share keys from user3 still exists
+ $this->assertTrue($this->view->file_exists(
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user3.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user3.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/file2.user3.shareKey'));
// cleanup
- $this->view->deleteAll('/admin/files/folder1');
+ $this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys');
- // change encryption proxy to previous state
- \OC_FileProxy::$enabled = $proxyStatus;
}
function testKeySetPreperation() {
@@ -283,6 +284,6 @@ class TestProtectedKeymanagerMethods extends \OCA\Encryption\Keymanager {
* @param string $basePath
*/
public static function testKeySetPreperation($view, $path, $basePath) {
- return self::keySetPreparation($view, $path, $basePath, '');
+ return self::keySetPreparation($view, $path, $basePath);
}
}