diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-11-20 14:22:00 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-12-03 08:03:57 +0100 |
commit | cc80339b39d998c615a5648d2c86b1e431a8b023 (patch) | |
tree | 3fed2c67f37db1e9746bc79013f17a2463896d73 /tests | |
parent | e5c95eed69a1d5e96b69147e4e7f6e40d21c8f9b (diff) | |
download | nextcloud-server-cc80339b39d998c615a5648d2c86b1e431a8b023.tar.gz nextcloud-server-cc80339b39d998c615a5648d2c86b1e431a8b023.zip |
Add typed create user events
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Files/Config/UserMountCacheTest.php | 3 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/EncryptionTest.php | 7 | ||||
-rw-r--r-- | tests/lib/Files/Stream/EncryptionTest.php | 3 | ||||
-rw-r--r-- | tests/lib/User/ManagerTest.php | 78 | ||||
-rw-r--r-- | tests/lib/User/SessionTest.php | 52 |
5 files changed, 81 insertions, 62 deletions
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index d63693a655b..2f61f634ffb 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -13,6 +13,7 @@ use OC\Files\Mount\MountPoint; use OC\Files\Storage\Storage; use OC\Log; use OC\User\Manager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\ICachedMountInfo; use OCP\IConfig; use OCP\IDBConnection; @@ -45,7 +46,7 @@ class UserMountCacheTest extends TestCase { protected function setUp(): void { $this->fileIds = []; $this->connection = \OC::$server->getDatabaseConnection(); - $this->userManager = new Manager($this->createMock(IConfig::class), $this->createMock(EventDispatcherInterface::class)); + $this->userManager = new Manager($this->createMock(IConfig::class), $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)); $userBackend = new Dummy(); $userBackend->createUser('u1', ''); $userBackend->createUser('u2', ''); diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index 95ee0ada24f..a9d678e76e9 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -14,6 +14,7 @@ use OC\User\Manager; use OCP\Encryption\IEncryptionModule; use OCP\Encryption\IFile; use OCP\Encryption\Keys\IStorage; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICache; use OCP\Files\Mount\IMountPoint; use OCP\IConfig; @@ -131,7 +132,7 @@ class EncryptionTest extends Storage { $this->util = $this->getMockBuilder('\OC\Encryption\Util') ->setMethods(['getUidAndFilename', 'isFile', 'isExcluded']) - ->setConstructorArgs([new View(), new Manager($this->config, $this->createMock(EventDispatcherInterface::class)), $this->groupManager, $this->config, $this->arrayCache]) + ->setConstructorArgs([new View(), new Manager($this->config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); $this->util->expects($this->any()) ->method('getUidAndFilename') @@ -568,7 +569,7 @@ class EncryptionTest extends Storage { ->setConstructorArgs( [ new View(), - new Manager($this->config, $this->createMock(EventDispatcherInterface::class)), + new Manager($this->config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $this->groupManager, $this->config, $this->arrayCache @@ -637,7 +638,7 @@ class EncryptionTest extends Storage { ->willReturn($exists); $util = $this->getMockBuilder('\OC\Encryption\Util') - ->setConstructorArgs([new View(), new Manager($this->config, $this->createMock(EventDispatcherInterface::class)), $this->groupManager, $this->config, $this->arrayCache]) + ->setConstructorArgs([new View(), new Manager($this->config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') diff --git a/tests/lib/Files/Stream/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php index 3ded6ef91d6..fd5e8c6ca9d 100644 --- a/tests/lib/Files/Stream/EncryptionTest.php +++ b/tests/lib/Files/Stream/EncryptionTest.php @@ -5,6 +5,7 @@ namespace Test\Files\Stream; use OC\Files\Cache\CacheEntry; use OC\Files\View; use OC\Memcache\ArrayCache; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICache; use OCP\IConfig; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -48,7 +49,7 @@ class EncryptionTest extends \Test\TestCase { $file->expects($this->any())->method('getAccessList')->willReturn([]); $util = $this->getMockBuilder('\OC\Encryption\Util') ->setMethods(['getUidAndFilename']) - ->setConstructorArgs([new View(), new \OC\User\Manager($config, $this->createMock(EventDispatcherInterface::class)), $groupManager, $config, $arrayCache]) + ->setConstructorArgs([new View(), new \OC\User\Manager($config, $this->createMock(EventDispatcherInterface::class), $this->createMock(IEventDispatcher::class)), $groupManager, $config, $arrayCache]) ->getMock(); $util->expects($this->any()) ->method('getUidAndFilename') diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index 58a6b550658..40197101fd6 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -11,6 +11,7 @@ namespace Test\User; use OC\AllConfig; use OC\User\Database; use OC\User\Manager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IUser; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -28,18 +29,21 @@ class ManagerTest extends TestCase { /** @var IConfig */ private $config; /** @var EventDispatcherInterface */ - private $dispatcher; + private $oldDispatcher; + /** @var IEventDispatcher */ + private $eventDispatcher; protected function setUp(): void { parent::setUp(); $this->config = $this->createMock(IConfig::class); - $this->dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->oldDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); } public function testGetBackends() { $userDummyBackend = $this->createMock(\Test\Util\User\Dummy::class); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($userDummyBackend); $this->assertEquals([$userDummyBackend], $manager->getBackends()); $dummyDatabaseBackend = $this->createMock(Database::class); @@ -58,7 +62,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertTrue($manager->userExists('foo')); @@ -74,14 +78,14 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertFalse($manager->userExists('foo')); } public function testUserExistsNoBackends() { - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $this->assertFalse($manager->userExists('foo')); } @@ -105,7 +109,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -129,7 +133,7 @@ class ManagerTest extends TestCase { $backend2->expects($this->never()) ->method('userExists'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -156,7 +160,7 @@ class ManagerTest extends TestCase { } })); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $user = $manager->checkPassword('foo', 'bar'); @@ -175,7 +179,7 @@ class ManagerTest extends TestCase { ->method('implementsActions') ->will($this->returnValue(false)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertFalse($manager->checkPassword('foo', 'bar')); @@ -193,7 +197,7 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertEquals('foo', $manager->get('foo')->getUID()); @@ -209,7 +213,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertEquals(null, $manager->get('foo')); @@ -227,7 +231,7 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID()); @@ -245,7 +249,7 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $result = $manager->search('fo'); @@ -279,7 +283,7 @@ class ManagerTest extends TestCase { $backend2->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -333,7 +337,7 @@ class ManagerTest extends TestCase { ->willReturn(true); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->expectException(\InvalidArgumentException::class, $exception); @@ -360,14 +364,14 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('loginName2UserName'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $user = $manager->createUser('foo', 'bar'); $this->assertEquals('foo', $user->getUID()); } - + public function testCreateUserSingleBackendExists() { $this->expectException(\Exception::class); @@ -387,7 +391,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $manager->createUser('foo', 'bar'); @@ -408,19 +412,19 @@ class ManagerTest extends TestCase { $backend->expects($this->never()) ->method('userExists'); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $this->assertFalse($manager->createUser('foo', 'bar')); } public function testCreateUserNoBackends() { - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $this->assertFalse($manager->createUser('foo', 'bar')); } - + public function testCreateUserFromBackendWithBackendError() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Could not create user'); @@ -435,11 +439,11 @@ class ManagerTest extends TestCase { ->with('MyUid', 'MyPassword') ->willReturn(false); - $manager = new Manager($config, $this->dispatcher); + $manager = new Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->createUserFromBackend('MyUid', 'MyPassword', $backend); } - + public function testCreateUserTwoBackendExists() { $this->expectException(\Exception::class); @@ -475,7 +479,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -483,7 +487,7 @@ class ManagerTest extends TestCase { } public function testCountUsersNoBackend() { - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $result = $manager->countUsers(); $this->assertTrue(is_array($result)); @@ -508,7 +512,7 @@ class ManagerTest extends TestCase { ->method('getBackendName') ->will($this->returnValue('Mock_Test_Util_User_Dummy')); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $result = $manager->countUsers(); @@ -549,7 +553,7 @@ class ManagerTest extends TestCase { ->method('getBackendName') ->will($this->returnValue('Mock_Test_Util_User_Dummy')); - $manager = new \OC\User\Manager($this->config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend1); $manager->registerBackend($backend2); @@ -650,21 +654,7 @@ class ManagerTest extends TestCase { } public function testDeleteUser() { - $config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $config - ->expects($this->at(0)) - ->method('getUserValue') - ->with('foo', 'core', 'enabled') - ->will($this->returnValue(true)); - $config - ->expects($this->at(1)) - ->method('getUserValue') - ->with('foo', 'login', 'lastLogin') - ->will($this->returnValue(0)); - - $manager = new \OC\User\Manager($config, $this->dispatcher); + $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher); $backend = new \Test\Util\User\Dummy(); $manager->registerBackend($backend); @@ -698,7 +688,7 @@ class ManagerTest extends TestCase { ->with($this->equalTo('uid2')) ->will($this->returnValue(true)); - $manager = new \OC\User\Manager($config, $this->dispatcher); + $manager = new \OC\User\Manager($config, $this->oldDispatcher, $this->eventDispatcher); $manager->registerBackend($backend); $users = $manager->getByEmail('test@example.com'); diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index 3567aa9cf62..e7df7578c7d 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -228,7 +228,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); @@ -271,7 +275,7 @@ class SessionTest extends \Test\TestCase { $this->assertEquals($user, $userSession->getUser()); } - + public function testLoginValidPasswordDisabled() { $this->expectException(\OC\User\LoginException::class); @@ -290,11 +294,13 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); - $backend = $this->createMock(\Test\Util\User\Dummy::class); - $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('isEnabled') @@ -321,7 +327,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $backend = $this->createMock(\Test\Util\User\Dummy::class); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher); @@ -404,7 +414,7 @@ class SessionTest extends \Test\TestCase { $userSession->login('foo', 'bar'); } - + public function testLogClientInNoTokenPasswordWith2fa() { $this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class); @@ -508,7 +518,7 @@ class SessionTest extends \Test\TestCase { $this->assertTrue($userSession->logClientIn('john', 'I-AM-AN-APP-PASSWORD', $request, $this->throttler)); } - + public function testLogClientInNoTokenPasswordNo2fa() { $this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class); @@ -560,7 +570,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $userSession = $this->getMockBuilder(Session::class) //override, otherwise tests will fail because of setcookie() @@ -645,7 +659,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $userSession = $this->getMockBuilder(Session::class) //override, otherwise tests will fail because of setcookie() @@ -705,7 +723,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $userSession = $this->getMockBuilder(Session::class) //override, otherwise tests will fail because of setcookie() @@ -753,7 +775,11 @@ class SessionTest extends \Test\TestCase { $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $manager = $this->getMockBuilder(Manager::class) ->setMethods($mockedManagerMethods) - ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) + ->setConstructorArgs([ + $this->config, + $this->createMock(EventDispatcherInterface::class), + $this->createMock(IEventDispatcher::class) + ]) ->getMock(); $userSession = $this->getMockBuilder(Session::class) //override, otherwise tests will fail because of setcookie() @@ -973,7 +999,7 @@ class SessionTest extends \Test\TestCase { $this->assertFalse($userSession->createSessionToken($request, $uid, $loginName, $password)); } - + public function testTryTokenLoginWithDisabledUser() { $this->expectException(\OC\User\LoginException::class); |