Merge pull request #18028 from nextcloud/enhancement/user-create-events

Add typed create user events
This commit is contained in:
Roeland Jago Douma 2019-12-03 08:57:51 +01:00 committed by GitHub
commit 1d707cc349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 308 additions and 137 deletions

View File

@ -30,6 +30,7 @@ use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection; use OCA\User_LDAP\Connection;
use OCA\User_LDAP\IGroupLDAP; use OCA\User_LDAP\IGroupLDAP;
use OCA\User_LDAP\IUserLDAP; use OCA\User_LDAP\IUserLDAP;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig; use OCP\IConfig;
use OCP\IServerContainer; use OCP\IServerContainer;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -46,7 +47,7 @@ class LDAPProviderTest extends \Test\TestCase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
} }
private function getServerMock(IUserLDAP $userBackend, IGroupLDAP $groupBackend) { private function getServerMock(IUserLDAP $userBackend, IGroupLDAP $groupBackend) {
$server = $this->getMockBuilder('OC\Server') $server = $this->getMockBuilder('OC\Server')
->setMethods(['getUserManager', 'getBackends', 'getGroupManager']) ->setMethods(['getUserManager', 'getBackends', 'getGroupManager'])
@ -71,7 +72,11 @@ class LDAPProviderTest extends \Test\TestCase {
private function getUserManagerMock(IUserLDAP $userBackend) { private function getUserManagerMock(IUserLDAP $userBackend) {
$userManager = $this->getMockBuilder(Manager::class) $userManager = $this->getMockBuilder(Manager::class)
->setMethods(['getBackends']) ->setMethods(['getBackends'])
->setConstructorArgs([$this->createMock(IConfig::class), $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([
$this->createMock(IConfig::class),
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IEventDispatcher::class)
])
->getMock(); ->getMock();
$userManager->expects($this->any()) $userManager->expects($this->any())
->method('getBackends') ->method('getBackends')
@ -92,9 +97,9 @@ class LDAPProviderTest extends \Test\TestCase {
private function getDefaultGroupBackendMock() { private function getDefaultGroupBackendMock() {
$groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
return $groupBackend; return $groupBackend;
} }
@ -102,8 +107,8 @@ class LDAPProviderTest extends \Test\TestCase {
$factory = new \OCA\User_LDAP\LDAPProviderFactory($serverContainer); $factory = new \OCA\User_LDAP\LDAPProviderFactory($serverContainer);
return $factory->getLDAPProvider(); return $factory->getLDAPProvider();
} }
public function testGetUserDNUserIDNotFound() { public function testGetUserDNUserIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP'); $this->expectExceptionMessage('User id not found in LDAP');
@ -113,13 +118,13 @@ class LDAPProviderTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false); $userBackend->expects($this->any())->method('userExists')->willReturn(false);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$ldapProvider->getUserDN('nonexisting_user'); $ldapProvider->getUserDN('nonexisting_user');
} }
public function testGetUserDN() { public function testGetUserDN() {
$userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
->setMethods(['userExists', 'getLDAPAccess', 'username2dn']) ->setMethods(['userExists', 'getLDAPAccess', 'username2dn'])
@ -134,15 +139,15 @@ class LDAPProviderTest extends \Test\TestCase {
$userBackend->expects($this->any()) $userBackend->expects($this->any())
->method($this->anything()) ->method($this->anything())
->willReturnSelf(); ->willReturnSelf();
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org', $this->assertEquals('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org',
$ldapProvider->getUserDN('existing_user')); $ldapProvider->getUserDN('existing_user'));
} }
public function testGetGroupDNGroupIDNotFound() { public function testGetGroupDNGroupIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('Group id not found in LDAP'); $this->expectExceptionMessage('Group id not found in LDAP');
@ -190,7 +195,7 @@ class LDAPProviderTest extends \Test\TestCase {
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org', $this->assertEquals('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org',
$ldapProvider->getGroupDN('existing_group')); $ldapProvider->getGroupDN('existing_group'));
} }
public function testGetUserName() { public function testGetUserName() {
$userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
@ -200,27 +205,27 @@ class LDAPProviderTest extends \Test\TestCase {
$userBackend->expects($this->any()) $userBackend->expects($this->any())
->method('dn2UserName') ->method('dn2UserName')
->willReturn('existing_user'); ->willReturn('existing_user');
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals('existing_user', $this->assertEquals('existing_user',
$ldapProvider->getUserName('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); $ldapProvider->getUserName('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'));
} }
public function testDNasBaseParameter() { public function testDNasBaseParameter() {
$userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
->setMethods([]) ->setMethods([])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals( $this->assertEquals(
$helper->DNasBaseParameter('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'), $helper->DNasBaseParameter('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'),
$ldapProvider->DNasBaseParameter('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); $ldapProvider->DNasBaseParameter('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'));
} }
@ -229,18 +234,18 @@ class LDAPProviderTest extends \Test\TestCase {
->setMethods([]) ->setMethods([])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals( $this->assertEquals(
$helper->sanitizeDN('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'), $helper->sanitizeDN('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'),
$ldapProvider->sanitizeDN('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); $ldapProvider->sanitizeDN('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'));
} }
public function testGetLDAPConnectionUserIDNotFound() { public function testGetLDAPConnectionUserIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP'); $this->expectExceptionMessage('User id not found in LDAP');
@ -250,13 +255,13 @@ class LDAPProviderTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false); $userBackend->expects($this->any())->method('userExists')->willReturn(false);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$ldapProvider->getLDAPConnection('nonexisting_user'); $ldapProvider->getLDAPConnection('nonexisting_user');
} }
public function testGetLDAPConnection() { public function testGetLDAPConnection() {
$userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
->setMethods(['userExists', 'getNewLDAPConnection']) ->setMethods(['userExists', 'getNewLDAPConnection'])
@ -268,14 +273,14 @@ class LDAPProviderTest extends \Test\TestCase {
$userBackend->expects($this->any()) $userBackend->expects($this->any())
->method('getNewLDAPConnection') ->method('getNewLDAPConnection')
->willReturn(true); ->willReturn(true);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertTrue($ldapProvider->getLDAPConnection('existing_user')); $this->assertTrue($ldapProvider->getLDAPConnection('existing_user'));
} }
public function testGetGroupLDAPConnectionGroupIDNotFound() { public function testGetGroupLDAPConnectionGroupIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('Group id not found in LDAP'); $this->expectExceptionMessage('Group id not found in LDAP');
@ -320,8 +325,8 @@ class LDAPProviderTest extends \Test\TestCase {
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertTrue($ldapProvider->getGroupLDAPConnection('existing_group')); $this->assertTrue($ldapProvider->getGroupLDAPConnection('existing_group'));
} }
public function testGetLDAPBaseUsersUserIDNotFound() { public function testGetLDAPBaseUsersUserIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP'); $this->expectExceptionMessage('User id not found in LDAP');
@ -331,13 +336,13 @@ class LDAPProviderTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false); $userBackend->expects($this->any())->method('userExists')->willReturn(false);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$ldapProvider->getLDAPBaseUsers('nonexisting_user'); $ldapProvider->getLDAPBaseUsers('nonexisting_user');
} }
public function testGetLDAPBaseUsers() { public function testGetLDAPBaseUsers() {
$bases = [ $bases = [
'ou=users,ou=foobar,dc=example,dc=org', 'ou=users,ou=foobar,dc=example,dc=org',
@ -379,12 +384,12 @@ class LDAPProviderTest extends \Test\TestCase {
->willReturn($access); ->willReturn($access);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals($bases[1], $ldapProvider->getLDAPBaseUsers('existing_user')); $this->assertEquals($bases[1], $ldapProvider->getLDAPBaseUsers('existing_user'));
} }
public function testGetLDAPBaseGroupsUserIDNotFound() { public function testGetLDAPBaseGroupsUserIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP'); $this->expectExceptionMessage('User id not found in LDAP');
@ -394,13 +399,13 @@ class LDAPProviderTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false); $userBackend->expects($this->any())->method('userExists')->willReturn(false);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$ldapProvider->getLDAPBaseGroups('nonexisting_user'); $ldapProvider->getLDAPBaseGroups('nonexisting_user');
} }
public function testGetLDAPBaseGroups() { public function testGetLDAPBaseGroups() {
$bases = [ $bases = [
'ou=groupd,ou=foobar,dc=example,dc=org', 'ou=groupd,ou=foobar,dc=example,dc=org',
@ -435,12 +440,12 @@ class LDAPProviderTest extends \Test\TestCase {
->willReturn($access); ->willReturn($access);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals($bases[0], $ldapProvider->getLDAPBaseGroups('existing_user')); $this->assertEquals($bases[0], $ldapProvider->getLDAPBaseGroups('existing_user'));
} }
public function testClearCacheUserIDNotFound() { public function testClearCacheUserIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP'); $this->expectExceptionMessage('User id not found in LDAP');
@ -450,13 +455,13 @@ class LDAPProviderTest extends \Test\TestCase {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$userBackend->expects($this->any())->method('userExists')->willReturn(false); $userBackend->expects($this->any())->method('userExists')->willReturn(false);
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$ldapProvider->clearCache('nonexisting_user'); $ldapProvider->clearCache('nonexisting_user');
} }
public function testClearCache() { public function testClearCache() {
$userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'clearCache']) ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'clearCache'])
@ -471,15 +476,15 @@ class LDAPProviderTest extends \Test\TestCase {
$userBackend->expects($this->any()) $userBackend->expects($this->any())
->method($this->anything()) ->method($this->anything())
->willReturnSelf(); ->willReturnSelf();
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$ldapProvider->clearCache('existing_user'); $ldapProvider->clearCache('existing_user');
$this->addToAssertionCount(1); $this->addToAssertionCount(1);
} }
public function testClearGroupCacheGroupIDNotFound() { public function testClearGroupCacheGroupIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('Group id not found in LDAP'); $this->expectExceptionMessage('Group id not found in LDAP');
@ -523,7 +528,7 @@ class LDAPProviderTest extends \Test\TestCase {
$ldapProvider->clearGroupCache('existing_group'); $ldapProvider->clearGroupCache('existing_group');
$this->addToAssertionCount(1); $this->addToAssertionCount(1);
} }
public function testDnExists() { public function testDnExists() {
$userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
->setMethods(['dn2UserName']) ->setMethods(['dn2UserName'])
@ -532,40 +537,40 @@ class LDAPProviderTest extends \Test\TestCase {
$userBackend->expects($this->any()) $userBackend->expects($this->any())
->method('dn2UserName') ->method('dn2UserName')
->willReturn('existing_user'); ->willReturn('existing_user');
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertTrue($ldapProvider->dnExists('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); $this->assertTrue($ldapProvider->dnExists('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'));
} }
public function testFlagRecord() { public function testFlagRecord() {
$userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
->setMethods([]) ->setMethods([])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$ldapProvider->flagRecord('existing_user'); $ldapProvider->flagRecord('existing_user');
$this->addToAssertionCount(1); $this->addToAssertionCount(1);
} }
public function testUnflagRecord() { public function testUnflagRecord() {
$userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP')
->setMethods([]) ->setMethods([])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$ldapProvider->unflagRecord('existing_user'); $ldapProvider->unflagRecord('existing_user');
$this->addToAssertionCount(1); $this->addToAssertionCount(1);
} }
public function testGetLDAPDisplayNameFieldUserIDNotFound() { public function testGetLDAPDisplayNameFieldUserIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP'); $this->expectExceptionMessage('User id not found in LDAP');
@ -603,7 +608,7 @@ class LDAPProviderTest extends \Test\TestCase {
$this->assertEquals('displayName', $ldapProvider->getLDAPDisplayNameField('existing_user')); $this->assertEquals('displayName', $ldapProvider->getLDAPDisplayNameField('existing_user'));
} }
public function testGetLDAPEmailFieldUserIDNotFound() { public function testGetLDAPEmailFieldUserIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('User id not found in LDAP'); $this->expectExceptionMessage('User id not found in LDAP');
@ -641,7 +646,7 @@ class LDAPProviderTest extends \Test\TestCase {
$this->assertEquals('mail', $ldapProvider->getLDAPEmailField('existing_user')); $this->assertEquals('mail', $ldapProvider->getLDAPEmailField('existing_user'));
} }
public function testGetLDAPGroupMemberAssocUserIDNotFound() { public function testGetLDAPGroupMemberAssocUserIDNotFound() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
$this->expectExceptionMessage('Group id not found in LDAP'); $this->expectExceptionMessage('Group id not found in LDAP');
@ -687,6 +692,6 @@ class LDAPProviderTest extends \Test\TestCase {
$ldapProvider = $this->getLDAPProvider($server); $ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals('assoc_type', $ldapProvider->getLDAPGroupMemberAssoc('existing_group')); $this->assertEquals('assoc_type', $ldapProvider->getLDAPGroupMemberAssoc('existing_group'));
} }
} }

View File

@ -450,7 +450,9 @@ return array(
'OCP\\User\\Backend\\IProvideAvatarBackend' => $baseDir . '/lib/public/User/Backend/IProvideAvatarBackend.php', 'OCP\\User\\Backend\\IProvideAvatarBackend' => $baseDir . '/lib/public/User/Backend/IProvideAvatarBackend.php',
'OCP\\User\\Backend\\ISetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/ISetDisplayNameBackend.php', 'OCP\\User\\Backend\\ISetDisplayNameBackend' => $baseDir . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.php', 'OCP\\User\\Backend\\ISetPasswordBackend' => $baseDir . '/lib/public/User/Backend/ISetPasswordBackend.php',
'OCP\\User\\Events\\CreateUserEvent' => $baseDir . '/lib/public/User/Events/CreateUserEvent.php',
'OCP\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/public/User/Events/PostLoginEvent.php', 'OCP\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/public/User/Events/PostLoginEvent.php',
'OCP\\User\\Events\\UserCreatedEvent' => $baseDir . '/lib/public/User/Events/UserCreatedEvent.php',
'OCP\\Util' => $baseDir . '/lib/public/Util.php', 'OCP\\Util' => $baseDir . '/lib/public/Util.php',
'OCP\\WorkflowEngine\\EntityContext\\IDisplayName' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayName.php', 'OCP\\WorkflowEngine\\EntityContext\\IDisplayName' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayName.php',
'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php', 'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php',

View File

@ -479,7 +479,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\User\\Backend\\IProvideAvatarBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IProvideAvatarBackend.php', 'OCP\\User\\Backend\\IProvideAvatarBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/IProvideAvatarBackend.php',
'OCP\\User\\Backend\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetDisplayNameBackend.php', 'OCP\\User\\Backend\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetDisplayNameBackend.php',
'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.php', 'OCP\\User\\Backend\\ISetPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ISetPasswordBackend.php',
'OCP\\User\\Events\\CreateUserEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/CreateUserEvent.php',
'OCP\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PostLoginEvent.php', 'OCP\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PostLoginEvent.php',
'OCP\\User\\Events\\UserCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserCreatedEvent.php',
'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php', 'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php',
'OCP\\WorkflowEngine\\EntityContext\\IDisplayName' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IDisplayName.php', 'OCP\\WorkflowEngine\\EntityContext\\IDisplayName' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IDisplayName.php',
'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php', 'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php',

View File

@ -317,9 +317,6 @@ class Server extends ServerContainer implements IServerContainer {
}); });
$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
$this->registerService(\OC\User\Manager::class, function (Server $c) {
return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher());
});
$this->registerAlias('UserManager', \OC\User\Manager::class); $this->registerAlias('UserManager', \OC\User\Manager::class);
$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);

View File

@ -33,12 +33,15 @@ namespace OC\User;
use OC\Hooks\PublicEmitter; use OC\Hooks\PublicEmitter;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroup; use OCP\IGroup;
use OCP\IUser; use OCP\IUser;
use OCP\IUserBackend; use OCP\IUserBackend;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\User\Backend\IGetRealUIDBackend; use OCP\User\Backend\IGetRealUIDBackend;
use OCP\User\Events\CreateUserEvent;
use OCP\User\Events\UserCreatedEvent;
use OCP\UserInterface; use OCP\UserInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -72,17 +75,24 @@ class Manager extends PublicEmitter implements IUserManager {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var EventDispatcherInterface */ /** @var EventDispatcherInterface */
private $dispatcher; private $dispatcher;
public function __construct(IConfig $config, EventDispatcherInterface $dispatcher) { /** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(IConfig $config,
EventDispatcherInterface $oldDispatcher,
IEventDispatcher $eventDispatcher) {
$this->config = $config; $this->config = $config;
$this->dispatcher = $dispatcher; $this->dispatcher = $oldDispatcher;
$cachedUsers = &$this->cachedUsers; $cachedUsers = &$this->cachedUsers;
$this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) {
/** @var \OC\User\User $user */ /** @var \OC\User\User $user */
unset($cachedUsers[$user->getUID()]); unset($cachedUsers[$user->getUID()]);
}); });
$this->eventDispatcher = $eventDispatcher;
} }
/** /**
@ -349,6 +359,7 @@ class Manager extends PublicEmitter implements IUserManager {
} }
$this->emit('\OC\User', 'preCreateUser', [$uid, $password]); $this->emit('\OC\User', 'preCreateUser', [$uid, $password]);
$this->eventDispatcher->dispatchTyped(new CreateUserEvent($uid, $password));
$state = $backend->createUser($uid, $password); $state = $backend->createUser($uid, $password);
if($state === false) { if($state === false) {
throw new \InvalidArgumentException($l->t('Could not create user')); throw new \InvalidArgumentException($l->t('Could not create user'));
@ -356,6 +367,7 @@ class Manager extends PublicEmitter implements IUserManager {
$user = $this->getUserObject($uid, $backend); $user = $this->getUserObject($uid, $backend);
if ($user instanceof IUser) { if ($user instanceof IUser) {
$this->emit('\OC\User', 'postCreateUser', [$user, $password]); $this->emit('\OC\User', 'postCreateUser', [$user, $password]);
$this->eventDispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
} }
return $user; return $user;
} }
@ -460,11 +472,11 @@ class Manager extends PublicEmitter implements IUserManager {
->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled'))) ->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR)); ->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false'), IQueryBuilder::PARAM_STR));
$result = $queryBuilder->execute(); $result = $queryBuilder->execute();
$count = $result->fetchColumn(); $count = $result->fetchColumn();
$result->closeCursor(); $result->closeCursor();
if ($count !== false) { if ($count !== false) {
$count = (int)$count; $count = (int)$count;
} else { } else {
@ -494,7 +506,7 @@ class Manager extends PublicEmitter implements IUserManager {
$result = $queryBuilder->execute(); $result = $queryBuilder->execute();
$count = $result->fetchColumn(); $count = $result->fetchColumn();
$result->closeCursor(); $result->closeCursor();
if ($count !== false) { if ($count !== false) {
$count = (int)$count; $count = (int)$count;
} else { } else {

View File

@ -0,0 +1,63 @@
<?php declare(strict_types=1);
/**
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @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 OCP\User\Events;
use OCP\EventDispatcher\Event;
/**
* @since 18.0.0
*/
class CreateUserEvent extends Event {
/** @var string */
private $uid;
/** @var string */
private $password;
/**
* @since 18.0.0
*/
public function __construct(string $uid,
string $password) {
parent::__construct();
$this->uid = $uid;
$this->password = $password;
}
/**
* @since 18.0.0
*/
public function getUid(): string {
return $this->uid;
}
/**
* @since 18.0.0
*/
public function getPassword(): string {
return $this->password;
}
}

View File

@ -0,0 +1,71 @@
<?php declare(strict_types=1);
/**
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @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 OCP\User\Events;
use OCP\EventDispatcher\Event;
use OCP\IUser;
/**
* @since 18.0.0
*/
class UserCreatedEvent extends Event {
/** @var IUser */
private $user;
/** @var string */
private $password;
/**
* @since 18.0.0
*/
public function __construct(IUser $user,
string $password) {
parent::__construct();
$this->user = $user;
$this->password = $password;
}
/**
* @since 18.0.0
*/
public function getUser(): IUser {
return $this->user;
}
/**
* @since 18.0.0
*/
public function getUid(): string {
return $this->user->getUID();
}
/**
* @since 18.0.0
*/
public function getPassword(): string {
return $this->password;
}
}

View File

@ -13,6 +13,7 @@ use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage; use OC\Files\Storage\Storage;
use OC\Log; use OC\Log;
use OC\User\Manager; use OC\User\Manager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Config\ICachedMountInfo;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
@ -45,7 +46,7 @@ class UserMountCacheTest extends TestCase {
protected function setUp(): void { protected function setUp(): void {
$this->fileIds = []; $this->fileIds = [];
$this->connection = \OC::$server->getDatabaseConnection(); $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 = new Dummy();
$userBackend->createUser('u1', ''); $userBackend->createUser('u1', '');
$userBackend->createUser('u2', ''); $userBackend->createUser('u2', '');

View File

@ -14,6 +14,7 @@ use OC\User\Manager;
use OCP\Encryption\IEncryptionModule; use OCP\Encryption\IEncryptionModule;
use OCP\Encryption\IFile; use OCP\Encryption\IFile;
use OCP\Encryption\Keys\IStorage; use OCP\Encryption\Keys\IStorage;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICache;
use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IMountPoint;
use OCP\IConfig; use OCP\IConfig;
@ -131,7 +132,7 @@ class EncryptionTest extends Storage {
$this->util = $this->getMockBuilder('\OC\Encryption\Util') $this->util = $this->getMockBuilder('\OC\Encryption\Util')
->setMethods(['getUidAndFilename', 'isFile', 'isExcluded']) ->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(); ->getMock();
$this->util->expects($this->any()) $this->util->expects($this->any())
->method('getUidAndFilename') ->method('getUidAndFilename')
@ -568,7 +569,7 @@ class EncryptionTest extends Storage {
->setConstructorArgs( ->setConstructorArgs(
[ [
new View(), 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->groupManager,
$this->config, $this->config,
$this->arrayCache $this->arrayCache
@ -637,7 +638,7 @@ class EncryptionTest extends Storage {
->willReturn($exists); ->willReturn($exists);
$util = $this->getMockBuilder('\OC\Encryption\Util') $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(); ->getMock();
$cache = $this->getMockBuilder('\OC\Files\Cache\Cache') $cache = $this->getMockBuilder('\OC\Files\Cache\Cache')

View File

@ -5,6 +5,7 @@ namespace Test\Files\Stream;
use OC\Files\Cache\CacheEntry; use OC\Files\Cache\CacheEntry;
use OC\Files\View; use OC\Files\View;
use OC\Memcache\ArrayCache; use OC\Memcache\ArrayCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICache;
use OCP\IConfig; use OCP\IConfig;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -48,7 +49,7 @@ class EncryptionTest extends \Test\TestCase {
$file->expects($this->any())->method('getAccessList')->willReturn([]); $file->expects($this->any())->method('getAccessList')->willReturn([]);
$util = $this->getMockBuilder('\OC\Encryption\Util') $util = $this->getMockBuilder('\OC\Encryption\Util')
->setMethods(['getUidAndFilename']) ->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(); ->getMock();
$util->expects($this->any()) $util->expects($this->any())
->method('getUidAndFilename') ->method('getUidAndFilename')

View File

@ -11,6 +11,7 @@ namespace Test\User;
use OC\AllConfig; use OC\AllConfig;
use OC\User\Database; use OC\User\Database;
use OC\User\Manager; use OC\User\Manager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUser; use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -28,18 +29,21 @@ class ManagerTest extends TestCase {
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
/** @var EventDispatcherInterface */ /** @var EventDispatcherInterface */
private $dispatcher; private $oldDispatcher;
/** @var IEventDispatcher */
private $eventDispatcher;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->config = $this->createMock(IConfig::class); $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() { public function testGetBackends() {
$userDummyBackend = $this->createMock(\Test\Util\User\Dummy::class); $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); $manager->registerBackend($userDummyBackend);
$this->assertEquals([$userDummyBackend], $manager->getBackends()); $this->assertEquals([$userDummyBackend], $manager->getBackends());
$dummyDatabaseBackend = $this->createMock(Database::class); $dummyDatabaseBackend = $this->createMock(Database::class);
@ -58,7 +62,7 @@ class ManagerTest extends TestCase {
->with($this->equalTo('foo')) ->with($this->equalTo('foo'))
->will($this->returnValue(true)); ->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->registerBackend($backend);
$this->assertTrue($manager->userExists('foo')); $this->assertTrue($manager->userExists('foo'));
@ -74,14 +78,14 @@ class ManagerTest extends TestCase {
->with($this->equalTo('foo')) ->with($this->equalTo('foo'))
->will($this->returnValue(false)); ->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); $manager->registerBackend($backend);
$this->assertFalse($manager->userExists('foo')); $this->assertFalse($manager->userExists('foo'));
} }
public function testUserExistsNoBackends() { 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')); $this->assertFalse($manager->userExists('foo'));
} }
@ -105,7 +109,7 @@ class ManagerTest extends TestCase {
->with($this->equalTo('foo')) ->with($this->equalTo('foo'))
->will($this->returnValue(true)); ->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($backend1);
$manager->registerBackend($backend2); $manager->registerBackend($backend2);
@ -129,7 +133,7 @@ class ManagerTest extends TestCase {
$backend2->expects($this->never()) $backend2->expects($this->never())
->method('userExists'); ->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($backend1);
$manager->registerBackend($backend2); $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); $manager->registerBackend($backend);
$user = $manager->checkPassword('foo', 'bar'); $user = $manager->checkPassword('foo', 'bar');
@ -175,7 +179,7 @@ class ManagerTest extends TestCase {
->method('implementsActions') ->method('implementsActions')
->will($this->returnValue(false)); ->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); $manager->registerBackend($backend);
$this->assertFalse($manager->checkPassword('foo', 'bar')); $this->assertFalse($manager->checkPassword('foo', 'bar'));
@ -193,7 +197,7 @@ class ManagerTest extends TestCase {
$backend->expects($this->never()) $backend->expects($this->never())
->method('loginName2UserName'); ->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); $manager->registerBackend($backend);
$this->assertEquals('foo', $manager->get('foo')->getUID()); $this->assertEquals('foo', $manager->get('foo')->getUID());
@ -209,7 +213,7 @@ class ManagerTest extends TestCase {
->with($this->equalTo('foo')) ->with($this->equalTo('foo'))
->will($this->returnValue(false)); ->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); $manager->registerBackend($backend);
$this->assertEquals(null, $manager->get('foo')); $this->assertEquals(null, $manager->get('foo'));
@ -227,7 +231,7 @@ class ManagerTest extends TestCase {
$backend->expects($this->never()) $backend->expects($this->never())
->method('loginName2UserName'); ->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); $manager->registerBackend($backend);
$this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID()); $this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID());
@ -245,7 +249,7 @@ class ManagerTest extends TestCase {
$backend->expects($this->never()) $backend->expects($this->never())
->method('loginName2UserName'); ->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); $manager->registerBackend($backend);
$result = $manager->search('fo'); $result = $manager->search('fo');
@ -279,7 +283,7 @@ class ManagerTest extends TestCase {
$backend2->expects($this->never()) $backend2->expects($this->never())
->method('loginName2UserName'); ->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($backend1);
$manager->registerBackend($backend2); $manager->registerBackend($backend2);
@ -333,7 +337,7 @@ class ManagerTest extends TestCase {
->willReturn(true); ->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); $manager->registerBackend($backend);
$this->expectException(\InvalidArgumentException::class, $exception); $this->expectException(\InvalidArgumentException::class, $exception);
@ -360,14 +364,14 @@ class ManagerTest extends TestCase {
$backend->expects($this->never()) $backend->expects($this->never())
->method('loginName2UserName'); ->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); $manager->registerBackend($backend);
$user = $manager->createUser('foo', 'bar'); $user = $manager->createUser('foo', 'bar');
$this->assertEquals('foo', $user->getUID()); $this->assertEquals('foo', $user->getUID());
} }
public function testCreateUserSingleBackendExists() { public function testCreateUserSingleBackendExists() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
@ -387,7 +391,7 @@ class ManagerTest extends TestCase {
->with($this->equalTo('foo')) ->with($this->equalTo('foo'))
->will($this->returnValue(true)); ->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->registerBackend($backend);
$manager->createUser('foo', 'bar'); $manager->createUser('foo', 'bar');
@ -408,19 +412,19 @@ class ManagerTest extends TestCase {
$backend->expects($this->never()) $backend->expects($this->never())
->method('userExists'); ->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); $manager->registerBackend($backend);
$this->assertFalse($manager->createUser('foo', 'bar')); $this->assertFalse($manager->createUser('foo', 'bar'));
} }
public function testCreateUserNoBackends() { 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')); $this->assertFalse($manager->createUser('foo', 'bar'));
} }
public function testCreateUserFromBackendWithBackendError() { public function testCreateUserFromBackendWithBackendError() {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Could not create user'); $this->expectExceptionMessage('Could not create user');
@ -435,11 +439,11 @@ class ManagerTest extends TestCase {
->with('MyUid', 'MyPassword') ->with('MyUid', 'MyPassword')
->willReturn(false); ->willReturn(false);
$manager = new Manager($config, $this->dispatcher); $manager = new Manager($this->config, $this->oldDispatcher, $this->eventDispatcher);
$manager->createUserFromBackend('MyUid', 'MyPassword', $backend); $manager->createUserFromBackend('MyUid', 'MyPassword', $backend);
} }
public function testCreateUserTwoBackendExists() { public function testCreateUserTwoBackendExists() {
$this->expectException(\Exception::class); $this->expectException(\Exception::class);
@ -475,7 +479,7 @@ class ManagerTest extends TestCase {
->with($this->equalTo('foo')) ->with($this->equalTo('foo'))
->will($this->returnValue(true)); ->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($backend1);
$manager->registerBackend($backend2); $manager->registerBackend($backend2);
@ -483,7 +487,7 @@ class ManagerTest extends TestCase {
} }
public function testCountUsersNoBackend() { 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(); $result = $manager->countUsers();
$this->assertTrue(is_array($result)); $this->assertTrue(is_array($result));
@ -508,7 +512,7 @@ class ManagerTest extends TestCase {
->method('getBackendName') ->method('getBackendName')
->will($this->returnValue('Mock_Test_Util_User_Dummy')); ->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); $manager->registerBackend($backend);
$result = $manager->countUsers(); $result = $manager->countUsers();
@ -549,7 +553,7 @@ class ManagerTest extends TestCase {
->method('getBackendName') ->method('getBackendName')
->will($this->returnValue('Mock_Test_Util_User_Dummy')); ->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($backend1);
$manager->registerBackend($backend2); $manager->registerBackend($backend2);
@ -650,21 +654,7 @@ class ManagerTest extends TestCase {
} }
public function testDeleteUser() { public function testDeleteUser() {
$config = $this->getMockBuilder(IConfig::class) $manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->eventDispatcher);
->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);
$backend = new \Test\Util\User\Dummy(); $backend = new \Test\Util\User\Dummy();
$manager->registerBackend($backend); $manager->registerBackend($backend);
@ -698,7 +688,7 @@ class ManagerTest extends TestCase {
->with($this->equalTo('uid2')) ->with($this->equalTo('uid2'))
->will($this->returnValue(true)); ->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); $manager->registerBackend($backend);
$users = $manager->getByEmail('test@example.com'); $users = $manager->getByEmail('test@example.com');

View File

@ -228,7 +228,11 @@ class SessionTest extends \Test\TestCase {
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class) $manager = $this->getMockBuilder(Manager::class)
->setMethods($mockedManagerMethods) ->setMethods($mockedManagerMethods)
->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([
$this->config,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IEventDispatcher::class)
])
->getMock(); ->getMock();
$backend = $this->createMock(\Test\Util\User\Dummy::class); $backend = $this->createMock(\Test\Util\User\Dummy::class);
@ -271,7 +275,7 @@ class SessionTest extends \Test\TestCase {
$this->assertEquals($user, $userSession->getUser()); $this->assertEquals($user, $userSession->getUser());
} }
public function testLoginValidPasswordDisabled() { public function testLoginValidPasswordDisabled() {
$this->expectException(\OC\User\LoginException::class); $this->expectException(\OC\User\LoginException::class);
@ -290,11 +294,13 @@ class SessionTest extends \Test\TestCase {
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class) $manager = $this->getMockBuilder(Manager::class)
->setMethods($mockedManagerMethods) ->setMethods($mockedManagerMethods)
->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([
$this->config,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IEventDispatcher::class)
])
->getMock(); ->getMock();
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
$user->expects($this->any()) $user->expects($this->any())
->method('isEnabled') ->method('isEnabled')
@ -321,7 +327,11 @@ class SessionTest extends \Test\TestCase {
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class) $manager = $this->getMockBuilder(Manager::class)
->setMethods($mockedManagerMethods) ->setMethods($mockedManagerMethods)
->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([
$this->config,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IEventDispatcher::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, $this->dispatcher); $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'); $userSession->login('foo', 'bar');
} }
public function testLogClientInNoTokenPasswordWith2fa() { public function testLogClientInNoTokenPasswordWith2fa() {
$this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class); $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)); $this->assertTrue($userSession->logClientIn('john', 'I-AM-AN-APP-PASSWORD', $request, $this->throttler));
} }
public function testLogClientInNoTokenPasswordNo2fa() { public function testLogClientInNoTokenPasswordNo2fa() {
$this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class); $this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class);
@ -560,7 +570,11 @@ class SessionTest extends \Test\TestCase {
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class) $manager = $this->getMockBuilder(Manager::class)
->setMethods($mockedManagerMethods) ->setMethods($mockedManagerMethods)
->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([
$this->config,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IEventDispatcher::class)
])
->getMock(); ->getMock();
$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()
@ -645,7 +659,11 @@ class SessionTest extends \Test\TestCase {
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class) $manager = $this->getMockBuilder(Manager::class)
->setMethods($mockedManagerMethods) ->setMethods($mockedManagerMethods)
->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([
$this->config,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IEventDispatcher::class)
])
->getMock(); ->getMock();
$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()
@ -705,7 +723,11 @@ class SessionTest extends \Test\TestCase {
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class) $manager = $this->getMockBuilder(Manager::class)
->setMethods($mockedManagerMethods) ->setMethods($mockedManagerMethods)
->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([
$this->config,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IEventDispatcher::class)
])
->getMock(); ->getMock();
$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()
@ -753,7 +775,11 @@ class SessionTest extends \Test\TestCase {
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']); $mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class) $manager = $this->getMockBuilder(Manager::class)
->setMethods($mockedManagerMethods) ->setMethods($mockedManagerMethods)
->setConstructorArgs([$this->config, $this->createMock(EventDispatcherInterface::class)]) ->setConstructorArgs([
$this->config,
$this->createMock(EventDispatcherInterface::class),
$this->createMock(IEventDispatcher::class)
])
->getMock(); ->getMock();
$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()
@ -973,7 +999,7 @@ class SessionTest extends \Test\TestCase {
$this->assertFalse($userSession->createSessionToken($request, $uid, $loginName, $password)); $this->assertFalse($userSession->createSessionToken($request, $uid, $loginName, $password));
} }
public function testTryTokenLoginWithDisabledUser() { public function testTryTokenLoginWithDisabledUser() {
$this->expectException(\OC\User\LoginException::class); $this->expectException(\OC\User\LoginException::class);