diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-11-20 14:22:00 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-12-03 08:03:57 +0100 |
commit | cc80339b39d998c615a5648d2c86b1e431a8b023 (patch) | |
tree | 3fed2c67f37db1e9746bc79013f17a2463896d73 /apps | |
parent | e5c95eed69a1d5e96b69147e4e7f6e40d21c8f9b (diff) | |
download | nextcloud-server-cc80339b39d998c615a5648d2c86b1e431a8b023.tar.gz nextcloud-server-cc80339b39d998c615a5648d2c86b1e431a8b023.zip |
Add typed create user events
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/user_ldap/tests/LDAPProviderTest.php | 139 |
1 files changed, 72 insertions, 67 deletions
diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php index 03756e85cc5..3b2365062ee 100644 --- a/apps/user_ldap/tests/LDAPProviderTest.php +++ b/apps/user_ldap/tests/LDAPProviderTest.php @@ -30,6 +30,7 @@ use OCA\User_LDAP\Access; use OCA\User_LDAP\Connection; use OCA\User_LDAP\IGroupLDAP; use OCA\User_LDAP\IUserLDAP; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IServerContainer; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -46,7 +47,7 @@ class LDAPProviderTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); } - + private function getServerMock(IUserLDAP $userBackend, IGroupLDAP $groupBackend) { $server = $this->getMockBuilder('OC\Server') ->setMethods(['getUserManager', 'getBackends', 'getGroupManager']) @@ -71,7 +72,11 @@ class LDAPProviderTest extends \Test\TestCase { private function getUserManagerMock(IUserLDAP $userBackend) { $userManager = $this->getMockBuilder(Manager::class) ->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(); $userManager->expects($this->any()) ->method('getBackends') @@ -92,9 +97,9 @@ class LDAPProviderTest extends \Test\TestCase { private function getDefaultGroupBackendMock() { $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') - ->disableOriginalConstructor() + ->disableOriginalConstructor() ->getMock(); - + return $groupBackend; } @@ -102,8 +107,8 @@ class LDAPProviderTest extends \Test\TestCase { $factory = new \OCA\User_LDAP\LDAPProviderFactory($serverContainer); return $factory->getLDAPProvider(); } - - + + public function testGetUserDNUserIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('User id not found in LDAP'); @@ -113,13 +118,13 @@ class LDAPProviderTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $userBackend->expects($this->any())->method('userExists')->willReturn(false); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->getUserDN('nonexisting_user'); } - + public function testGetUserDN() { $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists', 'getLDAPAccess', 'username2dn']) @@ -134,15 +139,15 @@ class LDAPProviderTest extends \Test\TestCase { $userBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $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')); } - + public function testGetGroupDNGroupIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Group id not found in LDAP'); @@ -190,7 +195,7 @@ class LDAPProviderTest extends \Test\TestCase { $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org', $ldapProvider->getGroupDN('existing_group')); - } + } public function testGetUserName() { $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') @@ -200,27 +205,27 @@ class LDAPProviderTest extends \Test\TestCase { $userBackend->expects($this->any()) ->method('dn2UserName') ->willReturn('existing_user'); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $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')); } - + public function testDNasBaseParameter() { $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); - + $ldapProvider = $this->getLDAPProvider($server); $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')); } @@ -229,18 +234,18 @@ class LDAPProviderTest extends \Test\TestCase { ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig()); - + $ldapProvider = $this->getLDAPProvider($server); $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')); } - - + + public function testGetLDAPConnectionUserIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('User id not found in LDAP'); @@ -250,13 +255,13 @@ class LDAPProviderTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $userBackend->expects($this->any())->method('userExists')->willReturn(false); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->getLDAPConnection('nonexisting_user'); } - + public function testGetLDAPConnection() { $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists', 'getNewLDAPConnection']) @@ -268,14 +273,14 @@ class LDAPProviderTest extends \Test\TestCase { $userBackend->expects($this->any()) ->method('getNewLDAPConnection') ->willReturn(true); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $this->assertTrue($ldapProvider->getLDAPConnection('existing_user')); } - + public function testGetGroupLDAPConnectionGroupIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Group id not found in LDAP'); @@ -320,8 +325,8 @@ class LDAPProviderTest extends \Test\TestCase { $ldapProvider = $this->getLDAPProvider($server); $this->assertTrue($ldapProvider->getGroupLDAPConnection('existing_group')); } - - + + public function testGetLDAPBaseUsersUserIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('User id not found in LDAP'); @@ -331,13 +336,13 @@ class LDAPProviderTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $userBackend->expects($this->any())->method('userExists')->willReturn(false); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->getLDAPBaseUsers('nonexisting_user'); } - + public function testGetLDAPBaseUsers() { $bases = [ 'ou=users,ou=foobar,dc=example,dc=org', @@ -379,12 +384,12 @@ class LDAPProviderTest extends \Test\TestCase { ->willReturn($access); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals($bases[1], $ldapProvider->getLDAPBaseUsers('existing_user')); } - - + + public function testGetLDAPBaseGroupsUserIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('User id not found in LDAP'); @@ -394,13 +399,13 @@ class LDAPProviderTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $userBackend->expects($this->any())->method('userExists')->willReturn(false); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->getLDAPBaseGroups('nonexisting_user'); } - + public function testGetLDAPBaseGroups() { $bases = [ 'ou=groupd,ou=foobar,dc=example,dc=org', @@ -435,12 +440,12 @@ class LDAPProviderTest extends \Test\TestCase { ->willReturn($access); $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals($bases[0], $ldapProvider->getLDAPBaseGroups('existing_user')); } - - + + public function testClearCacheUserIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('User id not found in LDAP'); @@ -450,13 +455,13 @@ class LDAPProviderTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $userBackend->expects($this->any())->method('userExists')->willReturn(false); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->clearCache('nonexisting_user'); } - + public function testClearCache() { $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['userExists', 'getLDAPAccess', 'getConnection', 'clearCache']) @@ -471,15 +476,15 @@ class LDAPProviderTest extends \Test\TestCase { $userBackend->expects($this->any()) ->method($this->anything()) ->willReturnSelf(); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->clearCache('existing_user'); $this->addToAssertionCount(1); } - + public function testClearGroupCacheGroupIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Group id not found in LDAP'); @@ -523,7 +528,7 @@ class LDAPProviderTest extends \Test\TestCase { $ldapProvider->clearGroupCache('existing_group'); $this->addToAssertionCount(1); } - + public function testDnExists() { $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods(['dn2UserName']) @@ -532,40 +537,40 @@ class LDAPProviderTest extends \Test\TestCase { $userBackend->expects($this->any()) ->method('dn2UserName') ->willReturn('existing_user'); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $this->assertTrue($ldapProvider->dnExists('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); } - + public function testFlagRecord() { $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->flagRecord('existing_user'); $this->addToAssertionCount(1); } - + public function testUnflagRecord() { $userBackend = $this->getMockBuilder('OCA\User_LDAP\User_LDAP') ->setMethods([]) ->disableOriginalConstructor() ->getMock(); - + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - + $ldapProvider = $this->getLDAPProvider($server); $ldapProvider->unflagRecord('existing_user'); $this->addToAssertionCount(1); } - + public function testGetLDAPDisplayNameFieldUserIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('User id not found in LDAP'); @@ -603,7 +608,7 @@ class LDAPProviderTest extends \Test\TestCase { $this->assertEquals('displayName', $ldapProvider->getLDAPDisplayNameField('existing_user')); } - + public function testGetLDAPEmailFieldUserIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('User id not found in LDAP'); @@ -641,7 +646,7 @@ class LDAPProviderTest extends \Test\TestCase { $this->assertEquals('mail', $ldapProvider->getLDAPEmailField('existing_user')); } - + public function testGetLDAPGroupMemberAssocUserIDNotFound() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Group id not found in LDAP'); @@ -687,6 +692,6 @@ class LDAPProviderTest extends \Test\TestCase { $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals('assoc_type', $ldapProvider->getLDAPGroupMemberAssoc('existing_group')); - } + } } |