From 660fbd64e34fccb26f1a38d1b67da5618e624875 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 14 Jun 2019 17:20:42 +0200 Subject: [PATCH] ensures mapping of chosen userid Signed-off-by: Arthur Schiwon --- apps/user_ldap/lib/Access.php | 2 +- apps/user_ldap/lib/Group_LDAP.php | 2 +- apps/user_ldap/lib/User_LDAP.php | 22 ++++++++++++++++++++-- apps/user_ldap/tests/User_LDAPTest.php | 19 +++++++++++++++++-- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 6a074bbed2..5db9dddf8f 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -635,7 +635,7 @@ class Access extends LDAPUtility { return false; } - protected function mapAndAnnounceIfApplicable( + public function mapAndAnnounceIfApplicable( AbstractMapping $mapper, string $fdn, string $name, diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index 5b25979b2d..d9059b2372 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -110,7 +110,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD $members = $this->access->connection->getFromCache($cacheKeyMembers); if(!is_null($members)) { $this->cachedGroupMembers[$gid] = $members; - $isInGroup = in_array($userDN, $members); + $isInGroup = in_array($userDN, $members, true); $this->access->connection->writeToCache($cacheKey, $isInGroup); return $isInGroup; } diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index ada07aa53a..5e06547533 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -622,8 +622,26 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn if ($this->userPluginManager->implementsActions(Backend::CREATE_USER)) { if ($dn = $this->userPluginManager->createUser($username, $password)) { if (is_string($dn)) { - //updates user mapping - $this->access->dn2ocname($dn, $username, true); + // the NC user creation work flow requires a know user id up front + $uuid = $this->access->getUUID($dn, true); + if(is_string($uuid)) { + $this->access->mapAndAnnounceIfApplicable( + $this->access->getUserMapper(), + $dn, + $username, + $uuid, + true + ); + $this->access->cacheUserExists($username); + } else { + \OC::$server->getLogger()->warning( + 'Failed to map created LDAP user with userid {userid}, because UUID could not be determined', + [ + 'app' => 'user_ldap', + 'userid' => $username, + ] + ); + } } else { throw new \UnexpectedValueException("LDAP Plugin: Method createUser changed to return the user DN instead of boolean."); } diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index e4f7bb8b6d..9b8bda2b80 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -35,6 +35,7 @@ use OC\User\Backend; use OC\User\Session; use OCA\User_LDAP\Access; use OCA\User_LDAP\Connection; +use OCA\User_LDAP\Mapping\AbstractMapping; use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\User\OfflineUser; @@ -1437,16 +1438,30 @@ class User_LDAPTest extends TestCase { } public function testCreateUserWithPlugin() { + $uid = 'alien6372'; + $uuid = '123-2345-36756-123-2345234-4431'; + $pwd = 'passwørd'; + $this->pluginManager->expects($this->once()) ->method('implementsActions') ->with(Backend::CREATE_USER) ->willReturn(true); $this->pluginManager->expects($this->once()) ->method('createUser') - ->with('uid','password') + ->with($uid, $pwd) ->willReturn('result'); - $this->assertEquals($this->backend->createUser('uid', 'password'),true); + $this->access->expects($this->atLeastOnce()) + ->method('getUUID') + ->willReturn($uuid); + $this->access->expects($this->once()) + ->method('mapAndAnnounceIfApplicable') + ->with($this->isInstanceOf(AbstractMapping::class), $this->anything(), $uid, $uuid, true); + $this->access->expects($this->any()) + ->method('getUserMapper') + ->willReturn($this->createMock(AbstractMapping::class)); + + $this->assertEquals($this->backend->createUser($uid, $pwd),true); } public function testCreateUserFailing() {