Skip to content

Commit

Permalink
Fix unit test when restorePossible set for masterkey
Browse files Browse the repository at this point in the history
Fix unit test when restorePossible is set for
masterkey encryption.

Signed-off-by: Sujith H <[email protected]>
  • Loading branch information
sharidas committed Dec 6, 2019
1 parent ba596e8 commit 9916188
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
27 changes: 9 additions & 18 deletions settings/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class UsersController extends Controller {
private $fromMailAddress;
/** @var IURLGenerator */
private $urlGenerator;
/** @var bool contains the state of the encryption app */
private $isEncryptionAppEnabled;
/** @var bool contains the state of the admin recovery setting */
private $isRestoreEnabled = false;
/** @var IAvatarManager */
Expand Down Expand Up @@ -153,8 +151,7 @@ public function __construct($appName,
$this->eventDispatcher = $eventDispatcher;

// check for encryption state - TODO see formatUserForIndex
$this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
if ($this->isEncryptionAppEnabled) {
if ($appManager->isEnabledForUser('encryption')) {
// putting this directly in empty is possible in PHP 5.5+
$result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0);
$this->isRestoreEnabled = !empty($result);
Expand All @@ -176,23 +173,17 @@ private function formatUserForIndex(IUser $user, array $userGroups = null) {
// below
$restorePossible = false;

if ($this->isEncryptionAppEnabled) {
if ($this->isRestoreEnabled) {
// check for the users recovery setting
$recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0');
// method call inside empty is possible with PHP 5.5+
$recoveryModeEnabled = !empty($recoveryMode);
if ($recoveryModeEnabled) {
// user also has recovery mode enabled
$restorePossible = true;
}
} else {
// masterkey encryption is active
if ($this->isRestoreEnabled) {
// check for the users recovery setting
$recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0');
// method call inside empty is possible with PHP 5.5+
$recoveryModeEnabled = !empty($recoveryMode);
if ($recoveryModeEnabled) {
// user also has recovery mode enabled
$restorePossible = true;
}
} else {
// recovery is possible if encryption is disabled (plain files are
// available)
// masterkey encryption or no encryption in place
$restorePossible = true;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Settings/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ public function testRestoreNotPossibleWithoutAdminRestore() {
)
->will($this->returnValue(true));

$expectedResult['isRestoreDisabled'] = true;
$expectedResult['isRestoreDisabled'] = false;

$subadmin = $this->getMockBuilder('\OC\SubAdmin')
->disableOriginalConstructor()
Expand Down

0 comments on commit 9916188

Please sign in to comment.