summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2023-10-09 22:18:39 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2023-10-10 11:18:57 +0200
commitc1480aade4ebc6988824d93acdb7fe854bdc8be7 (patch)
tree0ec5ed0b9bea3df2d47f06d06ebd82d88fd9bda5 /apps/user_ldap
parent039da6bd22dd38cd8e127e604975856c2509995e (diff)
downloadnextcloud-server-c1480aade4ebc6988824d93acdb7fe854bdc8be7.tar.gz
nextcloud-server-c1480aade4ebc6988824d93acdb7fe854bdc8be7.zip
refactor(LDAP): pass IConfig via constructor to Group_LDAP
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php12
-rw-r--r--apps/user_ldap/lib/Group_Proxy.php8
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php23
-rw-r--r--apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php3
4 files changed, 23 insertions, 23 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index 9afad6ad2ff..df54678db99 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -74,8 +74,9 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
* @var string $ldapGroupMemberAssocAttr contains the LDAP setting (in lower case) with the same name
*/
protected string $ldapGroupMemberAssocAttr;
+ private IConfig $config;
- public function __construct(Access $access, GroupPluginManager $groupPluginManager) {
+ public function __construct(Access $access, GroupPluginManager $groupPluginManager, IConfig $config) {
$this->access = $access;
$filter = $this->access->connection->ldapGroupFilter;
$gAssoc = $this->access->connection->ldapGroupMemberAssocAttr;
@@ -89,6 +90,7 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
$this->groupPluginManager = $groupPluginManager;
$this->logger = Server::get(LoggerInterface::class);
$this->ldapGroupMemberAssocAttr = strtolower((string)$gAssoc);
+ $this->config = $config;
}
/**
@@ -684,9 +686,7 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
if ($user instanceof OfflineUser) {
// We load known group memberships from configuration for remnants,
// because LDAP server does not contain them anymore
- /** @var IConfig $config */
- $config = Server::get(IConfig::class);
- $groupStr = $config->getUserValue($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), '[]');
+ $groupStr = $this->config->getUserValue($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), '[]');
return json_decode($groupStr) ?? [];
}
@@ -803,10 +803,8 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
$groups = array_unique($groups, SORT_LOCALE_STRING);
$this->access->connection->writeToCache($cacheKey, $groups);
- /** @var IConfig $config */
- $config = Server::get(IConfig::class);
$groupStr = \json_encode($groups);
- $config->setUserValue($ncUid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), $groupStr);
+ $this->config->setUserValue($ncUid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), $groupStr);
return $groups;
}
diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php
index 114902ff9ba..01a68466297 100644
--- a/apps/user_ldap/lib/Group_Proxy.php
+++ b/apps/user_ldap/lib/Group_Proxy.php
@@ -35,6 +35,7 @@ use OCP\Group\Backend\IGetDisplayNameBackend;
use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Backend\INamedBackend;
use OCP\GroupInterface;
+use OCP\IConfig;
class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend {
private $backends = [];
@@ -42,16 +43,19 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
private Helper $helper;
private GroupPluginManager $groupPluginManager;
private bool $isSetUp = false;
+ private IConfig $config;
public function __construct(
Helper $helper,
ILDAPWrapper $ldap,
AccessFactory $accessFactory,
- GroupPluginManager $groupPluginManager
+ GroupPluginManager $groupPluginManager,
+ IConfig $config,
) {
parent::__construct($ldap, $accessFactory);
$this->helper = $helper;
$this->groupPluginManager = $groupPluginManager;
+ $this->config = $config;
}
protected function setup(): void {
@@ -62,7 +66,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
$serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
foreach ($serverConfigPrefixes as $configPrefix) {
$this->backends[$configPrefix] =
- new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager);
+ new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->config);
if (is_null($this->refBackend)) {
$this->refBackend = &$this->backends[$configPrefix];
}
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index e66fdd633a2..b4789b09c3d 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -40,7 +40,6 @@ use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\OfflineUser;
use OCP\GroupInterface;
use OCP\IConfig;
-use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -52,24 +51,21 @@ use Test\TestCase;
* @package OCA\User_LDAP\Tests
*/
class Group_LDAPTest extends TestCase {
+ private MockObject|Access $access;
+ private MockObject|GroupPluginManager $pluginManager;
+ private MockObject|IConfig $config;
+ private GroupLDAP $groupBackend;
public function setUp(): void {
parent::setUp();
$this->access = $this->getAccessMock();
$this->pluginManager = $this->createMock(GroupPluginManager::class);
+ $this->config = $this->createMock(IConfig::class);
}
public function initBackend(): void {
- $this->groupBackend = new GroupLDAP($this->access, $this->pluginManager);
- }
-
-
- public function tearDown(): void {
- parent::tearDown();
-
- $realConfig = Server::get(IConfig::class);
- $realConfig->deleteUserValue('userX', 'user_ldap', 'cached-group-memberships-');
+ $this->groupBackend = new GroupLDAP($this->access, $this->pluginManager, $this->config);
}
public function testCountEmptySearchString() {
@@ -848,9 +844,10 @@ class Group_LDAPTest extends TestCase {
$offlineUser = $this->createMock(OfflineUser::class);
- // FIXME: should be available via CI
- $realConfig = Server::get(IConfig::class);
- $realConfig->setUserValue('userX', 'user_ldap', 'cached-group-memberships-', \json_encode(['groupB', 'groupF']));
+ $this->config->expects($this->any())
+ ->method('getUserValue')
+ ->with('userX', 'user_ldap', 'cached-group-memberships-', $this->anything())
+ ->willReturn(\json_encode(['groupB', 'groupF']));
$this->access->userManager->expects($this->any())
->method('get')
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
index a742c0b8076..e77b3aec6b0 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php
@@ -31,6 +31,7 @@ use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;
+use OCP\IConfig;
use Psr\Log\LoggerInterface;
require_once __DIR__ . '/../Bootstrap.php';
@@ -58,7 +59,7 @@ class IntegrationTestAttributeDetection extends AbstractIntegrationTest {
$userManager->clearBackends();
$userManager->registerBackend($userBackend);
- $groupBackend = new Group_LDAP($this->access, \OC::$server->query(GroupPluginManager::class));
+ $groupBackend = new Group_LDAP($this->access, \OC::$server->query(GroupPluginManager::class), \OC::$server->get(IConfig::class));
$groupManger = \OC::$server->getGroupManager();
$groupManger->clearBackends();
$groupManger->addBackend($groupBackend);