-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(users): Don't crash if disabled user is missing in the database
Signed-off-by: Louis Chemineau <[email protected]> [skip ci] Signed-off-by: Louis Chemineau <[email protected]>
- Loading branch information
Showing
8 changed files
with
65 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
use OCP\ICacheFactory; | ||
use OCP\IConfig; | ||
use OCP\IUser; | ||
use Psr\Log\LoggerInterface; | ||
use Test\TestCase; | ||
|
||
/** | ||
|
@@ -34,6 +35,8 @@ class ManagerTest extends TestCase { | |
private $cacheFactory; | ||
/** @var ICache */ | ||
private $cache; | ||
/** @var LoggerInterface */ | ||
private $logger; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
@@ -42,14 +45,15 @@ protected function setUp(): void { | |
$this->eventDispatcher = $this->createMock(IEventDispatcher::class); | ||
$this->cacheFactory = $this->createMock(ICacheFactory::class); | ||
$this->cache = $this->createMock(ICache::class); | ||
$this->logger = $this->createMock(LoggerInterface::class); | ||
|
||
$this->cacheFactory->method('createDistributed') | ||
->willReturn($this->cache); | ||
} | ||
|
||
public function testGetBackends() { | ||
$userDummyBackend = $this->createMock(\Test\Util\User\Dummy::class); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($userDummyBackend); | ||
$this->assertEquals([$userDummyBackend], $manager->getBackends()); | ||
$dummyDatabaseBackend = $this->createMock(Database::class); | ||
|
@@ -68,7 +72,7 @@ public function testUserExistsSingleBackendExists() { | |
->with($this->equalTo('foo')) | ||
->willReturn(true); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$this->assertTrue($manager->userExists('foo')); | ||
|
@@ -84,7 +88,7 @@ public function testUserExistsSingleBackendNotExists() { | |
->with($this->equalTo('foo')) | ||
->willReturn(false); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$this->assertFalse($manager->userExists('foo')); | ||
|
@@ -115,7 +119,7 @@ public function testUserExistsTwoBackendsSecondExists() { | |
->with($this->equalTo('foo')) | ||
->willReturn(true); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend1); | ||
$manager->registerBackend($backend2); | ||
|
||
|
@@ -139,7 +143,7 @@ public function testUserExistsTwoBackendsFirstExists() { | |
$backend2->expects($this->never()) | ||
->method('userExists'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend1); | ||
$manager->registerBackend($backend2); | ||
|
||
|
@@ -166,7 +170,7 @@ public function testCheckPassword() { | |
} | ||
}); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$user = $manager->checkPassword('foo', 'bar'); | ||
|
@@ -185,7 +189,7 @@ public function testCheckPasswordNotSupported() { | |
->method('implementsActions') | ||
->willReturn(false); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$this->assertFalse($manager->checkPassword('foo', 'bar')); | ||
|
@@ -203,7 +207,7 @@ public function testGetOneBackendExists() { | |
$backend->expects($this->never()) | ||
->method('loginName2UserName'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$this->assertEquals('foo', $manager->get('foo')->getUID()); | ||
|
@@ -219,7 +223,7 @@ public function testGetOneBackendNotExists() { | |
->with($this->equalTo('foo')) | ||
->willReturn(false); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$this->assertEquals(null, $manager->get('foo')); | ||
|
@@ -237,7 +241,7 @@ public function testGetOneBackendDoNotTranslateLoginNames() { | |
$backend->expects($this->never()) | ||
->method('loginName2UserName'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID()); | ||
|
@@ -255,7 +259,7 @@ public function testSearchOneBackend() { | |
$backend->expects($this->never()) | ||
->method('loginName2UserName'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$result = $manager->search('fo'); | ||
|
@@ -289,7 +293,7 @@ public function testSearchTwoBackendLimitOffset() { | |
$backend2->expects($this->never()) | ||
->method('loginName2UserName'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend1); | ||
$manager->registerBackend($backend2); | ||
|
||
|
@@ -343,7 +347,7 @@ public function testCreateUserInvalid($uid, $password, $exception) { | |
->willReturn(true); | ||
|
||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$this->expectException(\InvalidArgumentException::class, $exception); | ||
|
@@ -370,7 +374,7 @@ public function testCreateUserSingleBackendNotExists() { | |
$backend->expects($this->never()) | ||
->method('loginName2UserName'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$user = $manager->createUser('foo', 'bar'); | ||
|
@@ -397,7 +401,7 @@ public function testCreateUserSingleBackendExists() { | |
->with($this->equalTo('foo')) | ||
->willReturn(true); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$manager->createUser('foo', 'bar'); | ||
|
@@ -418,7 +422,7 @@ public function testCreateUserSingleBackendNotSupported() { | |
$backend->expects($this->never()) | ||
->method('userExists'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$this->assertFalse($manager->createUser('foo', 'bar')); | ||
|
@@ -445,7 +449,7 @@ public function testCreateUserFromBackendWithBackendError() { | |
->with('MyUid', 'MyPassword') | ||
->willReturn(false); | ||
|
||
$manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->createUserFromBackend('MyUid', 'MyPassword', $backend); | ||
} | ||
|
||
|
@@ -485,7 +489,7 @@ public function testCreateUserTwoBackendExists() { | |
->with($this->equalTo('foo')) | ||
->willReturn(true); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend1); | ||
$manager->registerBackend($backend2); | ||
|
||
|
@@ -518,7 +522,7 @@ public function testCountUsersOneBackend() { | |
->method('getBackendName') | ||
->willReturn('Mock_Test_Util_User_Dummy'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$result = $manager->countUsers(); | ||
|
@@ -559,7 +563,7 @@ public function testCountUsersTwoBackends() { | |
->method('getBackendName') | ||
->willReturn('Mock_Test_Util_User_Dummy'); | ||
|
||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($this->config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend1); | ||
$manager->registerBackend($backend2); | ||
|
||
|
@@ -672,7 +676,7 @@ public function testDeleteUser() { | |
->method('getAppValue') | ||
->willReturnArgument(2); | ||
|
||
$manager = new \OC\User\Manager($config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$backend = new \Test\Util\User\Dummy(); | ||
|
||
$manager->registerBackend($backend); | ||
|
@@ -706,7 +710,7 @@ public function testGetByEmail() { | |
true | ||
); | ||
|
||
$manager = new \OC\User\Manager($config, $this->cacheFactory, $this->eventDispatcher); | ||
$manager = new \OC\User\Manager($config, $this->cacheFactory, $this->eventDispatcher, $this->logger); | ||
$manager->registerBackend($backend); | ||
|
||
$users = $manager->getByEmail('[email protected]'); | ||
|
Oops, something went wrong.