diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-11-18 17:25:36 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-12-02 16:03:54 +0100 |
commit | 49cfc3035944956269e7264df9fbfb202b7e096d (patch) | |
tree | e37976b7b0019a2dc551952c359a2bbe3814b191 /apps/files_encryption/tests | |
parent | a90606fb14adc0aa149a87528d4f1ce61d0250e9 (diff) | |
download | nextcloud-server-49cfc3035944956269e7264df9fbfb202b7e096d.tar.gz nextcloud-server-49cfc3035944956269e7264df9fbfb202b7e096d.zip |
upgrade to new folder structure
Diffstat (limited to 'apps/files_encryption/tests')
-rwxr-xr-x | apps/files_encryption/tests/crypt.php | 22 | ||||
-rw-r--r-- | apps/files_encryption/tests/helper.php | 8 | ||||
-rw-r--r-- | apps/files_encryption/tests/hooks.php | 32 | ||||
-rw-r--r-- | apps/files_encryption/tests/keymanager.php | 23 | ||||
-rw-r--r-- | apps/files_encryption/tests/migration.php | 259 | ||||
-rw-r--r-- | apps/files_encryption/tests/proxy.php | 22 | ||||
-rwxr-xr-x | apps/files_encryption/tests/share.php | 31 | ||||
-rw-r--r-- | apps/files_encryption/tests/stream.php | 19 | ||||
-rw-r--r-- | apps/files_encryption/tests/testcase.php | 31 | ||||
-rwxr-xr-x | apps/files_encryption/tests/trashbin.php | 22 | ||||
-rwxr-xr-x | apps/files_encryption/tests/util.php | 25 | ||||
-rwxr-xr-x | apps/files_encryption/tests/webdav.php | 22 |
12 files changed, 211 insertions, 305 deletions
diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index 46a717f851e..ab2ce066cdb 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -33,20 +33,6 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { public static function setUpBeforeClass() { parent::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 self::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true); } @@ -99,14 +85,6 @@ class Test_Encryption_Crypt extends \OCA\Files_Encryption\Tests\TestCase { // cleanup test user \OC_User::deleteUser(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1); - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php index f0e3408b2e0..88ba9f20d53 100644 --- a/apps/files_encryption/tests/helper.php +++ b/apps/files_encryption/tests/helper.php @@ -38,14 +38,6 @@ class Test_Encryption_Helper extends \OCA\Files_Encryption\Tests\TestCase { } public static function tearDownAfterClass() { - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php index fc40d4cd61f..d5a30f5074a 100644 --- a/apps/files_encryption/tests/hooks.php +++ b/apps/files_encryption/tests/hooks.php @@ -63,28 +63,6 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { '.t est.txt' ); - // reset backend - \OC_User::clearBackends(); - \OC_User::useBackend('database'); - - \OC_Hook::clear('OC_Filesystem'); - \OC_Hook::clear('OC_User'); - - // clear share hooks - \OC_Hook::clear('OCP\\Share'); - \OC::registerShareHooks(); - \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); - - // Filesystem related hooks - \OCA\Encryption\Helper::registerFilesystemHooks(); - - // Sharing related hooks - \OCA\Encryption\Helper::registerShareHooks(); - - // clear and register proxies - \OC_FileProxy::clearProxies(); - \OC_FileProxy::register(new OCA\Encryption\Proxy()); - // create test user self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1, true); self::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2, true); @@ -114,14 +92,6 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { \OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1); \OC_User::deleteUser(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2); - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } @@ -439,7 +409,7 @@ class Test_Encryption_Hooks extends \OCA\Files_Encryption\Tests\TestCase { // set user password for the first time \OCA\Encryption\Hooks::postCreateUser(array('uid' => 'newUser', 'password' => 'newUserPassword')); - $this->assertTrue($view->file_exists('public-keys/newUser.publicKey')); + $this->assertTrue($view->file_exists(\OCA\Encryption\Keymanager::getPublicKeyPath() . '/newUser.publicKey')); $this->assertTrue($view->file_exists('newUser/files_encryption/newUser.privateKey')); // check if we are able to decrypt the private key diff --git a/apps/files_encryption/tests/keymanager.php b/apps/files_encryption/tests/keymanager.php index f86f7d894ce..21f03839430 100644 --- a/apps/files_encryption/tests/keymanager.php +++ b/apps/files_encryption/tests/keymanager.php @@ -28,17 +28,6 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { public static function setUpBeforeClass() { parent::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; @@ -92,14 +81,6 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { OC_App::enable('files_trashbin'); } - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } @@ -192,14 +173,14 @@ class Test_Encryption_Keymanager extends \OCA\Files_Encryption\Tests\TestCase { Encryption\Keymanager::setPrivateSystemKey($key, $keyName); - $this->assertTrue($this->view->file_exists('/owncloud_private_key/' . $keyName . '.privateKey')); + $this->assertTrue($this->view->file_exists('/files_encryption/' . $keyName . '.privateKey')); $result = Encryption\Keymanager::getPrivateSystemKey($keyName); $this->assertSame($encHeader . $key, $result); // clean up - $this->view->unlink('/owncloud_private_key/' . $keyName.'.privateKey'); + $this->view->unlink('/files_encryption/' . $keyName.'.privateKey'); } diff --git a/apps/files_encryption/tests/migration.php b/apps/files_encryption/tests/migration.php index 8ca2e94c90a..21c4e354c29 100644 --- a/apps/files_encryption/tests/migration.php +++ b/apps/files_encryption/tests/migration.php @@ -2,8 +2,9 @@ /** * ownCloud * - * @author Thomas Müller - * @copyright 2014 Thomas Müller deepdiver@owncloud.com + * @copyright (C) 2014 ownCloud, Inc. + * + * @author Bjoern Schiessle <schiessle@owncloud.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -23,7 +24,29 @@ use OCA\Encryption; use OCA\Files_Encryption\Migration; -class Test_Migration extends \Test\TestCase { +class Test_Migration extends \OCA\Files_Encryption\Tests\TestCase { + + const TEST_ENCRYPTION_MIGRATION_USER1='test_encryption_user1'; + const TEST_ENCRYPTION_MIGRATION_USER2='test_encryption_user2'; + const TEST_ENCRYPTION_MIGRATION_USER3='test_encryption_user3'; + + private $view; + private $public_share_key_id; + private $recovery_key_id; + + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + self::loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER1, true); + self::loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER2, true); + self::loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER3, true); + } + + public static function tearDownAfterClass() { + \OC_User::deleteUser(self::TEST_ENCRYPTION_MIGRATION_USER1); + \OC_User::deleteUser(self::TEST_ENCRYPTION_MIGRATION_USER2); + \OC_User::deleteUser(self::TEST_ENCRYPTION_MIGRATION_USER3); + parent::tearDownAfterClass(); + } protected function tearDown() { if (OC_DB::tableExists('encryption_test')) { @@ -34,26 +57,17 @@ class Test_Migration extends \Test\TestCase { parent::tearDown(); } - protected function setUp() { - parent::setUp(); - + public function setUp() { + $this->loginHelper(self::TEST_ENCRYPTION_MIGRATION_USER1); + $this->view = new \OC\Files\View(); + $this->public_share_key_id = Encryption\Helper::getPublicShareKeyId(); + $this->recovery_key_id = Encryption\Helper::getRecoveryKeyId(); if (OC_DB::tableExists('encryption_test')) { OC_DB::dropTable('encryption_test'); } $this->assertTableNotExist('encryption_test'); } - public function testEncryptionTableDoesNotExist() { - - $this->assertTableNotExist('encryption_test'); - - $migration = new Migration('encryption_test'); - $migration->dropTableEncryption(); - - $this->assertTableNotExist('encryption_test'); - - } - public function checkLastIndexId() { $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (' .' `item_type`, `item_source`, `item_target`, `share_type`,' @@ -91,89 +105,160 @@ class Test_Migration extends \Test\TestCase { $this->checkLastIndexId(); } - public function testDataMigration() { - // TODO travis - if (getenv('TRAVIS')) { - $this->markTestSkipped('Fails on travis'); + /** + * @param string $table + */ + public function assertTableNotExist($table) { + $type=OC_Config::getValue( "dbtype", "sqlite" ); + if( $type == 'sqlite' || $type == 'sqlite3' ) { + // sqlite removes the tables after closing the DB + $this->assertTrue(true); + } else { + $this->assertFalse(OC_DB::tableExists($table), 'Table ' . $table . ' exists.'); } - - $this->assertTableNotExist('encryption_test'); - - // create test table - OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml'); - $this->assertTableExist('encryption_test'); - - OC_DB::executeAudited('INSERT INTO `*PREFIX*encryption_test` values(?, ?, ?, ?)', - array('user1', 'server-side', 1, 1)); - - // preform migration - $migration = new Migration('encryption_test'); - $migration->dropTableEncryption(); - - // assert - $this->assertTableNotExist('encryption_test'); - - $rec = \OC_Preferences::getValue('user1', 'files_encryption', 'recovery_enabled'); - $mig = \OC_Preferences::getValue('user1', 'files_encryption', 'migration_status'); - - $this->assertEquals(1, $rec); - $this->assertEquals(1, $mig); } - public function testDuplicateDataMigration() { - // TODO travis - if (getenv('TRAVIS')) { - $this->markTestSkipped('Fails on travis'); + protected function createDummyShareKeys($uid) { + $this->view->mkdir($uid . '/files_encryption/share-keys/folder1/folder2/folder3'); + $this->view->mkdir($uid . '/files_encryption/share-keys/folder2/'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/folder3/file3.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/folder3/file3.' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/folder3/file3.' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/file2.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/file2.' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/folder2/file2.' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/file.1.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/file.1.' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder1/file.1.' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey' , 'data'); + if ($this->public_share_key_id) { + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . $this->public_share_key_id . '.shareKey' , 'data'); } - - // create test table - OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml'); - - // in case of duplicate entries we want to preserve 0 on migration status and 1 on recovery - $data = array( - array('user1', 'server-side', 1, 1), - array('user1', 'server-side', 1, 0), - array('user1', 'server-side', 0, 1), - array('user1', 'server-side', 0, 0), - ); - foreach ($data as $d) { - OC_DB::executeAudited( - 'INSERT INTO `*PREFIX*encryption_test` values(?, ?, ?, ?)', - $d); + if ($this->recovery_key_id) { + $this->view->file_put_contents($uid . '/files_encryption/share-keys/folder2/file.2.1.' . $this->recovery_key_id . '.shareKey' , 'data'); } + } - // preform migration - $migration = new Migration('encryption_test'); - $migration->dropTableEncryption(); + protected function createDummyFileKeys($uid) { + $this->view->mkdir($uid . '/files_encryption/keyfiles/folder1/folder2/folder3'); + $this->view->mkdir($uid . '/files_encryption/keyfiles/folder2/'); + $this->view->file_put_contents($uid . '/files_encryption/keyfiles/folder1/folder2/folder3/file3.key' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/keyfiles/folder1/folder2/file2.key' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/keyfiles/folder1/file.1.key' , 'data'); + $this->view->file_put_contents($uid . '/files_encryption/keyfiles/folder2/file.2.1.key' , 'data'); + } - // assert - $this->assertTableNotExist('encryption_test'); + protected function createDummyFilesInTrash($uid) { + $this->view->mkdir($uid . '/files_trashbin/share-keys'); + $this->view->mkdir($uid . '/files_trashbin/share-keys/folder1.d7437648723'); + $this->view->file_put_contents($uid . '/files_trashbin/share-keys/file1.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey.d5457864' , 'data'); + $this->view->file_put_contents($uid . '/files_trashbin/share-keys/file1.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey.d5457864' , 'data'); + $this->view->file_put_contents($uid . '/files_trashbin/share-keys/folder1.d7437648723/file2.' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data'); + + $this->view->mkdir($uid . '/files_trashbin/keyfiles'); + $this->view->mkdir($uid . '/files_trashbin/keyfiles/folder1.d7437648723'); + $this->view->file_put_contents($uid . '/files_trashbin/keyfiles/file1.key.d5457864' , 'data'); + $this->view->file_put_contents($uid . '/files_trashbin/keyfiles/folder1.d7437648723/file2.key' , 'data'); + } + + protected function createDummySystemWideKeys() { + $this->view->mkdir('owncloud_private_key'); + $this->view->file_put_contents('owncloud_private_key/systemwide_1.private.key', 'data'); + $this->view->file_put_contents('owncloud_private_key/systemwide_2.private.key', 'data'); + } - $rec = \OC_Preferences::getValue('user1', 'files_encryption', 'recovery_enabled'); - $mig = \OC_Preferences::getValue('user1', 'files_encryption', 'migration_status'); + public function testMigrateToNewFolderStructure() { + + // go back to the state before migration + $this->view->rename('/files_encryption/public_keys', '/public-keys'); + $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.public.key'); + $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.public.key'); + $this->view->rename('/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey', '/public-keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.public.key'); + $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/keys'); + $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/keys'); + $this->view->deleteAll(self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/keys'); + $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', + self::TEST_ENCRYPTION_MIGRATION_USER1 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key'); + $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', + self::TEST_ENCRYPTION_MIGRATION_USER2 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key'); + $this->view->rename(self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.privateKey', + self::TEST_ENCRYPTION_MIGRATION_USER3 . '/files_encryption/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.private.key'); + + $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER1); + $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER2); + $this->createDummyShareKeys(self::TEST_ENCRYPTION_MIGRATION_USER3); + + $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER1); + $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER2); + $this->createDummyFileKeys(self::TEST_ENCRYPTION_MIGRATION_USER3); + + $this->createDummyFilesInTrash(self::TEST_ENCRYPTION_MIGRATION_USER2); + + // no user for system wide mount points + $this->createDummyFileKeys(''); + $this->createDummyShareKeys(''); + + $this->createDummySystemWideKeys(); + + $m = new \OCA\Files_Encryption\Migration(); + $m->reorganizeFolderStructure(); + + // TODO Verify that all files at the right place + $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.publicKey')); + $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.publicKey')); + $this->assertTrue($this->view->file_exists('/files_encryption/public_keys/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.publicKey')); + $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER1); + $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER2); + $this->verifyNewKeyPath(self::TEST_ENCRYPTION_MIGRATION_USER3); + // system wide keys + $this->verifyNewKeyPath(''); + // trash + $this->verifyFilesInTrash(self::TEST_ENCRYPTION_MIGRATION_USER2); - $this->assertEquals(1, $rec); - $this->assertEquals(0, $mig); } - /** - * @param string $table - */ - public function assertTableExist($table) { - $this->assertTrue(OC_DB::tableExists($table), 'Table ' . $table . ' does not exist'); + protected function verifyFilesInTrash($uid) { + // share keys + $this->view->file_exists($uid . '/files_trashbin/keys/file1.d5457864/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey.d5457864' , 'data'); + $this->view->file_exists($uid . '/files_trashbin/keys/file1.d5457864/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey.d5457864' , 'data'); + $this->view->file_exists($uid . '/files_trashbin/keys/folder1.d7437648723/file2/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey' , 'data'); + + // file keys + $this->view->file_exists($uid . '/files_trashbin/keys/file1.d5457864/fileKey.d5457864' , 'data'); + $this->view->file_exists($uid . '/files_trashbin/keyfiles/file1.d5457864/fileKey.d5457864' , 'data'); + $this->view->file_exists($uid . '/files_trashbin/keyfiles/folder1.d7437648723/file2/fileKey' , 'data'); } - /** - * @param string $table - */ - public function assertTableNotExist($table) { - $type=OC_Config::getValue( "dbtype", "sqlite" ); - if( $type == 'sqlite' || $type == 'sqlite3' ) { - // sqlite removes the tables after closing the DB - $this->assertTrue(true); - } else { - $this->assertFalse(OC_DB::tableExists($table), 'Table ' . $table . ' exists.'); + protected function verifyNewKeyPath($uid) { + // private key + if ($uid !== '') { + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/' . $uid . '.privateKey')); + } + // file keys + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/folder3/file3/fileKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/file2/fileKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/file.1/fileKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/fileKey')); + // share keys + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/folder3/file3/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/folder3/file3/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/folder3/file3/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/file2/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/file2/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/folder2/file2/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/file.1/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/file.1/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder1/file.1/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . self::TEST_ENCRYPTION_MIGRATION_USER1 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . self::TEST_ENCRYPTION_MIGRATION_USER2 . '.shareKey')); + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . self::TEST_ENCRYPTION_MIGRATION_USER3 . '.shareKey')); + if ($this->public_share_key_id) { + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . $this->public_share_key_id . '.shareKey')); + } + if ($this->recovery_key_id) { + $this->assertTrue($this->view->file_exists($uid . '/files_encryption/keys/folder2/file.2.1/' . $this->recovery_key_id . '.shareKey')); } } - } diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index a91222327f1..72a9a9a5551 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -44,20 +44,6 @@ class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase { public static function setUpBeforeClass() { parent::setUpBeforeClass(); - // reset backend - \OC_User::clearBackends(); - \OC_User::useBackend('database'); - - \OC_Hook::clear('OC_Filesystem'); - \OC_Hook::clear('OC_User'); - - // Filesystem related hooks - \OCA\Encryption\Helper::registerFilesystemHooks(); - - // clear and register hooks - \OC_FileProxy::clearProxies(); - \OC_FileProxy::register(new OCA\Encryption\Proxy()); - // create test user self::loginHelper(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1, true); } @@ -85,14 +71,6 @@ class Test_Encryption_Proxy extends \OCA\Files_Encryption\Tests\TestCase { // cleanup test user \OC_User::deleteUser(\Test_Encryption_Proxy::TEST_ENCRYPTION_PROXY_USER1); - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index d7afc9e2da7..f827017569f 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -47,30 +47,15 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { public static function setUpBeforeClass() { parent::setUpBeforeClass(); - // reset backend - \OC_User::clearBackends(); - \OC_User::useBackend('database'); - // enable resharing \OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes'); - // clear share hooks - \OC_Hook::clear('OCP\\Share'); - // register share hooks \OC::registerShareHooks(); \OCA\Files_Sharing\Helper::registerHooks(); - // Sharing related hooks - \OCA\Encryption\Helper::registerShareHooks(); - - // Filesystem related hooks - \OCA\Encryption\Helper::registerFilesystemHooks(); - // clear and register hooks - \OC_FileProxy::clearProxies(); \OC_FileProxy::register(new OCA\Files\Share\Proxy()); - \OC_FileProxy::register(new OCA\Encryption\Proxy()); // create users self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true); @@ -127,14 +112,6 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3); \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4); - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } @@ -915,8 +892,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { $this->assertGreaterThan(0, $fileInfo['unencrypted_size']); // break users public key - $this->view->rename('/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey', - '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup'); + $this->view->rename(\OCA\Encryption\Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey', + \OCA\Encryption\Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup'); // re-enable the file proxy \OC_FileProxy::$enabled = $proxyStatus; @@ -943,8 +920,8 @@ class Test_Encryption_Share extends \OCA\Files_Encryption\Tests\TestCase { // break user1 public key $this->view->rename( - '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup', - '/public-keys/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey'); + \OCA\Encryption\Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey_backup', + \OCA\Encryption\Keymanager::getPublicKeyPath() . '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.publicKey'); // remove share file $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index b1404ca282a..f4824935ca0 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -42,17 +42,6 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase { public static function setUpBeforeClass() { parent::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 self::loginHelper(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1, true); } @@ -94,14 +83,6 @@ class Test_Encryption_Stream extends \OCA\Files_Encryption\Tests\TestCase { // cleanup test user \OC_User::deleteUser(\Test_Encryption_Stream::TEST_ENCRYPTION_STREAM_USER1); - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } diff --git a/apps/files_encryption/tests/testcase.php b/apps/files_encryption/tests/testcase.php index 3106aeda8ea..743a876ab45 100644 --- a/apps/files_encryption/tests/testcase.php +++ b/apps/files_encryption/tests/testcase.php @@ -14,6 +14,7 @@ use OCA\Encryption; * Class Test_Encryption_TestCase */ abstract class TestCase extends \Test\TestCase { + /** * @param string $user * @param bool $create @@ -50,4 +51,34 @@ abstract class TestCase extends \Test\TestCase { \OC_User::setUserId(false); \OC\Files\Filesystem::tearDown(); } + + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + + // reset backend + \OC_User::clearBackends(); + \OC_User::useBackend('database'); + + \OCA\Encryption\Helper::registerFilesystemHooks(); + \OCA\Encryption\Helper::registerUserHooks(); + \OCA\Encryption\Helper::registerShareHooks(); + + \OC::registerShareHooks(); + \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); + + // clear and register hooks + \OC_FileProxy::clearProxies(); + \OC_FileProxy::register(new \OCA\Encryption\Proxy()); + } + + public static function tearDownAfterClass() { + \OC_Hook::clear(); + \OC_FileProxy::clearProxies(); + + // Delete keys in /data/ + $view = new \OC\Files\View('/'); + $view->deleteAll('files_encryption'); + + parent::tearDownAfterClass(); + } } diff --git a/apps/files_encryption/tests/trashbin.php b/apps/files_encryption/tests/trashbin.php index 229fd084807..de5b8bd6edb 100755 --- a/apps/files_encryption/tests/trashbin.php +++ b/apps/files_encryption/tests/trashbin.php @@ -45,23 +45,9 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase { public static function setUpBeforeClass() { parent::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 self::loginHelper(self::TEST_ENCRYPTION_TRASHBIN_USER1, true); } @@ -107,14 +93,6 @@ class Test_Encryption_Trashbin extends \OCA\Files_Encryption\Tests\TestCase { // cleanup test user \OC_User::deleteUser(self::TEST_ENCRYPTION_TRASHBIN_USER1); - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index 96e8fcd81fe..8d9aba423cd 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -43,12 +43,6 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { public static function setUpBeforeClass() { parent::setUpBeforeClass(); - // reset backend - \OC_User::clearBackends(); - \OC_User::useBackend('database'); - - self::setupHooks(); - // create test user self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1, true); self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER2, true); @@ -85,7 +79,7 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { $this->genPublicKey = $keypair['publicKey']; $this->genPrivateKey = $keypair['privateKey']; - $this->publicKeyDir = '/' . 'public-keys'; + $this->publicKeyDir = \OCA\Encryption\Keymanager::getPublicKeyPath(); $this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption'; $this->keysPath = $this->encryptionDir . '/' . 'keys'; $this->publicKeyPath = @@ -126,26 +120,9 @@ class Test_Encryption_Util extends \OCA\Files_Encryption\Tests\TestCase { \OC_Group::deleteGroup(self::TEST_ENCRYPTION_UTIL_GROUP1); \OC_Group::deleteGroup(self::TEST_ENCRYPTION_UTIL_GROUP2); - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } - public static function setupHooks() { - // Filesystem related hooks - \OCA\Encryption\Helper::registerFilesystemHooks(); - - // clear and register hooks - \OC_FileProxy::clearProxies(); - \OC_FileProxy::register(new OCA\Encryption\Proxy()); - } - /** * @medium * test that paths set during User construction are correct diff --git a/apps/files_encryption/tests/webdav.php b/apps/files_encryption/tests/webdav.php index d0caf08b2df..a04a7621291 100755 --- a/apps/files_encryption/tests/webdav.php +++ b/apps/files_encryption/tests/webdav.php @@ -45,20 +45,6 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { public static function setUpBeforeClass() { parent::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 self::loginHelper(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1, true); @@ -106,14 +92,6 @@ class Test_Encryption_Webdav extends \OCA\Files_Encryption\Tests\TestCase { // cleanup test user \OC_User::deleteUser(\Test_Encryption_Webdav::TEST_ENCRYPTION_WEBDAV_USER1); - \OC_Hook::clear(); - \OC_FileProxy::clearProxies(); - - // Delete keys in /data/ - $view = new \OC\Files\View('/'); - $view->rmdir('public-keys'); - $view->rmdir('owncloud_private_key'); - parent::tearDownAfterClass(); } |