summaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests/lib/MigrationTest.php
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-07-08 09:25:42 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2015-07-08 13:26:53 +0200
commit876d7c160d7e9701aa7e1931b12ddb8096a8fa83 (patch)
treea04aae0d0e23942363d87709c17b2e52861fde76 /apps/encryption/tests/lib/MigrationTest.php
parent0fe81d2f214c59dbe223e949232475fb8a6f24b9 (diff)
downloadnextcloud-server-876d7c160d7e9701aa7e1931b12ddb8096a8fa83.tar.gz
nextcloud-server-876d7c160d7e9701aa7e1931b12ddb8096a8fa83.zip
more secure way to update the database
Diffstat (limited to 'apps/encryption/tests/lib/MigrationTest.php')
-rw-r--r--apps/encryption/tests/lib/MigrationTest.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/apps/encryption/tests/lib/MigrationTest.php b/apps/encryption/tests/lib/MigrationTest.php
index c07a4539e98..de1e2bd268b 100644
--- a/apps/encryption/tests/lib/MigrationTest.php
+++ b/apps/encryption/tests/lib/MigrationTest.php
@@ -242,6 +242,12 @@ class MigrationTest extends \Test\TestCase {
$config->setAppValue('files_encryption', 'recoveryAdminEnabled', '1');
$config->setUserValue(self::TEST_ENCRYPTION_MIGRATION_USER1, 'files_encryption', 'recoverKeyEnabled', '1');
+ //$this->invokePrivate($config, 'cache', [[]]);
+ $cache = $this->invokePrivate(\OC::$server->getAppConfig(), 'cache');
+ unset($cache['encryption']);
+ unset($cache['files_encryption']);
+ $this->invokePrivate(\OC::$server->getAppConfig(), 'cache', [$cache]);
+
// delete default values set by the encryption app during initialization
/** @var \OC\DB\Connection $connection */
@@ -271,6 +277,58 @@ class MigrationTest extends \Test\TestCase {
}
+ /**
+ * test update db if the db already contain some existing new values
+ */
+ public function testUpdateDBExistingNewConfig() {
+ $this->prepareDB();
+ $config = \OC::$server->getConfig();
+ $config->setAppValue('encryption', 'publicShareKeyId', 'wrong_share_id');
+ $config->setUserValue(self::TEST_ENCRYPTION_MIGRATION_USER1, 'encryption', 'recoverKeyEnabled', '9');
+
+ $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection());
+ $m->updateDB();
+
+ $this->verifyDB('`*PREFIX*appconfig`', 'files_encryption', 0);
+ $this->verifyDB('`*PREFIX*preferences`', 'files_encryption', 0);
+ $this->verifyDB('`*PREFIX*appconfig`', 'encryption', 3);
+ $this->verifyDB('`*PREFIX*preferences`', 'encryption', 1);
+
+ // check if the existing values where overwritten correctly
+ /** @var \OC\DB\Connection $connection */
+ $connection = \OC::$server->getDatabaseConnection();
+ $query = $connection->createQueryBuilder();
+ $query->select('`configvalue`')
+ ->from('`*PREFIX*appconfig`')
+ ->where($query->expr()->andX(
+ $query->expr()->eq('`appid`', ':appid'),
+ $query->expr()->eq('`configkey`', ':configkey')
+ ))
+ ->setParameter('appid', 'encryption')
+ ->setParameter('configkey', 'publicShareKeyId');
+ $result = $query->execute();
+ $value = $result->fetch();
+ $this->assertTrue(isset($value['configvalue']));
+ $this->assertSame('share_id', $value['configvalue']);
+
+ $query = $connection->createQueryBuilder();
+ $query->select('`configvalue`')
+ ->from('`*PREFIX*preferences`')
+ ->where($query->expr()->andX(
+ $query->expr()->eq('`appid`', ':appid'),
+ $query->expr()->eq('`configkey`', ':configkey'),
+ $query->expr()->eq('`userid`', ':userid')
+ ))
+ ->setParameter('appid', 'encryption')
+ ->setParameter('configkey', 'recoverKeyEnabled')
+ ->setParameter('userid', self::TEST_ENCRYPTION_MIGRATION_USER1);
+ $result = $query->execute();
+ $value = $result->fetch();
+ $this->assertTrue(isset($value['configvalue']));
+ $this->assertSame('1', $value['configvalue']);
+
+ }
+
public function verifyDB($table, $appid, $expected) {
/** @var \OC\DB\Connection $connection */
$connection = \OC::$server->getDatabaseConnection();