Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/encryption/lib/Hooks/UserHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public function addHooks() {
'postCreateUser');

OCUtil::connectHook('OC_User',
'pre_deleteUser',
'post_deleteUser',
$this,
'preDeleteUser');
'postDeleteUser');
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public function postCreateUser($params) {
* @param array $params : uid, password
* @note This method should never be called for users using client side encryption
*/
public function preDeleteUser($params) {
public function postDeleteUser($params) {

if (App::isEnabled('encryption')) {
$this->keyManager->deletePublicKey($params['uid']);
Expand Down
4 changes: 2 additions & 2 deletions apps/encryption/tests/Hooks/UserHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ public function testPostCreateUser() {
$this->assertTrue(true);
}

public function testPreDeleteUser() {
public function testPostDeleteUser() {
$this->keyManagerMock->expects($this->once())
->method('deletePublicKey')
->with('testUser');

$this->instance->preDeleteUser($this->params);
$this->instance->postDeleteUser($this->params);
$this->assertTrue(true);
}

Expand Down
18 changes: 16 additions & 2 deletions lib/private/Encryption/Keys/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OC\Files\View;
use OCP\Encryption\Keys\IStorage;
use OCP\IUserSession;
use OC\User\NoUserException;

class Storage implements IStorage {

Expand Down Expand Up @@ -138,8 +139,21 @@ public function setSystemUserKey($keyId, $key, $encryptionModuleId) {
* @inheritdoc
*/
public function deleteUserKey($uid, $keyId, $encryptionModuleId) {
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return !$this->view->file_exists($path) || $this->view->unlink($path);
try {
$path = $this->constructUserKeyPath($encryptionModuleId, $keyId, $uid);
return !$this->view->file_exists($path) || $this->view->unlink($path);
} catch (NoUserException $e) {
// this exception can come from initMountPoints() from setupUserMounts()
// for a deleted user.
//
// It means, that:
// - we are not running in alternative storage mode because we don't call
// initMountPoints() in that mode
// - the keys were in the user's home but since the user was deleted, the
// user's home is gone and so are the keys
//
// So there is nothing to do, just ignore.
}
}

/**
Expand Down