diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-10-17 18:21:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-17 18:21:57 +0200 |
commit | 658aa1a2ddf2b0eee0b32d907ce49bbbc5fd0460 (patch) | |
tree | 6d36f7424c0de4edf7beb1fdfdb39bd00be53fc1 /tests | |
parent | 93e4d2dabfbb885a8bc67469fae2da5c74bf0590 (diff) | |
parent | 7dc1c7f7628f44e8c2544917c272be1ed20ab89c (diff) | |
download | nextcloud-server-658aa1a2ddf2b0eee0b32d907ce49bbbc5fd0460.tar.gz nextcloud-server-658aa1a2ddf2b0eee0b32d907ce49bbbc5fd0460.zip |
Merge pull request #48588 from nextcloud/backport/47896/stable29
[stable29] fix: Make user removal more resilient
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Traits/UserTrait.php | 3 | ||||
-rw-r--r-- | tests/lib/User/UserTest.php | 81 |
2 files changed, 70 insertions, 14 deletions
diff --git a/tests/lib/Traits/UserTrait.php b/tests/lib/Traits/UserTrait.php index 3f7cfe419db..d2c1444c943 100644 --- a/tests/lib/Traits/UserTrait.php +++ b/tests/lib/Traits/UserTrait.php @@ -9,13 +9,16 @@ namespace Test\Traits; use OC\User\User; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IUser; +use OCP\Server; class DummyUser extends User { private string $uid; public function __construct(string $uid) { $this->uid = $uid; + parent::__construct($uid, null, Server::get(IEventDispatcher::class)); } public function getUID(): string { diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index 806cb094066..965dd65aeab 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -514,14 +514,25 @@ class UserTest extends TestCase { $test = $this; /** - * @var Backend | MockObject $backend + * @var UserInterface&MockObject $backend */ $backend = $this->createMock(\Test\Util\User\Dummy::class); $backend->expects($this->once()) ->method('deleteUser') ->willReturn($result); + + $config = $this->createMock(IConfig::class); + $config->method('getSystemValue') + ->willReturnArgument(1); + $config->method('getSystemValueString') + ->willReturnArgument(1); + $config->method('getSystemValueBool') + ->willReturnArgument(1); + $config->method('getSystemValueInt') + ->willReturnArgument(1); + $emitter = new PublicEmitter(); - $user = new User('foo', $backend, $this->dispatcher, $emitter); + $user = new User('foo', $backend, $this->dispatcher, $emitter, $config); /** * @param User $user @@ -534,21 +545,11 @@ class UserTest extends TestCase { $emitter->listen('\OC\User', 'preDelete', $hook); $emitter->listen('\OC\User', 'postDelete', $hook); - $config = $this->createMock(IConfig::class); $commentsManager = $this->createMock(ICommentsManager::class); $notificationManager = $this->createMock(INotificationManager::class); - $config->method('getSystemValue') - ->willReturnArgument(1); - $config->method('getSystemValueString') - ->willReturnArgument(1); - $config->method('getSystemValueBool') - ->willReturnArgument(1); - $config->method('getSystemValueInt') - ->willReturnArgument(1); - if ($result) { - $config->expects($this->once()) + $config->expects($this->atLeastOnce()) ->method('deleteAllUserValues') ->with('foo'); @@ -587,7 +588,6 @@ class UserTest extends TestCase { $this->overwriteService(\OCP\Notification\IManager::class, $notificationManager); $this->overwriteService(\OCP\Comments\ICommentsManager::class, $commentsManager); - $this->overwriteService(AllConfig::class, $config); $this->assertSame($result, $user->delete()); @@ -598,6 +598,59 @@ class UserTest extends TestCase { $this->assertEquals($expectedHooks, $hooksCalled); } + public function testDeleteRecoverState() { + $backend = $this->createMock(\Test\Util\User\Dummy::class); + $backend->expects($this->once()) + ->method('deleteUser') + ->willReturn(true); + + $config = $this->createMock(IConfig::class); + $config->method('getSystemValue') + ->willReturnArgument(1); + $config->method('getSystemValueString') + ->willReturnArgument(1); + $config->method('getSystemValueBool') + ->willReturnArgument(1); + $config->method('getSystemValueInt') + ->willReturnArgument(1); + + $userConfig = []; + $config->expects(self::atLeast(2)) + ->method('setUserValue') + ->willReturnCallback(function () { + $userConfig[] = func_get_args(); + }); + + $commentsManager = $this->createMock(ICommentsManager::class); + $commentsManager->expects($this->once()) + ->method('deleteReferencesOfActor') + ->willThrowException(new \Error('Test exception')); + + $this->overwriteService(\OCP\Comments\ICommentsManager::class, $commentsManager); + $this->expectException(\Error::class); + + $user = $this->getMockBuilder(User::class) + ->onlyMethods(['getHome']) + ->setConstructorArgs(['foo', $backend, $this->dispatcher, null, $config]) + ->getMock(); + + $user->expects(self::atLeastOnce()) + ->method('getHome') + ->willReturn('/home/path'); + + $user->delete(); + + $this->assertEqualsCanonicalizing( + [ + ['foo', 'core', 'deleted', 'true', null], + ['foo', 'core', 'deleted.backup-home', '/home/path', null], + ], + $userConfig, + ); + + $this->restoreService(\OCP\Comments\ICommentsManager::class); + } + public function dataGetCloudId(): array { return [ ['https://localhost:8888/nextcloud', 'foo@localhost:8888/nextcloud'], |