summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorinPeter <github@florin-peter.de>2013-05-27 05:15:21 -0700
committerFlorinPeter <github@florin-peter.de>2013-05-27 05:15:21 -0700
commitd878926256be72a27658ee6e98728f9c9b4a4b66 (patch)
tree93988bcd17bc0ed5fe63eb0dbc11f49db899ead2
parent73e0b4c10a26316e9ae085f8fcf6a4e3a2a85384 (diff)
parent8cf827ee9d4ef4c5edea3544ce6d88b4b8c0622d (diff)
downloadnextcloud-server-d878926256be72a27658ee6e98728f9c9b4a4b66.tar.gz
nextcloud-server-d878926256be72a27658ee6e98728f9c9b4a4b66.zip
Merge pull request #3496 from owncloud/file_encryption_tests
improved tests for files_encryption
-rwxr-xr-xapps/files_encryption/tests/crypt.php176
-rw-r--r--apps/files_encryption/tests/encryption.keybin24 -> 24 bytes
-rw-r--r--apps/files_encryption/tests/keymanager.php78
-rw-r--r--apps/files_encryption/tests/legacy-encrypted-text.txt2
-rwxr-xr-xapps/files_encryption/tests/share.php563
-rw-r--r--apps/files_encryption/tests/stream.php66
-rwxr-xr-xapps/files_encryption/tests/trashbin.php178
-rwxr-xr-xapps/files_encryption/tests/util.php182
-rwxr-xr-xapps/files_encryption/tests/webdav.php79
9 files changed, 750 insertions, 574 deletions
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php
index 621941c52a1..74b4252a1d4 100755
--- a/apps/files_encryption/tests/crypt.php
+++ b/apps/files_encryption/tests/crypt.php
@@ -16,14 +16,16 @@ require_once realpath(dirname(__FILE__) . '/../lib/stream.php');
require_once realpath(dirname(__FILE__) . '/../lib/util.php');
require_once realpath(dirname(__FILE__) . '/../lib/helper.php');
require_once realpath(dirname(__FILE__) . '/../appinfo/app.php');
+require_once realpath(dirname(__FILE__) . '/util.php');
use OCA\Encryption;
/**
* Class Test_Encryption_Crypt
*/
-class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_CRYPT_USER1 = "test-crypt-user1";
public $userId;
public $pass;
@@ -39,12 +41,31 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
public $genPrivateKey;
public $genPublicKey;
- function setUp()
- {
+ public static function setUpBeforeClass() {
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerUserHooks();
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true);
+ }
+
+ function setUp() {
+ // set user id
+ \OC_User::setUserId(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
+ $this->userId = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1;
+ $this->pass = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1;
+
// set content for encrypting / decrypting in tests
$this->dataLong = file_get_contents(realpath(dirname(__FILE__) . '/../lib/crypt.php'));
$this->dataShort = 'hats';
@@ -60,53 +81,29 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$this->view = new \OC_FilesystemView('/');
- \OC_User::setUserId('admin');
- $this->userId = 'admin';
- $this->pass = 'admin';
-
- $userHome = \OC_User::getHome($this->userId);
- $this->dataDir = str_replace('/' . $this->userId, '', $userHome);
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerUserHooks();
-
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// remember files_trashbin state
$this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
// we don't want to tests with app files_trashbin enabled
\OC_App::disable('files_trashbin');
-
- \OC_Util::tearDownFS();
- \OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS($this->userId);
- \OC_User::setUserId($this->userId);
-
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- OCA\Encryption\Hooks::login($params);
-
}
- function tearDown()
- {
- \OC_FileProxy::clearProxies();
-
+ function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
- } else {
+ }
+ else {
OC_App::disable('files_trashbin');
}
}
- function testGenerateKey()
- {
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
+ }
+
+ function testGenerateKey() {
# TODO: use more accurate (larger) string length for test confirmation
@@ -119,8 +116,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
/**
* @return String
*/
- function testGenerateIv()
- {
+ function testGenerateIv() {
$iv = Encryption\Crypt::generateIv();
@@ -133,8 +129,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
/**
* @depends testGenerateIv
*/
- function testConcatIv($iv)
- {
+ function testConcatIv($iv) {
$catFile = Encryption\Crypt::concatIv($this->dataLong, $iv);
@@ -157,7 +152,8 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
return array(
'iv' => $iv
- , 'catfile' => $catFile
+ ,
+ 'catfile' => $catFile
);
}
@@ -165,8 +161,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
/**
* @depends testConcatIv
*/
- function testSplitIv($testConcatIv)
- {
+ function testSplitIv($testConcatIv) {
// Split catfile into components
$splitCatfile = Encryption\Crypt::splitIv($testConcatIv['catfile']);
@@ -182,8 +177,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
/**
* @return string padded
*/
- function testAddPadding()
- {
+ function testAddPadding() {
$padded = Encryption\Crypt::addPadding($this->dataLong);
@@ -198,8 +192,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
/**
* @depends testAddPadding
*/
- function testRemovePadding($padded)
- {
+ function testRemovePadding($padded) {
$noPadding = Encryption\Crypt::RemovePadding($padded);
@@ -207,8 +200,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
}
- function testEncrypt()
- {
+ function testEncrypt() {
$random = openssl_random_pseudo_bytes(13);
@@ -220,8 +212,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
}
- function testDecrypt()
- {
+ function testDecrypt() {
$random = openssl_random_pseudo_bytes(13);
@@ -235,8 +226,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
}
- function testSymmetricEncryptFileContent()
- {
+ function testSymmetricEncryptFileContent() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
@@ -251,8 +241,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
}
- function testSymmetricStreamEncryptShortFileContent()
- {
+ function testSymmetricStreamEncryptShortFileContent() {
$filename = 'tmp-' . time() . '.test';
@@ -307,8 +296,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
* reassembly of its data
*/
- function testSymmetricStreamEncryptLongFileContent()
- {
+ function testSymmetricStreamEncryptLongFileContent() {
// Generate a a random filename
$filename = 'tmp-' . time() . '.test';
@@ -339,7 +327,14 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
//print_r($r);
// Join IVs and their respective data chunks
- $e = array($r[0] . $r[1], $r[2] . $r[3], $r[4] . $r[5], $r[6] . $r[7], $r[8] . $r[9], $r[10] . $r[11]); //.$r[11], $r[12].$r[13], $r[14] );
+ $e = array(
+ $r[0] . $r[1],
+ $r[2] . $r[3],
+ $r[4] . $r[5],
+ $r[6] . $r[7],
+ $r[8] . $r[9],
+ $r[10] . $r[11]
+ ); //.$r[11], $r[12].$r[13], $r[14] );
//print_r($e);
@@ -384,8 +379,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
/**
* @brief Test that data that is read by the crypto stream wrapper
*/
- function testSymmetricStreamDecryptShortFileContent()
- {
+ function testSymmetricStreamDecryptShortFileContent() {
$filename = 'tmp-' . time();
@@ -412,8 +406,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$this->view->unlink($this->userId . '/files/' . $filename);
}
- function testSymmetricStreamDecryptLongFileContent()
- {
+ function testSymmetricStreamDecryptLongFileContent() {
$filename = 'tmp-' . time();
@@ -432,8 +425,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$this->view->unlink($this->userId . '/files/' . $filename);
}
- function testSymmetricEncryptFileContentKeyfile()
- {
+ function testSymmetricEncryptFileContentKeyfile() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
@@ -448,8 +440,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
}
- function testIsEncryptedContent()
- {
+ function testIsEncryptedContent() {
$this->assertFalse(Encryption\Crypt::isCatfileContent($this->dataUrl));
@@ -461,8 +452,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
}
- function testMultiKeyEncrypt()
- {
+ function testMultiKeyEncrypt() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
@@ -486,8 +476,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
}
- function testKeyEncrypt()
- {
+ function testKeyEncrypt() {
// Generate keypair
$pair1 = Encryption\Crypt::createKeypair();
@@ -507,8 +496,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
/**
* @brief test encryption using legacy blowfish method
*/
- function testLegacyEncryptShort()
- {
+ function testLegacyEncryptShort() {
$crypted = Encryption\Crypt::legacyEncrypt($this->dataShort, $this->pass);
@@ -525,8 +513,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
* @brief test decryption using legacy blowfish method
* @depends testLegacyEncryptShort
*/
- function testLegacyDecryptShort($crypted)
- {
+ function testLegacyDecryptShort($crypted) {
$decrypted = Encryption\Crypt::legacyDecrypt($crypted, $this->pass);
@@ -537,8 +524,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
/**
* @brief test encryption using legacy blowfish method
*/
- function testLegacyEncryptLong()
- {
+ function testLegacyEncryptLong() {
$crypted = Encryption\Crypt::legacyEncrypt($this->dataLong, $this->pass);
@@ -555,8 +541,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
* @brief test decryption using legacy blowfish method
* @depends testLegacyEncryptLong
*/
- function testLegacyDecryptLong($crypted)
- {
+ function testLegacyDecryptLong($crypted) {
$decrypted = Encryption\Crypt::legacyDecrypt($crypted, $this->pass);
@@ -569,8 +554,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
* @brief test generation of legacy encryption key
* @depends testLegacyDecryptShort
*/
- function testLegacyCreateKey()
- {
+ function testLegacyCreateKey() {
// Create encrypted key
$encKey = Encryption\Crypt::legacyCreateKey($this->pass);
@@ -589,8 +573,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
* @brief test decryption using legacy blowfish method
* @depends testLegacyEncryptLong
*/
- function testLegacyKeyRecryptKeyfileEncrypt($crypted)
- {
+ function testLegacyKeyRecryptKeyfileEncrypt($crypted) {
$recrypted = Encryption\Crypt::LegacyKeyRecryptKeyfile($crypted, $this->pass, array($this->genPublicKey), $this->pass, '');
@@ -603,8 +586,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
}
- function testRenameFile()
- {
+ function testRenameFile() {
$filename = 'tmp-' . time();
@@ -632,8 +614,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$view->unlink($newFilename);
}
- function testMoveFileIntoFolder()
- {
+ function testMoveFileIntoFolder() {
$filename = 'tmp-' . time();
@@ -663,8 +644,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$view->unlink($newFolder);
}
- function testMoveFolder()
- {
+ function testMoveFolder() {
$view = new \OC\Files\View('/' . $this->userId . '/files');
@@ -696,11 +676,11 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
// tear down
$view->unlink($newFolder);
+ $view->unlink('/newfolder');
}
- function testChangePassphrase()
- {
- $filename = 'tmp-' . time();
+ function testChangePassphrase() {
+ $filename = 'tmp-' . time();
// Save long data as encrypted file using stream wrapper
$cryptedFile = file_put_contents('crypt://' . $filename, $this->dataLong);
@@ -733,8 +713,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$view->unlink($filename);
}
- function testViewFilePutAndGetContents()
- {
+ function testViewFilePutAndGetContents() {
$filename = '/tmp-' . time();
$view = new \OC\Files\View('/' . $this->userId . '/files');
@@ -765,8 +744,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$view->unlink($filename);
}
- function testTouchExistingFile()
- {
+ function testTouchExistingFile() {
$filename = '/tmp-' . time();
$view = new \OC\Files\View('/' . $this->userId . '/files');
@@ -787,8 +765,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$view->unlink($filename);
}
- function testTouchFile()
- {
+ function testTouchFile() {
$filename = '/tmp-' . time();
$view = new \OC\Files\View('/' . $this->userId . '/files');
@@ -809,8 +786,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase
$view->unlink($filename);
}
- function testFopenFile()
- {
+ function testFopenFile() {
$filename = '/tmp-' . time();
$view = new \OC\Files\View('/' . $this->userId . '/files');
diff --git a/apps/files_encryption/tests/encryption.key b/apps/files_encryption/tests/encryption.key
index 4495cee78e2..4ee962145c2 100644
--- a/apps/files_encryption/tests/encryption.key
+++ b/apps/files_encryption/tests/encryption.key
Binary files differ
diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php
index b1bae673e82..40ae1659a55 100644
--- a/apps/files_encryption/tests/keymanager.php
+++ b/apps/files_encryption/tests/keymanager.php
@@ -20,8 +20,7 @@ use OCA\Encryption;
/**
* Class Test_Encryption_Keymanager
*/
-class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
public $userId;
public $pass;
@@ -33,14 +32,35 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
public $randomKey;
public $dataShort;
- function setUp()
- {
+ public static function setUpBeforeClass() {
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // disable file proxy by default
\OC_FileProxy::$enabled = false;
+ // setup filesystem
+ \OC_Util::tearDownFS();
+ \OC_User::setUserId('');
+ \OC\Files\Filesystem::tearDown();
+ \OC_Util::setupFS('admin');
+ \OC_User::setUserId('admin');
+
+ // login admin
+ $params['uid'] = 'admin';
+ $params['password'] = 'admin';
+ OCA\Encryption\Hooks::login($params);
+ }
+
+ function setUp() {
// set content for encrypting / decrypting in tests
$this->dataLong = file_get_contents(realpath(dirname(__FILE__) . '/../lib/crypt.php'));
$this->dataShort = 'hats';
@@ -62,44 +82,28 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
$userHome = \OC_User::getHome($this->userId);
$this->dataDir = str_replace('/' . $this->userId, '', $userHome);
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// remember files_trashbin state
$this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
// we don't want to tests with app files_trashbin enabled
\OC_App::disable('files_trashbin');
-
- \OC_Util::tearDownFS();
- \OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS($this->userId);
- \OC_User::setUserId($this->userId);
-
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- OCA\Encryption\Hooks::login($params);
}
- function tearDown()
- {
-
- \OC_FileProxy::$enabled = true;
- \OC_FileProxy::clearProxies();
-
+ function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
- } else {
+ }
+ else {
OC_App::disable('files_trashbin');
}
}
- function testGetPrivateKey()
- {
+ public static function tearDownAfterClass() {
+ \OC_FileProxy::$enabled = true;
+ }
+
+ function testGetPrivateKey() {
$key = Encryption\Keymanager::getPrivateKey($this->view, $this->userId);
@@ -115,8 +119,7 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
}
- function testGetPublicKey()
- {
+ function testGetPublicKey() {
$publiceKey = Encryption\Keymanager::getPublicKey($this->view, $this->userId);
@@ -129,8 +132,7 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('key', $sslInfo);
}
- function testSetFileKey()
- {
+ function testSetFileKey() {
# NOTE: This cannot be tested until we are able to break out
# of the FileSystemView data directory root
@@ -163,8 +165,7 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
}
- function testGetUserKeys()
- {
+ function testGetUserKeys() {
$keys = Encryption\Keymanager::getUserKeys($this->view, $this->userId);
@@ -187,8 +188,7 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('key', $sslInfoPrivate);
}
- function testFixPartialFilePath()
- {
+ function testFixPartialFilePath() {
$partFilename = 'testfile.txt.part';
$filename = 'testfile.txt';
@@ -202,8 +202,7 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
$this->assertEquals('testfile.txt', Encryption\Keymanager::fixPartialFilePath($filename));
}
- function testRecursiveDelShareKeys()
- {
+ function testRecursiveDelShareKeys() {
// generate filename
$filename = '/tmp-' . time() . '.txt';
@@ -230,7 +229,8 @@ class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase
Encryption\Keymanager::delShareKey($this->view, array('admin'), '/folder1/');
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/folder1/subfolder/subsubfolder/' . $filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/admin/files_encryption/share-keys/folder1/subfolder/subsubfolder/' . $filename . '.admin.shareKey'));
// enable encryption proxy
$proxyStatus = \OC_FileProxy::$enabled;
diff --git a/apps/files_encryption/tests/legacy-encrypted-text.txt b/apps/files_encryption/tests/legacy-encrypted-text.txt
index d38cb7d1b0d..1f5087178cd 100644
--- a/apps/files_encryption/tests/legacy-encrypted-text.txt
+++ b/apps/files_encryption/tests/legacy-encrypted-text.txt
@@ -1 +1 @@
- «ß• ’tÕ.µ¤—dS@t9 øQJ \ No newline at end of file
+ð˜¯5–¡‹Ç¡i›òë³Zg§ESlÁF=Àªð \ No newline at end of file
diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php
index 1d0cbfbc1de..6d92881ceb0 100755
--- a/apps/files_encryption/tests/share.php
+++ b/apps/files_encryption/tests/share.php
@@ -29,14 +29,20 @@ require_once realpath(dirname(__FILE__) . '/../lib/stream.php');
require_once realpath(dirname(__FILE__) . '/../lib/util.php');
require_once realpath(dirname(__FILE__) . '/../lib/helper.php');
require_once realpath(dirname(__FILE__) . '/../appinfo/app.php');
+require_once realpath(dirname(__FILE__) . '/util.php');
use OCA\Encryption;
/**
* Class Test_Encryption_Share
*/
-class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_SHARE_USER1 = "test-share-user1";
+ const TEST_ENCRYPTION_SHARE_USER2 = "test-share-user2";
+ const TEST_ENCRYPTION_SHARE_USER3 = "test-share-user3";
+ const TEST_ENCRYPTION_SHARE_USER4 = "test-share-user4";
+ const TEST_ENCRYPTION_SHARE_GROUP1 = "test-share-group1";
public $stateFilesTrashbin;
public $filename;
@@ -49,24 +55,11 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
public $subfolder;
public $subsubfolder;
- function setUp()
- {
+ public static function setUpBeforeClass() {
// reset backend
\OC_User::clearBackends();
\OC_User::useBackend('database');
- $this->dataShort = 'hats';
- $this->view = new \OC_FilesystemView('/');
-
- $userHome = \OC_User::getHome('admin');
- $this->dataDir = str_replace('/admin', '', $userHome);
-
- $this->folder1 = '/folder1';
- $this->subfolder = '/subfolder1';
- $this->subsubfolder = '/subsubfolder1';
-
- $this->filename = 'share-tmp.test';
-
// enable resharing
\OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes');
@@ -81,52 +74,66 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
// Filesystem related hooks
\OCA\Encryption\Helper::registerFilesystemHooks();
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
\OC_FileProxy::register(new OCA\Encryption\Proxy());
- // remember files_trashbin state
- $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
+ // create users
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true);
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true);
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true);
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true);
+
+ // create group and assign users
+ \OC_Group::createGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
+ \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
+ \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
+ }
+
+ function setUp() {
+ $this->dataShort = 'hats';
+ $this->view = new \OC_FilesystemView('/');
+
+ $this->folder1 = '/folder1';
+ $this->subfolder = '/subfolder1';
+ $this->subsubfolder = '/subsubfolder1';
+
+ $this->filename = 'share-tmp.test';
// we don't want to tests with app files_trashbin enabled
\OC_App::disable('files_trashbin');
- // create users
- $this->loginHelper('user1', true);
- $this->loginHelper('user2', true);
- $this->loginHelper('user3', true);
-
- // create group and assign users
- \OC_Group::createGroup('group1');
- \OC_Group::addToGroup('user2', 'group1');
- \OC_Group::addToGroup('user3', 'group1');
+ // remember files_trashbin state
+ $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
}
- function tearDown()
- {
+ function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
- } else {
+ }
+ else {
OC_App::disable('files_trashbin');
}
+ }
+ public static function tearDownAfterClass() {
// clean group
- \OC_Group::deleteGroup('group1');
+ \OC_Group::deleteGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
// cleanup users
- \OC_User::deleteUser('user1');
- \OC_User::deleteUser('user2');
- \OC_User::deleteUser('user3');
-
- \OC_FileProxy::clearProxies();
+ \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+ \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
+ \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
+ \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4);
}
/**
* @param bool $withTeardown
*/
- function testShareFile($withTeardown = true)
- {
+ function testShareFile($withTeardown = true) {
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt://' . $this->filename, $this->dataShort);
@@ -139,7 +146,8 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = false;
// get the file info from previous created file
- $fileInfo = $this->view->getFileInfo('/admin/files/' . $this->filename);
+ $fileInfo = $this->view->getFileInfo(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
$this->assertTrue(is_array($fileInfo));
@@ -151,19 +159,22 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = $proxyStatus;
// share the file
- \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user1', OCP\PERMISSION_ALL);
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user1 exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user1.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// login as user1
- $this->loginHelper('user1');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// get file contents
- $retrievedCryptedFile = $this->view->file_get_contents('/user1/files/Shared/' . $this->filename);
+ $retrievedCryptedFile = $this->view->file_get_contents(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename);
// check if data is the same as we previously written
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
@@ -172,49 +183,57 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
if ($withTeardown) {
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the file
- \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user1');
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user1.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink('/admin/files/' . $this->filename);
+ $this->view->unlink(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
}
/**
* @param bool $withTeardown
*/
- function testReShareFile($withTeardown = true)
- {
+ function testReShareFile($withTeardown = true) {
$this->testShareFile(false);
// login as user1
- $this->loginHelper('user1');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// get the file info
- $fileInfo = $this->view->getFileInfo('/user1/files/Shared/' . $this->filename);
+ $fileInfo = $this->view->getFileInfo(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename);
// share the file with user2
- \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user2', OCP\PERMISSION_ALL);
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, OCP\PERMISSION_ALL);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user2 exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as user2
- $this->loginHelper('user2');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// get file contents
- $retrievedCryptedFile = $this->view->file_get_contents('/user2/files/Shared/' . $this->filename);
+ $retrievedCryptedFile = $this->view->file_get_contents(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/Shared/' . $this->filename);
// check if data is the same as previously written
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
@@ -223,28 +242,35 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
if ($withTeardown) {
// login as user1
- $this->loginHelper('user1');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// unshare the file with user2
- \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user2');
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// unshare the file with user1
- \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user1');
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user1.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink('/admin/files/' . $this->filename);
+ $this->view->unlink(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
}
@@ -252,18 +278,21 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
* @param bool $withTeardown
* @return array
*/
- function testShareFolder($withTeardown = true)
- {
+ function testShareFolder($withTeardown = true) {
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// create folder structure
- $this->view->mkdir('/admin/files' . $this->folder1);
- $this->view->mkdir('/admin/files' . $this->folder1 . $this->subfolder);
- $this->view->mkdir('/admin/files' . $this->folder1 . $this->subfolder . $this->subsubfolder);
+ $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
+ $this->view->mkdir(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder);
+ $this->view->mkdir(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder
+ . $this->subsubfolder);
// save file with content
- $cryptedFile = file_put_contents('crypt://' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename, $this->dataShort);
+ $cryptedFile = file_put_contents('crypt://' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename, $this->dataShort);
// test that data was successfully written
$this->assertTrue(is_int($cryptedFile));
@@ -273,7 +302,8 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = false;
// get the file info from previous created folder
- $fileInfo = $this->view->getFileInfo('/admin/files' . $this->folder1);
+ $fileInfo = $this->view->getFileInfo(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
// check if we have a valid file info
$this->assertTrue(is_array($fileInfo));
@@ -282,19 +312,24 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = $proxyStatus;
// share the folder with user1
- \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user1', OCP\PERMISSION_ALL);
+ \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user1 exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user1.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// login as user1
- $this->loginHelper('user1');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// get file contents
- $retrievedCryptedFile = $this->view->file_get_contents('/user1/files/Shared' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
+ $retrievedCryptedFile = $this->view->file_get_contents(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
// check if data is the same
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
@@ -303,19 +338,25 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
if ($withTeardown) {
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the folder with user1
- \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user1');
+ \OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user1.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink('/admin/files' . $this->folder1);
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
return $fileInfo;
@@ -324,19 +365,20 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
/**
* @param bool $withTeardown
*/
- function testReShareFolder($withTeardown = true)
- {
+ function testReShareFolder($withTeardown = true) {
$fileInfoFolder1 = $this->testShareFolder(false);
// login as user1
- $this->loginHelper('user1');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
// get the file info from previous created folder
- $fileInfoSubFolder = $this->view->getFileInfo('/user1/files/Shared' . $this->folder1 . $this->subfolder);
+ $fileInfoSubFolder = $this->view->getFileInfo(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared' . $this->folder1
+ . $this->subfolder);
// check if we have a valid file info
$this->assertTrue(is_array($fileInfoSubFolder));
@@ -345,43 +387,54 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = $proxyStatus;
// share the file with user2
- \OCP\Share::shareItem('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user2', OCP\PERMISSION_ALL);
+ \OCP\Share::shareItem('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, OCP\PERMISSION_ALL);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user2 exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user2.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as user2
- $this->loginHelper('user2');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// get file contents
- $retrievedCryptedFile = $this->view->file_get_contents('/user2/files/Shared' . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
+ $retrievedCryptedFile = $this->view->file_get_contents(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/Shared' . $this->subfolder
+ . $this->subsubfolder . '/' . $this->filename);
// check if data is the same
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
// get the file info
- $fileInfo = $this->view->getFileInfo('/user2/files/Shared' . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
+ $fileInfo = $this->view->getFileInfo(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/Shared' . $this->subfolder
+ . $this->subsubfolder . '/' . $this->filename);
// check if we have fileInfos
$this->assertTrue(is_array($fileInfo));
// share the file with user3
- \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user3', OCP\PERMISSION_ALL);
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, OCP\PERMISSION_ALL);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user3 exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user3.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user3
- $this->loginHelper('user3');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4);
// get file contents
- $retrievedCryptedFile = $this->view->file_get_contents('/user3/files/Shared/' . $this->filename);
+ $retrievedCryptedFile = $this->view->file_get_contents(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '/files/Shared/' . $this->filename);
// check if data is the same
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
@@ -390,44 +443,57 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
if ($withTeardown) {
// login as user2
- $this->loginHelper('user2');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// unshare the file with user3
- \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user3');
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user3.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user1
- $this->loginHelper('user1');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// unshare the folder with user2
- \OCP\Share::unshare('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user2');
+ \OCP\Share::unshare('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user2.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the folder1 with user1
- \OCP\Share::unshare('folder', $fileInfoFolder1['fileid'], \OCP\Share::SHARE_TYPE_USER, 'user1');
+ \OCP\Share::unshare('folder', $fileInfoFolder1['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user1.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
// cleanup
- $this->view->unlink('/admin/files' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
+ $this->view->unlink(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder
+ . $this->subsubfolder . '/' . $this->filename);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys'
+ . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
}
- function testPublicShareFile()
- {
+ function testPublicShareFile() {
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt://' . $this->filename, $this->dataShort);
@@ -440,7 +506,8 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = false;
// get the file info from previous created file
- $fileInfo = $this->view->getFileInfo('/admin/files/' . $this->filename);
+ $fileInfo = $this->view->getFileInfo(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
$this->assertTrue(is_array($fileInfo));
@@ -455,16 +522,18 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, false, OCP\PERMISSION_ALL);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
$publicShareKeyId = \OC_Appconfig::getValue('files_encryption', 'publicShareKeyId');
// check if share key for public exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.' . $publicShareKeyId . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . $publicShareKeyId . '.shareKey'));
// some hacking to simulate public link
$GLOBALS['app'] = 'files_sharing';
- $GLOBALS['fileOwner'] = 'admin';
+ $GLOBALS['fileOwner'] = \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1;
\OC_User::setUserId('');
// get file contents
@@ -476,25 +545,28 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
// tear down
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the file
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.' . $publicShareKeyId . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . $publicShareKeyId . '.shareKey'));
// cleanup
- $this->view->unlink('/admin/files/' . $this->filename);
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
- function testShareFileWithGroup()
- {
+ function testShareFileWithGroup() {
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt://' . $this->filename, $this->dataShort);
@@ -507,7 +579,8 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = false;
// get the file info from previous created file
- $fileInfo = $this->view->getFileInfo('/admin/files/' . $this->filename);
+ $fileInfo = $this->view->getFileInfo(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
$this->assertTrue(is_array($fileInfo));
@@ -519,44 +592,57 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = $proxyStatus;
// share the file
- \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'group1', OCP\PERMISSION_ALL);
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, OCP\PERMISSION_ALL);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user2 and user3 exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey'));
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user3.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// login as user1
- $this->loginHelper('user2');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
// get file contents
- $retrievedCryptedFile = $this->view->file_get_contents('/user2/files/Shared/' . $this->filename);
+ $retrievedCryptedFile = $this->view->file_get_contents(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/Shared/' . $this->filename);
// check if data is the same as we previously written
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// unshare the file
- \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'group1');
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey'));
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user3.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '.shareKey'));
// cleanup
- $this->view->unlink('/admin/files/' . $this->filename);
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
}
- function testRecoveryFile()
- {
+ function testRecoveryFile() {
+ // login as admin
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
+
\OCA\Encryption\Helper::adminEnableRecovery(null, 'test123');
$recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId');
@@ -564,9 +650,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->view->file_exists('/control-file/controlfile.enc'));
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
- $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), 'admin');
+ $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if recovery password match
$this->assertTrue($util->checkRecoveryPassword('test123'));
@@ -575,23 +661,37 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$this->assertTrue($util->setRecoveryForUser(1));
// create folder structure
- $this->view->mkdir('/admin/files' . $this->folder1);
- $this->view->mkdir('/admin/files' . $this->folder1 . $this->subfolder);
- $this->view->mkdir('/admin/files' . $this->folder1 . $this->subfolder . $this->subsubfolder);
+ $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
+ $this->view->mkdir(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder);
+ $this->view->mkdir(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1 . $this->subfolder
+ . $this->subsubfolder);
// save file with content
$cryptedFile1 = file_put_contents('crypt://' . $this->filename, $this->dataShort);
- $cryptedFile2 = file_put_contents('crypt://' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename, $this->dataShort);
+ $cryptedFile2 = file_put_contents('crypt://' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename, $this->dataShort);
// test that data was successfully written
$this->assertTrue(is_int($cryptedFile1));
$this->assertTrue(is_int($cryptedFile2));
// check if share key for admin and recovery exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.admin.shareKey'));
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.admin.shareKey'));
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
// disable recovery for admin
$this->assertTrue($util->setRecoveryForUser(0));
@@ -600,8 +700,13 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$util->removeRecoveryKeys('/');
// check if share key for recovery not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
// enable recovery for admin
$this->assertTrue($util->setRecoveryForUser(1));
@@ -610,26 +715,35 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$util->addRecoveryKeys('/');
// check if share key for admin and recovery exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
// cleanup
- $this->view->unlink('/admin/files/' . $this->filename);
- $this->view->unlink('/admin/files/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->folder1);
// check if share key for recovery not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
$this->assertTrue(\OCA\Encryption\Helper::adminEnableRecovery(null, 'test123'));
$this->assertTrue(\OCA\Encryption\Helper::adminDisableRecovery('test123'));
$this->assertEquals(0, \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'));
}
- function testRecoveryForUser()
- {
+ function testRecoveryForUser() {
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
\OCA\Encryption\Helper::adminEnableRecovery(null, 'test123');
$recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId');
@@ -638,58 +752,83 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->view->file_exists('/control-file/controlfile.enc'));
// login as user1
- $this->loginHelper('user1');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
- $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), 'user1');
+ $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
// enable recovery for admin
$this->assertTrue($util->setRecoveryForUser(1));
// create folder structure
- $this->view->mkdir('/user1/files' . $this->folder1);
- $this->view->mkdir('/user1/files' . $this->folder1 . $this->subfolder);
- $this->view->mkdir('/user1/files' . $this->folder1 . $this->subfolder . $this->subsubfolder);
+ $this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1);
+ $this->view->mkdir(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder);
+ $this->view->mkdir(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1 . $this->subfolder
+ . $this->subsubfolder);
// save file with content
$cryptedFile1 = file_put_contents('crypt://' . $this->filename, $this->dataShort);
- $cryptedFile2 = file_put_contents('crypt://' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename, $this->dataShort);
+ $cryptedFile2 = file_put_contents('crypt://' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename, $this->dataShort);
// test that data was successfully written
$this->assertTrue(is_int($cryptedFile1));
$this->assertTrue(is_int($cryptedFile2));
// check if share key for user and recovery exists
- $this->assertTrue($this->view->file_exists('/user1/files_encryption/share-keys/' . $this->filename . '.user1.shareKey'));
- $this->assertTrue($this->view->file_exists('/user1/files_encryption/share-keys/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
- $this->assertTrue($this->view->file_exists('/user1/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user1.shareKey'));
- $this->assertTrue($this->view->file_exists('/user1/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// change password
- \OC_User::setPassword('user1', 'test', 'test123');
+ \OC_User::setPassword(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'test', 'test123');
// login as user1
- $this->loginHelper('user1', false, 'test');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, false, 'test');
// get file contents
$retrievedCryptedFile1 = file_get_contents('crypt://' . $this->filename);
- $retrievedCryptedFile2 = file_get_contents('crypt://' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
+ $retrievedCryptedFile2 = file_get_contents(
+ 'crypt://' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename);
// check if data is the same as we previously written
$this->assertEquals($this->dataShort, $retrievedCryptedFile1);
$this->assertEquals($this->dataShort, $retrievedCryptedFile2);
// cleanup
- $this->view->unlink('/user1/files' . $this->folder1);
- $this->view->unlink('/user1/files' . $this->filename);
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->folder1);
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files' . $this->filename);
// check if share key for user and recovery exists
- $this->assertFalse($this->view->file_exists('/user1/files_encryption/share-keys/' . $this->filename . '.user1.shareKey'));
- $this->assertFalse($this->view->file_exists('/user1/files_encryption/share-keys/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
- $this->assertFalse($this->view->file_exists('/user1/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.user1.shareKey'));
- $this->assertFalse($this->view->file_exists('/user1/files_encryption/share-keys/' . $this->folder1 . $this->subfolder . $this->subsubfolder . '/' . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files_encryption/share-keys/' . $this->folder1
+ . $this->subfolder . $this->subsubfolder . '/'
+ . $this->filename . '.' . $recoveryKeyId . '.shareKey'));
// enable recovery for admin
$this->assertTrue($util->setRecoveryForUser(0));
@@ -698,10 +837,9 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$this->assertEquals(0, \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'));
}
- function testFailShareFile()
- {
+ function testFailShareFile() {
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// save file with content
$cryptedFile = file_put_contents('crypt://' . $this->filename, $this->dataShort);
@@ -714,7 +852,8 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = false;
// get the file info from previous created file
- $fileInfo = $this->view->getFileInfo('/admin/files/' . $this->filename);
+ $fileInfo = $this->view->getFileInfo(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
// check if we have a valid file info
$this->assertTrue(is_array($fileInfo));
@@ -723,68 +862,50 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase
$this->assertGreaterThan(0, $fileInfo['unencrypted_size']);
// break users public key
- $this->view->rename('/public-keys/user2.public.key', '/public-keys/user2.public.key_backup');
+ $this->view->rename('/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key',
+ '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key_backup');
// re-enable the file proxy
\OC_FileProxy::$enabled = $proxyStatus;
// share the file
- \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'group1', OCP\PERMISSION_ALL);
+ \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1, OCP\PERMISSION_ALL);
// login as admin
- $this->loginHelper('admin');
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
// check if share key for user1 not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
// break user1 public key
- $this->view->rename('/public-keys/user2.public.key_backup', '/public-keys/user2.public.key');
+ $this->view->rename(
+ '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key_backup',
+ '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.public.key');
// remove share file
- $this->view->unlink('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey');
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3
+ . '.shareKey');
// re-enable the file proxy
\OC_FileProxy::$enabled = $proxyStatus;
// unshare the file with user1
- \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'group1');
+ \OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
// check if share key not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $this->filename . '.user2.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
+ . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
// cleanup
- $this->view->unlink('/admin/files/' . $this->filename);
+ $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
}
-
-
- /**
- * @param $user
- * @param bool $create
- * @param bool $password
- */
- function loginHelper($user, $create = false, $password = false)
- {
- if ($create) {
- \OC_User::createUser($user, $user);
- }
-
- if ($password === false) {
- $password = $user;
- }
-
- \OC_Util::tearDownFS();
- \OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS($user);
- \OC_User::setUserId($user);
-
- $params['uid'] = $user;
- $params['password'] = $password;
- OCA\Encryption\Hooks::login($params);
- }
}
diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php
index 3765d986e12..3d978767542 100644
--- a/apps/files_encryption/tests/stream.php
+++ b/apps/files_encryption/tests/stream.php
@@ -27,6 +27,7 @@ require_once realpath(dirname(__FILE__) . '/../lib/proxy.php');
require_once realpath(dirname(__FILE__) . '/../lib/stream.php');
require_once realpath(dirname(__FILE__) . '/../lib/util.php');
require_once realpath(dirname(__FILE__) . '/../appinfo/app.php');
+require_once realpath(dirname(__FILE__) . '/util.php');
use OCA\Encryption;
@@ -34,8 +35,9 @@ use OCA\Encryption;
* Class Test_Encryption_Stream
* @brief this class provide basic stream tests
*/
-class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_STREAM_USER1 = "test-stream-user1";
public $userId;
public $pass;
@@ -46,15 +48,27 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
public $dataShort;
public $stateFilesTrashbin;
- function setUp()
- {
+ public static function setUpBeforeClass() {
// reset backend
+ \OC_User::clearBackends();
\OC_User::useBackend('database');
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1, true);
+ }
+
+ function setUp() {
// set user id
- \OC_User::setUserId('admin');
- $this->userId = 'admin';
- $this->pass = 'admin';
+ \OC_User::setUserId(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1);
+ $this->userId = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1;
+ $this->pass = \Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1;
// init filesystem view
$this->view = new \OC_FilesystemView('/');
@@ -62,42 +76,26 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
// init short data
$this->dataShort = 'hats';
- // init filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // register encryption file proxy
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// remember files_trashbin state
$this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
// we don't want to tests with app files_trashbin enabled
\OC_App::disable('files_trashbin');
-
- // init filesystem for user
- \OC_Util::tearDownFS();
- \OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS($this->userId);
- \OC_User::setUserId($this->userId);
-
- // login user
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- OCA\Encryption\Hooks::login($params);
}
- function tearDown()
- {
+ function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
- } else {
+ }
+ else {
OC_App::disable('files_trashbin');
}
+ }
- // clear all proxies
- \OC_FileProxy::clearProxies();
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1);
}
function testStreamOptions() {
@@ -113,7 +111,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
$handle = $view->fopen($filename, 'r');
// check if stream is at position zero
- $this->assertEquals(0,ftell($handle));
+ $this->assertEquals(0, ftell($handle));
// set stream options
$this->assertTrue(flock($handle, LOCK_SH));
@@ -136,7 +134,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
$handle = $view->fopen($filename, 'r');
// set stream options
- $this->assertTrue(stream_set_blocking($handle,1));
+ $this->assertTrue(stream_set_blocking($handle, 1));
// tear down
$view->unlink($filename);
@@ -155,7 +153,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
$handle = $view->fopen($filename, 'r');
// set stream options
- $this->assertFalse(stream_set_timeout($handle,1));
+ $this->assertFalse(stream_set_timeout($handle, 1));
// tear down
$view->unlink($filename);
@@ -174,7 +172,7 @@ class Test_Encryption_Stream extends \PHPUnit_Framework_TestCase
$handle = $view->fopen($filename, 'r');
// set stream options
- $this->assertEquals(0, stream_set_write_buffer($handle,1024));
+ $this->assertEquals(0, stream_set_write_buffer($handle, 1024));
// tear down
$view->unlink($filename);
diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php
index cc8709b6f24..29f8fb5a396 100755
--- a/apps/files_encryption/tests/trashbin.php
+++ b/apps/files_encryption/tests/trashbin.php
@@ -28,6 +28,7 @@ require_once realpath(dirname(__FILE__) . '/../lib/stream.php');
require_once realpath(dirname(__FILE__) . '/../lib/util.php');
require_once realpath(dirname(__FILE__) . '/../appinfo/app.php');
require_once realpath(dirname(__FILE__) . '/../../files_trashbin/appinfo/app.php');
+require_once realpath(dirname(__FILE__) . '/util.php');
use OCA\Encryption;
@@ -35,8 +36,9 @@ use OCA\Encryption;
* Class Test_Encryption_Trashbin
* @brief this class provide basic trashbin app tests
*/
-class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_TRASHBIN_USER1 = "test-trashbin-user1";
public $userId;
public $pass;
@@ -50,15 +52,33 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase
public $subfolder;
public $subsubfolder;
- function setUp()
- {
+ public static function setUpBeforeClass() {
// reset backend
+ \OC_User::clearBackends();
\OC_User::useBackend('database');
+ \OC_Hook::clear('OC_Filesystem');
+ \OC_Hook::clear('OC_User');
+
+ // trashbin hooks
+ \OCA\Files_Trashbin\Trashbin::registerHooks();
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1, true);
+ }
+
+ function setUp() {
// set user id
- \OC_User::setUserId('admin');
- $this->userId = 'admin';
- $this->pass = 'admin';
+ \OC_User::setUserId(\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1);
+ $this->userId = \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1;
+ $this->pass = \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1;
// init filesystem view
$this->view = new \OC_FilesystemView('/');
@@ -70,48 +90,26 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase
$this->subfolder = '/subfolder1';
$this->subsubfolder = '/subsubfolder1';
- \OC_Hook::clear('OC_Filesystem');
- \OC_Hook::clear('OC_User');
-
- // init filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // register encryption file proxy
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
- // trashbin hooks
- \OCA\Files_Trashbin\Trashbin::registerHooks();
-
// remember files_trashbin state
$this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
- // we don't want to tests with app files_trashbin enabled
+ // we want to tests with app files_trashbin enabled
\OC_App::enable('files_trashbin');
-
- // init filesystem for user
- \OC_Util::tearDownFS();
- \OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS($this->userId);
- \OC_User::setUserId($this->userId);
-
- // login user
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- OCA\Encryption\Hooks::login($params);
}
- function tearDown()
- {
+ function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
- } else {
+ }
+ else {
OC_App::disable('files_trashbin');
}
+ }
- // clear all proxies
- \OC_FileProxy::clearProxies();
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1);
}
/**
@@ -129,30 +127,40 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase
$this->assertTrue(is_int($cryptedFile));
// check if key for admin exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/keyfiles/' . $filename . '.key'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
+ . '.key'));
// check if share key for admin exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $filename . '.admin.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// delete file
\OC\FIles\Filesystem::unlink($filename);
// check if file not exists
- $this->assertFalse($this->view->file_exists('/admin/files/' . $filename));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
// check if key for admin not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/keyfiles/' . $filename . '.key'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
+ . '.key'));
// check if share key for admin not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// get files
- $trashFiles = $this->view->getDirectoryContent('/admin/files_trashbin/files/');
+ $trashFiles = $this->view->getDirectoryContent(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/');
$trashFileSuffix = null;
// find created file with timestamp
- foreach($trashFiles as $file) {
- if(strncmp($file['path'], $filename, strlen($filename))) {
+ foreach ($trashFiles as $file) {
+ if (strncmp($file['path'], $filename, strlen($filename))) {
$path_parts = pathinfo($file['name']);
$trashFileSuffix = $path_parts['extension'];
}
@@ -162,10 +170,14 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase
$this->assertNotNull($trashFileSuffix);
// check if key for admin not exists
- $this->assertTrue($this->view->file_exists('/admin/files_trashbin/keyfiles/' . $filename . '.key.' . $trashFileSuffix));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
+ . '.key.' . $trashFileSuffix));
// check if share key for admin not exists
- $this->assertTrue($this->view->file_exists('/admin/files_trashbin/share-keys/' . $filename . '.admin.shareKey.' . $trashFileSuffix));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
+ . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
// return filename for next test
return $filename . '.' . $trashFileSuffix;
@@ -182,19 +194,24 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase
$path_parts = pathinfo($filename);
$trashFileSuffix = $path_parts['extension'];
$timestamp = str_replace('d', '', $trashFileSuffix);
- $fileNameWithoutSuffix = str_replace('.'.$trashFileSuffix, '', $filename);
+ $fileNameWithoutSuffix = str_replace('.' . $trashFileSuffix, '', $filename);
// restore file
$this->assertTrue(\OCA\Files_Trashbin\Trashbin::restore($filename, $fileNameWithoutSuffix, $timestamp));
// check if file exists
- $this->assertTrue($this->view->file_exists('/admin/files/' . $fileNameWithoutSuffix));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $fileNameWithoutSuffix));
// check if key for admin exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/keyfiles/' . $fileNameWithoutSuffix . '.key'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/'
+ . $fileNameWithoutSuffix . '.key'));
// check if share key for admin exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $fileNameWithoutSuffix . '.admin.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $fileNameWithoutSuffix . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
}
/**
@@ -212,44 +229,51 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase
$this->assertTrue(is_int($cryptedFile));
// check if key for admin exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/keyfiles/' . $filename . '.key'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
+ . '.key'));
// check if share key for admin exists
- $this->assertTrue($this->view->file_exists('/admin/files_encryption/share-keys/' . $filename . '.admin.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
// delete file
\OC\FIles\Filesystem::unlink($filename);
// check if file not exists
- $this->assertFalse($this->view->file_exists('/admin/files/' . $filename));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files/' . $filename));
// check if key for admin not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/keyfiles/' . $filename . '.key'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/keyfiles/' . $filename
+ . '.key'));
// check if share key for admin not exists
- $this->assertFalse($this->view->file_exists('/admin/files_encryption/share-keys/' . $filename . '.admin.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_encryption/share-keys/'
+ . $filename . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey'));
- // get files
- $trashFiles = $this->view->getDirectoryContent('/admin/files_trashbin/files/');
-
- $trashFileSuffix = null;
// find created file with timestamp
- foreach($trashFiles as $file) {
- if(strncmp($file['name'], $filename, strlen($filename)) == 0) {
- $path_parts = pathinfo($file['name']);
- $trashFileSuffix = $path_parts['extension'];
- break;
- }
- }
+ $query = \OC_DB::prepare('SELECT `timestamp`,`type` FROM `*PREFIX*files_trash`'
+ . ' WHERE `id`=?');
+ $result = $query->execute(array($filename))->fetchRow();
- // check if we found the file we created
- $this->assertNotNull($trashFileSuffix);
+ $this->assertTrue(is_array($result));
+
+ // build suffix
+ $trashFileSuffix = 'd' . $result['timestamp'];
// check if key for admin exists
- $this->assertTrue($this->view->file_exists('/admin/files_trashbin/keyfiles/' . $filename . '.key.' . $trashFileSuffix));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
+ . '.key.' . $trashFileSuffix));
// check if share key for admin exists
- $this->assertTrue($this->view->file_exists('/admin/files_trashbin/share-keys/' . $filename . '.admin.shareKey.' . $trashFileSuffix));
+ $this->assertTrue($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
+ . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
// get timestamp from file
$timestamp = str_replace('d', '', $trashFileSuffix);
@@ -258,13 +282,19 @@ class Test_Encryption_Trashbin extends \PHPUnit_Framework_TestCase
$this->assertGreaterThan(0, \OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp));
// check if key for admin not exists
- $this->assertFalse($this->view->file_exists('/admin/files_trashbin/files/' . $filename . '.' . $trashFileSuffix));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/files/' . $filename . '.'
+ . $trashFileSuffix));
// check if key for admin not exists
- $this->assertFalse($this->view->file_exists('/admin/files_trashbin/keyfiles/' . $filename . '.key.' . $trashFileSuffix));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/keyfiles/' . $filename
+ . '.key.' . $trashFileSuffix));
// check if share key for admin not exists
- $this->assertFalse($this->view->file_exists('/admin/files_trashbin/share-keys/' . $filename . '.admin.shareKey.' . $trashFileSuffix));
+ $this->assertFalse($this->view->file_exists(
+ '/' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '/files_trashbin/share-keys/' . $filename
+ . '.' . \Test_Encryption_Trashbin::TEST_ENCRYPTION_TRASHBIN_USER1 . '.shareKey.' . $trashFileSuffix));
}
} \ No newline at end of file
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index a2be8a40417..2069cae27e5 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -19,8 +19,10 @@ use OCA\Encryption;
/**
* Class Test_Encryption_Util
*/
-class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_UTIL_USER1 = "test-util-user1";
+ const TEST_ENCRYPTION_UTIL_LEGACY_USER = "test-legacy-user";
public $userId;
public $encryptionDir;
@@ -40,16 +42,31 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
public $dataShort;
public $legacyEncryptedData;
public $legacyEncryptedDataKey;
- public $lagacyKey;
+ public $legacyKey;
+ public $stateFilesTrashbin;
- function setUp()
- {
+ public static function setUpBeforeClass() {
// reset backend
+ \OC_User::clearBackends();
\OC_User::useBackend('database');
- \OC_User::setUserId('admin');
- $this->userId = 'admin';
- $this->pass = 'admin';
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1, true);
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER, true);
+ }
+
+
+ function setUp() {
+ \OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
+ $this->userId = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
+ $this->pass = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1;
// set content for encrypting / decrypting in tests
$this->dataUrl = realpath(dirname(__FILE__) . '/../lib/crypt.php');
@@ -58,7 +75,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
$this->legacyData = realpath(dirname(__FILE__) . '/legacy-text.txt');
$this->legacyEncryptedData = realpath(dirname(__FILE__) . '/legacy-encrypted-text.txt');
$this->legacyEncryptedDataKey = realpath(dirname(__FILE__) . '/encryption.key');
- $this->lagacyKey = '62829813025828180801';
+ $this->legacyKey = '30943623843030686906';
$keypair = Encryption\Crypt::createKeypair();
@@ -68,43 +85,42 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
$this->publicKeyDir = '/' . 'public-keys';
$this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
$this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles';
- $this->publicKeyPath = $this->publicKeyDir . '/' . $this->userId . '.public.key'; // e.g. data/public-keys/admin.public.key
- $this->privateKeyPath = $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
+ $this->publicKeyPath =
+ $this->publicKeyDir . '/' . $this->userId . '.public.key'; // e.g. data/public-keys/admin.public.key
+ $this->privateKeyPath =
+ $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
$this->view = new \OC_FilesystemView('/');
- $userHome = \OC_User::getHome($this->userId);
- $this->dataDir = str_replace('/' . $this->userId, '', $userHome);
-
- // Filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
- \OC_Util::tearDownFS();
- \OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS($this->userId);
- \OC_User::setUserId($this->userId);
+ $this->util = new Encryption\Util($this->view, $this->userId);
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- OCA\Encryption\Hooks::login($params);
+ // remember files_trashbin state
+ $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
- $this->util = new Encryption\Util($this->view, $this->userId);
+ // we don't want to tests with app files_trashbin enabled
+ \OC_App::disable('files_trashbin');
}
- function tearDown()
- {
+ function tearDown() {
+ // reset app files_trashbin
+ if ($this->stateFilesTrashbin) {
+ OC_App::enable('files_trashbin');
+ }
+ else {
+ OC_App::disable('files_trashbin');
+ }
+ }
- \OC_FileProxy::clearProxies();
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
+ \OC_User::deleteUser(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
}
/**
* @brief test that paths set during User construction are correct
*/
- function testKeyPaths()
- {
+ function testKeyPaths() {
$util = new Encryption\Util($this->view, $this->userId);
$this->assertEquals($this->publicKeyDir, $util->getPath('publicKeyDir'));
@@ -118,39 +134,37 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
/**
* @brief test setup of encryption directories
*/
- function testSetupServerSide()
- {
+ function testSetupServerSide() {
$this->assertEquals(true, $this->util->setupServerSide($this->pass));
}
/**
* @brief test checking whether account is ready for encryption,
*/
- function testUserIsReady()
- {
+ function testUserIsReady() {
$this->assertEquals(true, $this->util->ready());
}
/**
* @brief test checking whether account is not ready for encryption,
*/
- function testUserIsNotReady()
- {
- $this->view->unlink($this->publicKeyDir);
-
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- $this->assertFalse(OCA\Encryption\Hooks::login($params));
-
- $this->view->unlink($this->privateKeyPath);
- }
+// function testUserIsNotReady() {
+// $this->view->unlink($this->publicKeyDir);
+//
+// $params['uid'] = $this->userId;
+// $params['password'] = $this->pass;
+// $this->assertFalse(OCA\Encryption\Hooks::login($params));
+//
+// $this->view->unlink($this->privateKeyPath);
+// }
/**
* @brief test checking whether account is not ready for encryption,
*/
- function testIsLagacyUser()
- {
- $userView = new \OC_FilesystemView( '/' . $this->userId );
+ function testIsLegacyUser() {
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
+
+ $userView = new \OC_FilesystemView('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
@@ -161,19 +175,18 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = $proxyStatus;
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
+ $params['uid'] = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER;
+ $params['password'] = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER;
- $util = new Encryption\Util($this->view, $this->userId);
+ $util = new Encryption\Util($this->view, \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
$util->setMigrationStatus(0);
$this->assertTrue(OCA\Encryption\Hooks::login($params));
- $this->assertEquals($this->lagacyKey, $_SESSION['legacyKey']);
+ $this->assertEquals($this->legacyKey, $_SESSION['legacyKey']);
}
- function testRecoveryEnabledForUser()
- {
+ function testRecoveryEnabledForUser() {
$util = new Encryption\Util($this->view, $this->userId);
@@ -193,10 +206,9 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
}
- function testGetUidAndFilename()
- {
+ function testGetUidAndFilename() {
- \OC_User::setUserId('admin');
+ \OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1);
$filename = 'tmp-' . time() . '.test';
@@ -213,9 +225,11 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
list($fileOwnerUid, $file) = $util->getUidAndFilename($filename);
- $this->assertEquals('admin', $fileOwnerUid);
+ $this->assertEquals(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1, $fileOwnerUid);
$this->assertEquals($file, $filename);
+
+ $this->view->unlink($this->userId . '/files/' . $filename);
}
function testIsSharedPath() {
@@ -227,10 +241,11 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->util->isSharedPath($path));
}
- function testEncryptLagacyFiles()
- {
- $userView = new \OC_FilesystemView( '/' . $this->userId);
- $view = new \OC_FilesystemView( '/' . $this->userId . '/files' );
+ function testEncryptLegacyFiles() {
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
+
+ $userView = new \OC_FilesystemView('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
+ $view = new \OC_FilesystemView('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER . '/files');
// Disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
@@ -250,23 +265,23 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
\OC_FileProxy::$enabled = $proxyStatus;
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
+ $params['uid'] = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER;
+ $params['password'] = \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER;
- $util = new Encryption\Util($this->view, $this->userId);
+ $util = new Encryption\Util($this->view, \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER);
$util->setMigrationStatus(0);
$this->assertTrue(OCA\Encryption\Hooks::login($params));
- $this->assertEquals($this->lagacyKey, $_SESSION['legacyKey']);
+ $this->assertEquals($this->legacyKey, $_SESSION['legacyKey']);
- $files = $util->findEncFiles('/' . $this->userId . '/files/');
+ $files = $util->findEncFiles('/' . \Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER . '/files/');
$this->assertTrue(is_array($files));
$found = false;
- foreach($files['encrypted'] as $encryptedFile) {
- if($encryptedFile['name'] === 'legacy-encrypted-text.txt') {
+ foreach ($files['encrypted'] as $encryptedFile) {
+ if ($encryptedFile['name'] === 'legacy-encrypted-text.txt') {
$found = true;
break;
}
@@ -274,4 +289,29 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase
$this->assertTrue($found);
}
+
+ /**
+ * @param $user
+ * @param bool $create
+ * @param bool $password
+ */
+ public static function loginHelper($user, $create = false, $password = false) {
+ if ($create) {
+ \OC_User::createUser($user, $user);
+ }
+
+ if ($password === false) {
+ $password = $user;
+ }
+
+ \OC_Util::tearDownFS();
+ \OC_User::setUserId('');
+ \OC\Files\Filesystem::tearDown();
+ \OC_Util::setupFS($user);
+ \OC_User::setUserId($user);
+
+ $params['uid'] = $user;
+ $params['password'] = $password;
+ OCA\Encryption\Hooks::login($params);
+ }
} \ No newline at end of file
diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php
index 4b453d0c9d1..94d3ec3fa55 100755
--- a/apps/files_encryption/tests/webdav.php
+++ b/apps/files_encryption/tests/webdav.php
@@ -27,6 +27,7 @@ require_once realpath(dirname(__FILE__) . '/../lib/proxy.php');
require_once realpath(dirname(__FILE__) . '/../lib/stream.php');
require_once realpath(dirname(__FILE__) . '/../lib/util.php');
require_once realpath(dirname(__FILE__) . '/../appinfo/app.php');
+require_once realpath(dirname(__FILE__) . '/util.php');
use OCA\Encryption;
@@ -34,8 +35,9 @@ use OCA\Encryption;
* Class Test_Encryption_Webdav
* @brief this class provide basic webdav tests for PUT,GET and DELETE
*/
-class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
-{
+class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
+
+ const TEST_ENCRYPTION_WEBDAV_USER1 = "test-webdav-user1";
public $userId;
public $pass;
@@ -46,15 +48,33 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
public $dataShort;
public $stateFilesTrashbin;
- function setUp()
- {
+ public static function setUpBeforeClass() {
+ // reset backend
+ \OC_User::clearBackends();
+ \OC_User::useBackend('database');
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerFilesystemHooks();
+
+ // Filesystem related hooks
+ \OCA\Encryption\Helper::registerUserHooks();
+
+ // clear and register hooks
+ \OC_FileProxy::clearProxies();
+ \OC_FileProxy::register(new OCA\Encryption\Proxy());
+
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1, true);
+ }
+
+ function setUp() {
// reset backend
\OC_User::useBackend('database');
// set user id
- \OC_User::setUserId('admin');
- $this->userId = 'admin';
- $this->pass = 'admin';
+ \OC_User::setUserId(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
+ $this->userId = \Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1;
+ $this->pass = \Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1;
// init filesystem view
$this->view = new \OC_FilesystemView('/');
@@ -62,42 +82,29 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
// init short data
$this->dataShort = 'hats';
- // init filesystem related hooks
- \OCA\Encryption\Helper::registerFilesystemHooks();
-
- // register encryption file proxy
- \OC_FileProxy::register(new OCA\Encryption\Proxy());
-
// remember files_trashbin state
$this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
// we don't want to tests with app files_trashbin enabled
\OC_App::disable('files_trashbin');
- // init filesystem for user
- \OC_Util::tearDownFS();
- \OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
- \OC_Util::setupFS($this->userId);
- \OC_User::setUserId($this->userId);
-
- // login user
- $params['uid'] = $this->userId;
- $params['password'] = $this->pass;
- OCA\Encryption\Hooks::login($params);
+ // create test user
+ \Test_Encryption_Util::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
}
- function tearDown()
- {
+ function tearDown() {
// reset app files_trashbin
if ($this->stateFilesTrashbin) {
OC_App::enable('files_trashbin');
- } else {
+ }
+ else {
OC_App::disable('files_trashbin');
}
+ }
- // clear all proxies
- \OC_FileProxy::clearProxies();
+ public static function tearDownAfterClass() {
+ // cleanup test user
+ \OC_User::deleteUser(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1);
}
/**
@@ -125,10 +132,12 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->view->file_exists('/' . $this->userId . '/files' . $filename));
// check if key-file was created
- $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keyfiles/' . $filename . '.key'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . $this->userId . '/files_encryption/keyfiles/' . $filename . '.key'));
// check if shareKey-file was created
- $this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/share-keys/' . $filename . '.' . $this->userId . '.shareKey'));
+ $this->assertTrue($this->view->file_exists(
+ '/' . $this->userId . '/files_encryption/share-keys/' . $filename . '.' . $this->userId . '.shareKey'));
// disable encryption proxy to prevent recursive calls
$proxyStatus = \OC_FileProxy::$enabled;
@@ -194,10 +203,12 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->view->file_exists('/' . $this->userId . '/files' . $filename));
// check if key-file was removed
- $this->assertFalse($this->view->file_exists('/' . $this->userId . '/files_encryption/keyfiles' . $filename . '.key'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . $this->userId . '/files_encryption/keyfiles' . $filename . '.key'));
// check if shareKey-file was removed
- $this->assertFalse($this->view->file_exists('/' . $this->userId . '/files_encryption/share-keys' . $filename . '.' . $this->userId . '.shareKey'));
+ $this->assertFalse($this->view->file_exists(
+ '/' . $this->userId . '/files_encryption/share-keys' . $filename . '.' . $this->userId . '.shareKey'));
}
/**
@@ -229,7 +240,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase
$server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
// And off we go!
- if($body) {
+ if ($body) {
$server->httpRequest->setBody($body);
}