Merge pull request #16579 from nextcloud/enh/PostLoginEvent

Add proper PostLoginEvent
This commit is contained in:
Roeland Jago Douma 2019-07-30 08:54:10 +02:00 committed by GitHub
commit 135209f24e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 153 additions and 46 deletions

View File

@ -1212,6 +1212,7 @@ return array(
'OC\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php', 'OC\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php',
'OC\\User\\Backend' => $baseDir . '/lib/private/User/Backend.php', 'OC\\User\\Backend' => $baseDir . '/lib/private/User/Backend.php',
'OC\\User\\Database' => $baseDir . '/lib/private/User/Database.php', 'OC\\User\\Database' => $baseDir . '/lib/private/User/Database.php',
'OC\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/private/User/Events/PostLoginEvent.php',
'OC\\User\\LoginException' => $baseDir . '/lib/private/User/LoginException.php', 'OC\\User\\LoginException' => $baseDir . '/lib/private/User/LoginException.php',
'OC\\User\\Manager' => $baseDir . '/lib/private/User/Manager.php', 'OC\\User\\Manager' => $baseDir . '/lib/private/User/Manager.php',
'OC\\User\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php', 'OC\\User\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php',

View File

@ -1246,6 +1246,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php', 'OC\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php',
'OC\\User\\Backend' => __DIR__ . '/../../..' . '/lib/private/User/Backend.php', 'OC\\User\\Backend' => __DIR__ . '/../../..' . '/lib/private/User/Backend.php',
'OC\\User\\Database' => __DIR__ . '/../../..' . '/lib/private/User/Database.php', 'OC\\User\\Database' => __DIR__ . '/../../..' . '/lib/private/User/Database.php',
'OC\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/private/User/Events/PostLoginEvent.php',
'OC\\User\\LoginException' => __DIR__ . '/../../..' . '/lib/private/User/LoginException.php', 'OC\\User\\LoginException' => __DIR__ . '/../../..' . '/lib/private/User/LoginException.php',
'OC\\User\\Manager' => __DIR__ . '/../../..' . '/lib/private/User/Manager.php', 'OC\\User\\Manager' => __DIR__ . '/../../..' . '/lib/private/User/Manager.php',
'OC\\User\\NoUserException' => __DIR__ . '/../../..' . '/lib/private/User/NoUserException.php', 'OC\\User\\NoUserException' => __DIR__ . '/../../..' . '/lib/private/User/NoUserException.php',

View File

@ -135,6 +135,7 @@ use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\Contacts\ContactsMenu\IContactsStore; use OCP\Contacts\ContactsMenu\IContactsStore;
use OCP\Dashboard\IDashboardManager; use OCP\Dashboard\IDashboardManager;
use OCP\Defaults; use OCP\Defaults;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager; use OCP\Federation\ICloudFederationProviderManager;
use OCP\Federation\ICloudIdManager; use OCP\Federation\ICloudIdManager;
@ -385,7 +386,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getConfig(), $c->getConfig(),
$c->getSecureRandom(), $c->getSecureRandom(),
$c->getLockdownManager(), $c->getLockdownManager(),
$c->getLogger() $c->getLogger(),
$c->query(IEventDispatcher::class)
); );
$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));

View File

@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\User\Events;
use OCP\EventDispatcher\Event;
use OCP\IUser;
class PostLoginEvent extends Event {
/** @var IUser */
private $user;
/** @var string */
private $password;
/** @var bool */
private $isTokenLogin;
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
parent::__construct();
$this->user = $user;
$this->password = $password;
$this->isTokenLogin = $isTokenLogin;
}
public function getUser(): IUser {
return $this->user;
}
public function hasPassword(): bool {
return $this->password !== '';
}
public function getPassword(): string {
return $this->password;
}
public function getIsTokenLogin(): bool {
return $this->isTokenLogin;
}
}

View File

