Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning when resetting user's password with masterkey encryption #36523

Merged
merged 2 commits into from
Dec 20, 2019

Conversation

pako81
Copy link

@pako81 pako81 commented Dec 4, 2019

Description

Suppress warning when resetting user's password over the Users management page with masterkey encryption enabled.

Related Issue

Motivation and Context

This PR fixes the following warning displayed when the admin is about to reset user's password over the Users management page with masterkey encryption in place:

70141012-5d090880-1696-11ea-90ad-476b4b1d648b

The warning itself does not prevent resetting user's password but it is scary and makes no sense when masterkey encryption is in use.

How Has This Been Tested?

Manually by enabling masterkey encryption and as admin hovering over the password field for one random user: the warning is not displayed anymore.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised
  • Changelog item

@pako81 pako81 self-assigned this Dec 4, 2019
@pako81 pako81 added this to the development milestone Dec 4, 2019
@pako81 pako81 force-pushed the password-reset-masterkey-fix branch from 62a0cde to 5d08d0a Compare December 4, 2019 14:19
@pako81 pako81 requested review from sharidas and micbar December 4, 2019 14:21
@pako81 pako81 force-pushed the password-reset-masterkey-fix branch from 5d08d0a to ba596e8 Compare December 4, 2019 19:40
@phil-davis
Copy link
Contributor

Unit test expectations also need adjusting: https://drone.owncloud.com/owncloud/core/21714/13/9

@codecov
Copy link

codecov bot commented Dec 5, 2019

Codecov Report

Merging #36523 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #36523      +/-   ##
============================================
- Coverage     64.67%   64.67%   -0.01%     
+ Complexity    19099    19098       -1     
============================================
  Files          1268     1268              
  Lines         74695    74693       -2     
  Branches       1320     1320              
============================================
- Hits          48309    48307       -2     
  Misses        25998    25998              
  Partials        388      388
Flag Coverage Δ Complexity Δ
#javascript 54.12% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 65.84% <100%> (-0.01%) 19098 <0> (-1)
Impacted Files Coverage Δ Complexity Δ
settings/Controller/UsersController.php 85.51% <100%> (-0.06%) 131 <0> (-1)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e08811...6e31d51. Read the comment docs.

@@ -186,6 +186,9 @@ private function formatUserForIndex(IUser $user, array $userGroups = null) {
// user also has recovery mode enabled
$restorePossible = true;
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of if's and else would bring down the readability. How about changing this code to:

if ($this->isRestoreEnabled) {
	$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 {
	$restorePossible = true;
}

Copy link
Author

@pako81 pako81 Dec 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharidas thanks for the suggestion!

I guess we can indeed get rid of the if (this->isEncryptionAppEnabled) condition since if ($this->isRestoreEnabled) is basically already performing the same check. This will help us to have better code readability.

Got also rid of any reference to isEncryptionAppEnabled from code.

@pako81 pako81 force-pushed the password-reset-masterkey-fix branch from 79ae211 to 30fb6cb Compare December 5, 2019 11:26
@sharidas sharidas force-pushed the password-reset-masterkey-fix branch from 30fb6cb to 0c6fcf8 Compare December 6, 2019 06:23
@sharidas
Copy link
Contributor

sharidas commented Dec 6, 2019

There was a semi colon added in the proposesd change, due to which the tests were failing. I have removed the semi colon and now the tests should pass.

@sharidas sharidas force-pushed the password-reset-masterkey-fix branch from 0c6fcf8 to 9916188 Compare December 6, 2019 06:45
Copy link
Contributor

@sharidas sharidas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the code looks good to me. I have not tested this. If it works as expected, then Ok from my side.

@phil-davis phil-davis force-pushed the password-reset-masterkey-fix branch from 9916188 to 6e31d51 Compare December 20, 2019 01:21
@phil-davis
Copy link
Contributor

I rebased just now to make sure that CI is still good for this.

@micbar is this to be released?
Needs someone to review/approve.
I added to 10.4 project so it gets noticed - otherwise these PRs seem to just sit and nobody looks at them.

@sharidas
Copy link
Contributor

Tests done

  • With masterkey encryption enabled

    • Create a user in the users page and try to reset the password for the new user. The message related to data recovery is not shown.
  • With user keys encryption

    • Create a user in the users page and try to enable the recovery password for the user.
      • Now try to reset the password. There is no message displayed related to data recovery.
    • Create another user in the users page and do not enable the recovery password for the user
      • Now try to reset the password. There is a message that appears. This is expected behaviour.
  • Tested without encryption

    • All users created in the users page can reset their password gracefully and the data recovery message does not pops up. This behaves as expected.

Copy link
Contributor

@sharidas sharidas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@micbar micbar merged commit fc33551 into master Dec 20, 2019
@delete-merged-branch delete-merged-branch bot deleted the password-reset-masterkey-fix branch December 20, 2019 11:08
@pako81
Copy link
Author

pako81 commented Dec 20, 2019

thanks @phil-davis @sharidas @micbar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants