chore(user_ldap): Adapt code to LDAP constructor change, remove dead code

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2026-03-02 14:58:48 +01:00
parent d8084559a9
commit 279d5c226e
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
5 changed files with 15 additions and 26 deletions

View file

@ -8,11 +8,8 @@
namespace OCA\User_LDAP\Command;
use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\User_Proxy;
use OCP\IConfig;
use OCP\Server;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@ -82,10 +79,6 @@ class Search extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$helper = Server::get(Helper::class);
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();
$offset = (int)$input->getOption('offset');
$limit = (int)$input->getOption('limit');
$this->validateOffsetAndLimit($offset, $limit);

View file

@ -10,14 +10,19 @@ namespace OCA\User_LDAP\Command;
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCP\Server;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SetConfig extends Command {
public function __construct(
private readonly Helper $helper,
private readonly ConnectionFactory $connectionFactory,
) {
parent::__construct();
}
protected function configure(): void {
$this
->setName('ldap:set-config')
@ -41,8 +46,7 @@ class SetConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$helper = Server::get(Helper::class);
$availableConfigs = $helper->getServerConfigurationPrefixes();
$availableConfigs = $this->helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if (!in_array($configID, $availableConfigs)) {
$output->writeln('Invalid configID');
@ -65,7 +69,6 @@ class SetConfig extends Command {
$configHolder->$key = $value;
$configHolder->saveConfiguration();
$connectionFactory = new ConnectionFactory(new LDAP());
$connectionFactory->get($configID)->clearCache();
$this->connectionFactory->get($configID)->clearCache();
}
}

View file

@ -23,8 +23,6 @@ class Sync extends TimedJob {
public const MAX_INTERVAL = 12 * 60 * 60; // 12h
public const MIN_INTERVAL = 30 * 60; // 30min
protected LDAP $ldap;
public function __construct(
ITimeFactory $timeFactory,
private IConfig $config,
@ -42,7 +40,6 @@ class Sync extends TimedJob {
self::MIN_INTERVAL
)
);
$this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
}
/**
@ -253,11 +250,4 @@ class Sync extends TimedJob {
}
return $prefixes[$i];
}
/**
* Only used in tests
*/
public function overwritePropertiesForTest(LDAP $ldapWrapper): void {
$this->ldap = $ldapWrapper;
}
}

View file

@ -29,6 +29,7 @@ use OCP\IConfig;
use OCP\Image;
use OCP\IUserManager;
use OCP\Notification\IManager as INotificationManager;
use OCP\Profiler\IProfiler;
use OCP\Server;
use OCP\Share\IManager;
use PHPUnit\Framework\MockObject\MockObject;
@ -242,7 +243,11 @@ class AccessTest extends TestCase {
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dnInputDataProvider')]
public function testStringResemblesDNLDAPmod(string $input, array|bool $interResult, bool $expectedResult): void {
[, $con, $um, $helper] = $this->getConnectorAndLdapMock();
$lw = new LDAP();
$lw = new LDAP(
$this->createMock(IProfiler::class),
$this->createMock(IConfig::class),
$this->createMock(LoggerInterface::class),
);
$access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
if (!function_exists('ldap_explode_dn')) {

View file

@ -76,8 +76,6 @@ class SyncTest extends TestCase {
$this->connectionFactory,
$this->accessFactory,
);
$this->sync->overwritePropertiesForTest($this->ldapWrapper);
}
public static function intervalDataProvider(): array {