@ -50,6 +50,7 @@ use OC_User;
use OC_Util; use OC_Util;
use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\Connector\Sabre\Auth;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\NotPermittedException; use OCP\Files\NotPermittedException;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger; use OCP\ILogger;
@ -113,6 +114,8 @@ class Session implements IUserSession, Emitter {
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;
/** @var IEventDispatcher */
private $dispatcher;
/** /**
* @param Manager $manager * @param Manager $manager
@ -131,7 +134,8 @@ class Session implements IUserSession, Emitter {
IConfig $config, IConfig $config,
ISecureRandom $random, ISecureRandom $random,
ILockdownManager $lockdownManager, ILockdownManager $lockdownManager,
ILogger $logger) { ILogger $logger,
IEventDispatcher $dispatcher) {
$this->manager = $manager; $this->manager = $manager;
$this->session = $session; $this->session = $session;
$this->timeFactory = $timeFactory; $this->timeFactory = $timeFactory;
@ -140,6 +144,7 @@ class Session implements IUserSession, Emitter {
$this->random = $random; $this->random = $random;
$this->lockdownManager = $lockdownManager; $this->lockdownManager = $lockdownManager;
$this->logger = $logger; $this->logger = $logger;
$this->dispatcher = $dispatcher;
} }
/** /**
@ -369,6 +374,14 @@ class Session implements IUserSession, Emitter {
$this->setToken(null); $this->setToken(null);
$firstTimeLogin = $user->updateLastLoginTimestamp(); $firstTimeLogin = $user->updateLastLoginTimestamp();
} }
$postLoginEvent = new OC\User\Events\PostLoginEvent(
$user,
$loginDetails['password'],
$isToken
);
$this->dispatcher->dispatch(OC\User\Events\PostLoginEvent::class, $postLoginEvent);
$this->manager->emit('\OC\User', 'postLogin', [ $this->manager->emit('\OC\User', 'postLogin', [
$user, $user,
$loginDetails['password'], $loginDetails['password'],

View File

@ -15,11 +15,13 @@ use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken; use OC\Authentication\Token\IToken;
use OC\Security\Bruteforce\Throttler; use OC\Security\Bruteforce\Throttler;
use OC\Session\Memory; use OC\Session\Memory;
use OC\User\Events\PostLoginEvent;
use OC\User\Manager; use OC\User\Manager;
use OC\User\Session; use OC\User\Session;
use OC\User\User; use OC\User\User;
use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\Connector\Sabre\Auth;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger; use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
@ -28,6 +30,7 @@ use OCP\IUser;
use OCP\Lockdown\ILockdownManager; use OCP\Lockdown\ILockdownManager;
use OCP\Security\ICrypto; use OCP\Security\ICrypto;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/** /**
@ -35,26 +38,28 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
* @package Test\User * @package Test\User
*/ */
class SessionTest extends \Test\TestCase { class SessionTest extends \Test\TestCase {
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */ /** @var ITimeFactory|MockObject */
private $timeFactory; private $timeFactory;
/** @var DefaultTokenProvider|\PHPUnit_Framework_MockObject_MockObject */ /** @var DefaultTokenProvider|MockObject */
protected $tokenProvider; protected $tokenProvider;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ /** @var IConfig|MockObject */
private $config; private $config;
/** @var Throttler|\PHPUnit_Framework_MockObject_MockObject */ /** @var Throttler|MockObject */
private $throttler; private $throttler;
/** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */ /** @var ISecureRandom|MockObject */
private $random; private $random;
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject */ /** @var Manager|MockObject */
private $manager; private $manager;
/** @var ISession|\PHPUnit_Framework_MockObject_MockObject */ /** @var ISession|MockObject */
private $session; private $session;
/** @var Session|\PHPUnit_Framework_MockObject_MockObject */ /** @var Session|MockObject */
private $userSession; private $userSession;
/** @var ILockdownManager|\PHPUnit_Framework_MockObject_MockObject */ /** @var ILockdownManager|MockObject */
private $lockdownManager; private $lockdownManager;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ /** @var ILogger|MockObject */
private $logger; private $logger;
/** @var IEventDispatcher|MockObject */
private $dispatcher;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -71,6 +76,7 @@ class SessionTest extends \Test\TestCase {
$this->session = $this->createMock(ISession::class); $this->session = $this->createMock(ISession::class);
$this->lockdownManager = $this->createMock(ILockdownManager::class); $this->lockdownManager = $this->createMock(ILockdownManager::class);
$this->logger = $this->createMock(ILogger::class); $this->logger = $this->createMock(ILogger::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->userSession = $this->getMockBuilder(Session::class) $this->userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([ ->setConstructorArgs([
$this->manager, $this->manager,
@ -81,6 +87,7 @@ class SessionTest extends \Test\TestCase {
$this->random, $this->random,
$this->lockdownManager, $this->lockdownManager,
$this->logger, $this->logger,
$this->dispatcher
]) ])
->setMethods([ ->setMethods([
'setMagicInCookie', 'setMagicInCookie',
@ -141,7 +148,7 @@ class SessionTest extends \Test\TestCase {
->with($expectedUser->getUID()) ->with($expectedUser->getUID())
->will($this->returnValue($expectedUser)); ->will($this->returnValue($expectedUser));
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$user = $userSession->getUser(); $user = $userSession->getUser();
$this->assertSame($expectedUser, $user); $this->assertSame($expectedUser, $user);
$this->assertSame(10000, $token->getLastCheck()); $this->assertSame(10000, $token->getLastCheck());
@ -163,7 +170,7 @@ class SessionTest extends \Test\TestCase {
$manager = $this->createMock(Manager::class); $manager = $this->createMock(Manager::class);
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods([ ->setMethods([
'getUser' 'getUser'
]) ])
@ -190,7 +197,7 @@ class SessionTest extends \Test\TestCase {
->method('getUID') ->method('getUID')
->will($this->returnValue('foo')); ->will($this->returnValue('foo'));
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession->setUser($user); $userSession->setUser($user);
} }
@ -242,13 +249,25 @@ class SessionTest extends \Test\TestCase {
->will($this->returnValue($user)); ->will($this->returnValue($user));
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods([ ->setMethods([
'prepareUserLogin' 'prepareUserLogin'
]) ])
->getMock(); ->getMock();
$userSession->expects($this->once()) $userSession->expects($this->once())
->method('prepareUserLogin'); ->method('prepareUserLogin');
$this->dispatcher->expects($this->once())
->method('dispatch')
->with(
PostLoginEvent::class,
$this->callback(function(PostLoginEvent $e) {
return $e->getUser()->getUID() === 'foo' &&
$e->getPassword() === 'bar' &&
$e->getIsTokenLogin() === false;
})
);
$userSession->login('foo', 'bar'); $userSession->login('foo', 'bar');
$this->assertEquals($user, $userSession->getUser()); $this->assertEquals($user, $userSession->getUser());
} }
@ -289,7 +308,10 @@ class SessionTest extends \Test\TestCase {
->with('foo', 'bar') ->with('foo', 'bar')
->will($this->returnValue($user)); ->will($this->returnValue($user));
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $this->dispatcher->expects($this->never())
->method('dispatch');
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession->login('foo', 'bar'); $userSession->login('foo', 'bar');
} }
@ -303,7 +325,7 @@ class SessionTest extends \Test\TestCase {
->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)])
->getMock(); ->getMock();
$backend = $this->createMock(\Test\Util\User\Dummy::class); $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); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
@ -326,13 +348,16 @@ class SessionTest extends \Test\TestCase {
->with('foo', 'bar') ->with('foo', 'bar')
->will($this->returnValue(false)); ->will($this->returnValue(false));
$this->dispatcher->expects($this->never())
->method('dispatch');
$userSession->login('foo', 'bar'); $userSession->login('foo', 'bar');
} }
public function testLoginNonExisting() { public function testLoginNonExisting() {
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$manager = $this->createMock(Manager::class); $manager = $this->createMock(Manager::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$session->expects($this->never()) $session->expects($this->never())
->method('set'); ->method('set');
@ -358,7 +383,7 @@ class SessionTest extends \Test\TestCase {
public function testLoginWithDifferentTokenLoginName() { public function testLoginWithDifferentTokenLoginName() {
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$manager = $this->createMock(Manager::class); $manager = $this->createMock(Manager::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$username = 'user123'; $username = 'user123';
$token = new \OC\Authentication\Token\DefaultToken(); $token = new \OC\Authentication\Token\DefaultToken();
$token->setLoginName($username); $token->setLoginName($username);
@ -390,7 +415,7 @@ class SessionTest extends \Test\TestCase {
/** @var \OC\User\Session $userSession */ /** @var \OC\User\Session $userSession */
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser']) ->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock(); ->getMock();
@ -426,7 +451,7 @@ class SessionTest extends \Test\TestCase {
/** @var Session $userSession */ /** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser']) ->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock(); ->getMock();
@ -452,7 +477,7 @@ class SessionTest extends \Test\TestCase {
/** @var \OC\User\Session $userSession */ /** @var \OC\User\Session $userSession */
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser']) ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser'])
->getMock(); ->getMock();
@ -494,7 +519,7 @@ class SessionTest extends \Test\TestCase {
/** @var \OC\User\Session $userSession */ /** @var \OC\User\Session $userSession */
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['login', 'isTwoFactorEnforced']) ->setMethods(['login', 'isTwoFactorEnforced'])
->getMock(); ->getMock();
@ -541,7 +566,7 @@ class SessionTest extends \Test\TestCase {
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie() //override, otherwise tests will fail because of setcookie()
->setMethods(['setMagicInCookie', 'setLoginName']) ->setMethods(['setMagicInCookie', 'setLoginName'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock(); ->getMock();
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
@ -627,7 +652,7 @@ class SessionTest extends \Test\TestCase {
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie() //override, otherwise tests will fail because of setcookie()
->setMethods(['setMagicInCookie']) ->setMethods(['setMagicInCookie'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock(); ->getMock();
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
@ -687,7 +712,7 @@ class SessionTest extends \Test\TestCase {
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie() //override, otherwise tests will fail because of setcookie()
->setMethods(['setMagicInCookie']) ->setMethods(['setMagicInCookie'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock(); ->getMock();
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
@ -735,7 +760,7 @@ class SessionTest extends \Test\TestCase {
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
//override, otherwise tests will fail because of setcookie() //override, otherwise tests will fail because of setcookie()
->setMethods(['setMagicInCookie']) ->setMethods(['setMagicInCookie'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock(); ->getMock();
$token = 'goodToken'; $token = 'goodToken';
$oldSessionId = 'sess321'; $oldSessionId = 'sess321';
@ -783,7 +808,7 @@ class SessionTest extends \Test\TestCase {
$session = new Memory(''); $session = new Memory('');
$session->set('user_id', 'foo'); $session->set('user_id', 'foo');
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods([ ->setMethods([
'validateSession' 'validateSession'
]) ])
@ -803,7 +828,7 @@ class SessionTest extends \Test\TestCase {
$manager = $this->createMock(Manager::class); $manager = $this->createMock(Manager::class);
$session = $this->createMock(ISession::class); $session = $this->createMock(ISession::class);
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$random = $this->createMock(ISecureRandom::class); $random = $this->createMock(ISecureRandom::class);
$config = $this->createMock(IConfig::class); $config = $this->createMock(IConfig::class);
@ -844,7 +869,7 @@ class SessionTest extends \Test\TestCase {
$manager = $this->createMock(Manager::class); $manager = $this->createMock(Manager::class);
$session = $this->createMock(ISession::class); $session = $this->createMock(ISession::class);
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$random = $this->createMock(ISecureRandom::class); $random = $this->createMock(ISecureRandom::class);
$config = $this->createMock(IConfig::class); $config = $this->createMock(IConfig::class);
@ -888,7 +913,7 @@ class SessionTest extends \Test\TestCase {
$session = $this->createMock(ISession::class); $session = $this->createMock(ISession::class);
$token = $this->createMock(IToken::class); $token = $this->createMock(IToken::class);
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$random = $this->createMock(ISecureRandom::class); $random = $this->createMock(ISecureRandom::class);
$config = $this->createMock(IConfig::class); $config = $this->createMock(IConfig::class);
@ -935,7 +960,7 @@ class SessionTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$session = $this->createMock(ISession::class); $session = $this->createMock(ISession::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$request = $this->createMock(IRequest::class); $request = $this->createMock(IRequest::class);
$uid = 'user123'; $uid = 'user123';
@ -965,7 +990,7 @@ class SessionTest extends \Test\TestCase {
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setMethods(['logout']) ->setMethods(['logout'])
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->getMock(); ->getMock();
$request = $this->createMock(IRequest::class); $request = $this->createMock(IRequest::class);
@ -994,7 +1019,7 @@ class SessionTest extends \Test\TestCase {
$timeFactory = $this->createMock(ITimeFactory::class); $timeFactory = $this->createMock(ITimeFactory::class);
$tokenProvider = $this->createMock(IProvider::class); $tokenProvider = $this->createMock(IProvider::class);
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['logout']) ->setMethods(['logout'])
->getMock(); ->getMock();
@ -1039,7 +1064,7 @@ class SessionTest extends \Test\TestCase {
$timeFactory = $this->createMock(ITimeFactory::class); $timeFactory = $this->createMock(ITimeFactory::class);
$tokenProvider = $this->createMock(IProvider::class); $tokenProvider = $this->createMock(IProvider::class);
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['logout']) ->setMethods(['logout'])
->getMock(); ->getMock();
@ -1074,7 +1099,7 @@ class SessionTest extends \Test\TestCase {
$timeFactory = $this->createMock(ITimeFactory::class); $timeFactory = $this->createMock(ITimeFactory::class);
$tokenProvider = $this->createMock(IProvider::class); $tokenProvider = $this->createMock(IProvider::class);
$userSession = $this->getMockBuilder(Session::class) $userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger]) ->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['logout']) ->setMethods(['logout'])
->getMock(); ->getMock();
@ -1122,7 +1147,7 @@ class SessionTest extends \Test\TestCase {
$session = $this->createMock(ISession::class); $session = $this->createMock(ISession::class);
$timeFactory = $this->createMock(ITimeFactory::class); $timeFactory = $this->createMock(ITimeFactory::class);
$tokenProvider = $this->createMock(IProvider::class); $tokenProvider = $this->createMock(IProvider::class);
$userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$password = '123456'; $password = '123456';
$sessionId = 'session1234'; $sessionId = 'session1234';
@ -1147,7 +1172,7 @@ class SessionTest extends \Test\TestCase {
$session = $this->createMock(ISession::class); $session = $this->createMock(ISession::class);
$timeFactory = $this->createMock(ITimeFactory::class); $timeFactory = $this->createMock(ITimeFactory::class);
$tokenProvider = $this->createMock(IProvider::class); $tokenProvider = $this->createMock(IProvider::class);
$userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$session->expects($this->once()) $session->expects($this->once())
->method('getId') ->method('getId')
@ -1161,7 +1186,7 @@ class SessionTest extends \Test\TestCase {
$session = $this->createMock(ISession::class); $session = $this->createMock(ISession::class);
$timeFactory = $this->createMock(ITimeFactory::class); $timeFactory = $this->createMock(ITimeFactory::class);
$tokenProvider = $this->createMock(IProvider::class); $tokenProvider = $this->createMock(IProvider::class);
$userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new \OC\User\Session($userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$password = '123456'; $password = '123456';
$sessionId = 'session1234'; $sessionId = 'session1234';
@ -1201,7 +1226,7 @@ class SessionTest extends \Test\TestCase {
$tokenProvider = new DefaultTokenProvider($mapper, $crypto, $this->config, $logger, $this->timeFactory); $tokenProvider = new DefaultTokenProvider($mapper, $crypto, $this->config, $logger, $this->timeFactory);
/** @var \OC\User\Session $userSession */ /** @var \OC\User\Session $userSession */
$userSession = new Session($manager, $session, $this->timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new Session($manager, $session, $this->timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$mapper->expects($this->any()) $mapper->expects($this->any())
->method('getToken') ->method('getToken')
@ -1255,7 +1280,7 @@ class SessionTest extends \Test\TestCase {
$tokenProvider = new DefaultTokenProvider($mapper, $crypto, $this->config, $logger, $this->timeFactory); $tokenProvider = new DefaultTokenProvider($mapper, $crypto, $this->config, $logger, $this->timeFactory);
/** @var \OC\User\Session $userSession */ /** @var \OC\User\Session $userSession */
$userSession = new Session($manager, $session, $this->timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger); $userSession = new Session($manager, $session, $this->timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$mapper->expects($this->any()) $mapper->expects($this->any())
->method('getToken') ->method('getToken')
@ -1348,7 +1373,8 @@ class SessionTest extends \Test\TestCase {
$this->config, $this->config,
$this->random, $this->random,
$this->lockdownManager, $this->lockdownManager,
$this->logger $this->logger,
$this->dispatcher
]) ])
->setMethods([ ->setMethods([
'logClientIn', 'logClientIn',
@ -1356,7 +1382,7 @@ class SessionTest extends \Test\TestCase {
]) ])
->getMock(); ->getMock();
/** @var Session|\PHPUnit_Framework_MockObject_MockObject */ /** @var Session|MockObject */
$userSession->expects($this->once()) $userSession->expects($this->once())
->method('logClientIn') ->method('logClientIn')
->with( ->with(
@ -1399,14 +1425,15 @@ class SessionTest extends \Test\TestCase {
$this->config, $this->config,
$this->random, $this->random,
$this->lockdownManager, $this->lockdownManager,
$this->logger $this->logger,
$this->dispatcher
]) ])
->setMethods([ ->setMethods([
'logClientIn', 'logClientIn',
]) ])
->getMock(); ->getMock();
/** @var Session|\PHPUnit_Framework_MockObject_MockObject */ /** @var Session|MockObject */
$userSession->expects($this->never()) $userSession->expects($this->never())
->method('logClientIn'); ->method('logClientIn');