Commit 00adeafd authored by Vincent Petry's avatar Vincent Petry Committed by GitHub
Browse files

Merge pull request #26968 from owncloud/enc-properly-deletekeys

Ignore exception when deleting keys of deleted user
parents 8dfc27db 933ee8c6
......@@ -137,9 +137,9 @@ class UserHooks implements IHook {
'postCreateUser');
OCUtil::connectHook('OC_User',
'pre_deleteUser',
'post_deleteUser',
$this,
'preDeleteUser');
'postDeleteUser');
}
}
......@@ -194,7 +194,7 @@ class UserHooks implements IHook {
* @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']);
......
......@@ -108,12 +108,12 @@ class UserHooksTest extends TestCase {
$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);
}
......
......@@ -28,6 +28,7 @@ use OC\Files\Filesystem;
use OC\Files\View;
use OCP\Encryption\Keys\IStorage;
use OCP\IUserSession;
use OC\User\NoUserException;
class Storage implements IStorage {
......@@ -138,8 +139,21 @@ class Storage implements IStorage {
* @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.
}
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment