summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2020-08-11 18:53:50 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2020-08-12 01:19:46 +0200
commiteb1277e78fe298f52997c71c3dc906282fe05275 (patch)
tree0aa70003e9a00562fcf78a6fc9e3c3db3d6861f5 /apps/user_ldap
parent41eb1c0f86071a7294b7a2ab54fdde46fe707a35 (diff)
downloadnextcloud-server-eb1277e78fe298f52997c71c3dc906282fe05275.tar.gz
nextcloud-server-eb1277e78fe298f52997c71c3dc906282fe05275.zip
do not flip available state to unavailable, allow empty results
- the detection relies that the first, requested result is not empty - it might be empty though – groups without members - protect switching from available to unavailable - switching the other way around was also not envisaged either Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/Connection.php1
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php31
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php22
3 files changed, 41 insertions, 13 deletions
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 8d499a4ee1c..47d7a4fdbb7 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -66,6 +66,7 @@ use OCP\ILogger;
* @property string[] ldapBaseGroups
* @property string ldapGroupFilter
* @property string ldapGroupDisplayName
+ * @property string ldapMatchingRuleInChainState
*/
class Connection extends LDAPUtility {
private $ldapConnectionRes = null;
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index 46a0467d15d..e9382206f72 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -240,21 +240,27 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
) {
$attemptedLdapMatchingRuleInChain = true;
// compatibility hack with servers supporting :1.2.840.113556.1.4.1941:, and others)
- $filter = $this->access->combineFilterWithAnd([$this->access->connection->ldapUserFilter, 'memberof:1.2.840.113556.1.4.1941:=' . $dnGroup]);
+ $filter = $this->access->combineFilterWithAnd([
+ $this->access->connection->ldapUserFilter,
+ $this->access->connection->ldapUserDisplayName . '=*',
+ 'memberof:1.2.840.113556.1.4.1941:=' . $dnGroup
+ ]);
$memberRecords = $this->access->fetchListOfUsers(
$filter,
$this->access->userManager->getAttributes(true)
);
- if (!empty($memberRecords)) {
- if ($this->access->connection->ldapMatchingRuleInChainState === Configuration::LDAP_SERVER_FEATURE_UNKNOWN) {
- $this->access->connection->ldapMatchingRuleInChainState = Configuration::LDAP_SERVER_FEATURE_AVAILABLE;
- $this->access->connection->saveConfiguration();
- }
- return array_reduce($memberRecords, function ($carry, $record) {
- $carry[] = $record['dn'][0];
- return $carry;
- }, []);
+ $result = array_reduce($memberRecords, function ($carry, $record) {
+ $carry[] = $record['dn'][0];
+ return $carry;
+ }, []);
+ if ($this->access->connection->ldapMatchingRuleInChainState === Configuration::LDAP_SERVER_FEATURE_AVAILABLE) {
+ return $result;
+ } elseif (!empty($memberRecords)) {
+ $this->access->connection->ldapMatchingRuleInChainState = Configuration::LDAP_SERVER_FEATURE_AVAILABLE;
+ $this->access->connection->saveConfiguration();
+ return $result;
}
+ // when feature availability is unknown, and the result is empty, continue and test with original approach
}
$seen[$dnGroup] = 1;
@@ -269,7 +275,10 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$allMembers += $this->getDynamicGroupMembers($dnGroup);
$this->access->connection->writeToCache($cacheKey, $allMembers);
- if (isset($attemptedLdapMatchingRuleInChain) && !empty($allMembers)) {
+ if (isset($attemptedLdapMatchingRuleInChain)
+ && $this->access->connection->ldapMatchingRuleInChainState === Configuration::LDAP_SERVER_FEATURE_UNKNOWN
+ && !empty($allMembers)
+ ) {
$this->access->connection->ldapMatchingRuleInChainState = Configuration::LDAP_SERVER_FEATURE_UNAVAILABLE;
$this->access->connection->saveConfiguration();
}
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index 3e681233186..f71b2472886 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -127,6 +127,10 @@ class Group_LDAPTest extends TestCase {
->method('countUsers')
->will($this->returnValue(2));
+ $access->userManager->expects($this->any())
+ ->method('getAttributes')
+ ->willReturn(['displayName', 'mail']);
+
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->countUsersInGroup('group');
@@ -167,6 +171,10 @@ class Group_LDAPTest extends TestCase {
return 'foobar' . \OC::$server->getSecureRandom()->generate(7);
}));
+ $access->userManager->expects($this->any())
+ ->method('getAttributes')
+ ->willReturn(['displayName', 'mail']);
+
$groupBackend = new GroupLDAP($access,$pluginManager);
$users = $groupBackend->countUsersInGroup('group', '3');
@@ -535,7 +543,10 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->exactly(2))
->method('nextcloudUserNames')
->willReturnOnConsecutiveCalls(['lisa', 'bart', 'kira', 'brad'], ['walle', 'dino', 'xenia']);
- $access->userManager = $this->createMock(Manager::class);
+
+ $access->userManager->expects($this->any())
+ ->method('getAttributes')
+ ->willReturn(['displayName', 'mail']);
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->usersInGroup('foobar');
@@ -570,7 +581,10 @@ class Group_LDAPTest extends TestCase {
$access->expects($this->once())
->method('nextcloudUserNames')
->will($this->returnValue(array('lisa', 'bart', 'kira', 'brad')));
- $access->userManager = $this->createMock(Manager::class);
+
+ $access->userManager->expects($this->any())
+ ->method('getAttributes')
+ ->willReturn(['displayName', 'mail']);
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->usersInGroup('foobar');
@@ -609,6 +623,10 @@ class Group_LDAPTest extends TestCase {
->method('countUsers')
->will($this->returnValue(4));
+ $access->userManager->expects($this->any())
+ ->method('getAttributes')
+ ->willReturn(['displayName', 'mail']);
+
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->countUsersInGroup('foobar');