Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2018-05-29 17:55:14 +0300
committerGitHub <noreply@github.com>2018-05-29 17:55:14 +0300
commitc0ed6f91a8217c9a1cbb720167bfd0d85bd467bc (patch)
tree76a31764191143464a9dbc653b8d745aece29bf3 /apps
parent7f301be188bc8dd08f624e9ccc74f9795d347c2a (diff)
parent73cacb8896ac067e4686ef8d4471ba497248a729 (diff)
Merge pull request #9640 from nextcloud/fix/9502/missedstatecheck
check user state when fetching to avoid dealing with offline objects, fixes #9502
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/lib/Access.php25
-rw-r--r--apps/user_ldap/tests/AccessTest.php39
2 files changed, 56 insertions, 8 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 3557f45a32f..91089e779a0 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -54,7 +54,6 @@ use OC\ServerNotAvailableException;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserManager;
-use OCP\Util;
/**
* Class Access
@@ -664,6 +663,7 @@ class Access extends LDAPUtility implements IUserTools {
* @param array $ldapObjects as returned by fetchList()
* @param bool $isUsers
* @return array
+ * @throws \Exception
*/
private function ldap2NextcloudNames($ldapObjects, $isUsers) {
if($isUsers) {
@@ -672,7 +672,7 @@ class Access extends LDAPUtility implements IUserTools {
} else {
$nameAttribute = $this->connection->ldapGroupDisplayName;
}
- $nextcloudNames = array();
+ $nextcloudNames = [];
foreach($ldapObjects as $ldapObject) {
$nameByLDAP = null;
@@ -688,6 +688,7 @@ class Access extends LDAPUtility implements IUserTools {
if($ncName) {
$nextcloudNames[] = $ncName;
if($isUsers) {
+ $this->updateUserState($ncName);
//cache the user names so it does not need to be retrieved
//again later (e.g. sharing dialogue).
if(is_null($nameByLDAP)) {
@@ -703,6 +704,19 @@ class Access extends LDAPUtility implements IUserTools {
}
/**
+ * removes the deleted-flag of a user if it was set
+ *
+ * @param string $ncname
+ * @throws \Exception
+ */
+ public function updateUserState($ncname) {
+ $user = $this->userManager->get($ncname);
+ if($user instanceof OfflineUser) {
+ $user->unmark();
+ }
+ }
+
+ /**
* caches the user display name
* @param string $ocName the internal Nextcloud username
* @param string|false $home the home directory path
@@ -873,7 +887,9 @@ class Access extends LDAPUtility implements IUserTools {
* provided with an array of LDAP user records the method will fetch the
* user object and requests it to process the freshly fetched attributes and
* and their values
+ *
* @param array $ldapRecords
+ * @throws \Exception
*/
public function batchApplyUserAttributes(array $ldapRecords){
$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
@@ -886,11 +902,8 @@ class Access extends LDAPUtility implements IUserTools {
if($ocName === false) {
continue;
}
+ $this->updateUserState($ocName);
$user = $this->userManager->get($ocName);
- if($user instanceof OfflineUser) {
- $user->unmark();
- $user = $this->userManager->get($ocName);
- }
if ($user !== null) {
$user->processAttributes($userRecord);
} else {
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index 43a34959c54..a51a396cfff 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -43,6 +43,7 @@ use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\LogWrapper;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager;
+use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
use OCP\IAvatarManager;
use OCP\IConfig;
@@ -316,7 +317,7 @@ class AccessTest extends TestCase {
$userMock->expects($this->exactly(count($data)))
->method('processAttributes');
- $this->userManager->expects($this->exactly(count($data)))
+ $this->userManager->expects($this->exactly(count($data) * 2))
->method('get')
->will($this->returnValue($userMock));
@@ -398,7 +399,7 @@ class AccessTest extends TestCase {
$userMock->expects($this->exactly(count($data)))
->method('processAttributes');
- $this->userManager->expects($this->exactly(count($data)))
+ $this->userManager->expects($this->exactly(count($data) * 2))
->method('get')
->will($this->returnValue($userMock));
@@ -666,6 +667,40 @@ class AccessTest extends TestCase {
$this->assertSame($expected, $sanitizedName);
}
+ public function testUserStateUpdate() {
+ $this->connection->expects($this->any())
+ ->method('__get')
+ ->willReturnMap([
+ [ 'ldapUserDisplayName', 'displayName' ],
+ [ 'ldapUserDisplayName2', null],
+ ]);
+
+ $offlineUserMock = $this->createMock(OfflineUser::class);
+ $offlineUserMock->expects($this->once())
+ ->method('unmark');
+
+ $regularUserMock = $this->createMock(User::class);
+
+ $this->userManager->expects($this->atLeastOnce())
+ ->method('get')
+ ->with('detta')
+ ->willReturnOnConsecutiveCalls($offlineUserMock, $regularUserMock);
+
+ /** @var UserMapping|\PHPUnit_Framework_MockObject_MockObject $mapperMock */
+ $mapperMock = $this->createMock(UserMapping::class);
+ $mapperMock->expects($this->any())
+ ->method('getNameByDN')
+ ->with('uid=detta,ou=users,dc=hex,dc=ample')
+ ->willReturn('detta');
+ $this->access->setUserMapper($mapperMock);
+ $records = [
+ [
+ 'dn' => ['uid=detta,ou=users,dc=hex,dc=ample'],
+ 'displayName' => ['Detta Detkova'],
+ ]
+ ];
+ $this->access->nextcloudUserNames($records);
+ }
}