summaryrefslogtreecommitdiffstats
path: root/tests/lib/User
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-11-20 14:22:00 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2019-12-03 08:03:57 +0100
commitcc80339b39d998c615a5648d2c86b1e431a8b023 (patch)
tree3fed2c67f37db1e9746bc79013f17a2463896d73 /tests/lib/User
parente5c95eed69a1d5e96b69147e4e7f6e40d21c8f9b (diff)
downloadnextcloud-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/lib/User')
-rw-r--r--tests/lib/User/ManagerTest.php78
-rw-r--r--tests/lib/User/SessionTest.php52
2 files changed, 73 insertions, 57 deletions
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);