示例#1
0
 /**
  * @dataProvider dataBackupAllKeys
  */
 function testRestoreBackup($addTimestamp, $includeUserKeys)
 {
     $util = new \OCA\Files_Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1);
     $this->createDummyKeysForBackupTest();
     $util->backupAllKeys('restoreKeysBackupTest', $addTimestamp, $includeUserKeys);
     $this->view->deleteAll($this->keysPath);
     if ($includeUserKeys) {
         $this->view->unlink($this->privateKeyPath);
         $this->view->unlink($this->publicKeyPath);
     }
     // key should be removed after backup was created
     $this->assertFalse($this->view->is_dir($this->keysPath));
     if ($includeUserKeys) {
         $this->assertFalse($this->view->file_exists($this->privateKeyPath));
         $this->assertFalse($this->view->file_exists($this->publicKeyPath));
     }
     $backupPath = $this->getBackupPath('restoreKeysBackupTest');
     $backupName = substr(basename($backupPath), strlen('backup.'));
     $this->assertTrue($util->restoreBackup($backupName));
     // check if all keys are restored
     $this->assertFalse($this->view->is_dir($backupPath));
     $this->assertTrue($this->view->is_dir($this->keysPath));
     $this->assertTrue($this->view->is_dir($this->keysPath . '/foo'));
     $this->assertTrue($this->view->file_exists($this->keysPath . '/foo/fileKey'));
     $this->assertTrue($this->view->file_exists($this->keysPath . '/foo/user1.shareKey'));
     $this->assertTrue($this->view->file_exists($this->privateKeyPath));
     $this->assertTrue($this->view->file_exists($this->publicKeyPath));
 }
示例#2
0
<?php

OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$l = \OC::$server->getL10N('settings');
$util = new \OCA\Files_Encryption\Util(new \OC\Files\View(), \OC_User::getUser());
$result = $util->restoreBackup('decryptAll');
if ($result) {
    \OCP\JSON::success(array('data' => array('message' => $l->t('Backups restored successfully'))));
} else {
    \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t restore your encryption keys, please check your owncloud.log or ask your administrator'))));
}