Skip to content

Commit 279d5c2

Browse files
committed
chore(user_ldap): Adapt code to LDAP constructor change, remove dead code
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent d808455 commit 279d5c2

5 files changed

Lines changed: 15 additions & 26 deletions

File tree

apps/user_ldap/lib/Command/Search.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
namespace OCA\User_LDAP\Command;
99

1010
use OCA\User_LDAP\Group_Proxy;
11-
use OCA\User_LDAP\Helper;
12-
use OCA\User_LDAP\LDAP;
1311
use OCA\User_LDAP\User_Proxy;
1412
use OCP\IConfig;
15-
use OCP\Server;
1613

1714
use Symfony\Component\Console\Command\Command;
1815
use Symfony\Component\Console\Input\InputArgument;
@@ -82,10 +79,6 @@ protected function validateOffsetAndLimit(int $offset, int $limit): void {
8279
}
8380

8481
protected function execute(InputInterface $input, OutputInterface $output): int {
85-
$helper = Server::get(Helper::class);
86-
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
87-
$ldapWrapper = new LDAP();
88-
8982
$offset = (int)$input->getOption('offset');
9083
$limit = (int)$input->getOption('limit');
9184
$this->validateOffsetAndLimit($offset, $limit);

apps/user_ldap/lib/Command/SetConfig.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010
use OCA\User_LDAP\Configuration;
1111
use OCA\User_LDAP\ConnectionFactory;
1212
use OCA\User_LDAP\Helper;
13-
use OCA\User_LDAP\LDAP;
14-
use OCP\Server;
1513
use Symfony\Component\Console\Command\Command;
1614
use Symfony\Component\Console\Input\InputArgument;
1715
use Symfony\Component\Console\Input\InputInterface;
1816
use Symfony\Component\Console\Output\OutputInterface;
1917

2018
class SetConfig extends Command {
19+
public function __construct(
20+
private readonly Helper $helper,
21+
private readonly ConnectionFactory $connectionFactory,
22+
) {
23+
parent::__construct();
24+
}
25+
2126
protected function configure(): void {
2227
$this
2328
->setName('ldap:set-config')
@@ -41,8 +46,7 @@ protected function configure(): void {
4146
}
4247

4348
protected function execute(InputInterface $input, OutputInterface $output): int {
44-
$helper = Server::get(Helper::class);
45-
$availableConfigs = $helper->getServerConfigurationPrefixes();
49+
$availableConfigs = $this->helper->getServerConfigurationPrefixes();
4650
$configID = $input->getArgument('configID');
4751
if (!in_array($configID, $availableConfigs)) {
4852
$output->writeln('Invalid configID');
@@ -65,7 +69,6 @@ protected function setValue(string $configID, string $key, string $value): void
6569
$configHolder->$key = $value;
6670
$configHolder->saveConfiguration();
6771

68-
$connectionFactory = new ConnectionFactory(new LDAP());
69-
$connectionFactory->get($configID)->clearCache();
72+
$this->connectionFactory->get($configID)->clearCache();
7073
}
7174
}

apps/user_ldap/lib/Jobs/Sync.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class Sync extends TimedJob {
2323
public const MAX_INTERVAL = 12 * 60 * 60; // 12h
2424
public const MIN_INTERVAL = 30 * 60; // 30min
2525

26-
protected LDAP $ldap;
27-
2826
public function __construct(
2927
ITimeFactory $timeFactory,
3028
private IConfig $config,
@@ -42,7 +40,6 @@ public function __construct(
4240
self::MIN_INTERVAL
4341
)
4442
);
45-
$this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
4643
}
4744

4845
/**
@@ -253,11 +250,4 @@ protected function getNextPrefix(?string $lastPrefix): ?string {
253250
}
254251
return $prefixes[$i];
255252
}
256-
257-
/**
258-
* Only used in tests
259-
*/
260-
public function overwritePropertiesForTest(LDAP $ldapWrapper): void {
261-
$this->ldap = $ldapWrapper;
262-
}
263253
}

apps/user_ldap/tests/AccessTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\Image;
3030
use OCP\IUserManager;
3131
use OCP\Notification\IManager as INotificationManager;
32+
use OCP\Profiler\IProfiler;
3233
use OCP\Server;
3334
use OCP\Share\IManager;
3435
use PHPUnit\Framework\MockObject\MockObject;
@@ -242,7 +243,11 @@ public function testStringResemblesDN(string $input, array|bool $interResult, bo
242243
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dnInputDataProvider')]
243244
public function testStringResemblesDNLDAPmod(string $input, array|bool $interResult, bool $expectedResult): void {
244245
[, $con, $um, $helper] = $this->getConnectorAndLdapMock();
245-
$lw = new LDAP();
246+
$lw = new LDAP(
247+
$this->createMock(IProfiler::class),
248+
$this->createMock(IConfig::class),
249+
$this->createMock(LoggerInterface::class),
250+
);
246251
$access = new Access($lw, $con, $um, $helper, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
247252

248253
if (!function_exists('ldap_explode_dn')) {

apps/user_ldap/tests/Jobs/SyncTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ protected function setUp(): void {
7676
$this->connectionFactory,
7777
$this->accessFactory,
7878
);
79-
80-
$this->sync->overwritePropertiesForTest($this->ldapWrapper);
8179
}
8280

8381
public static function intervalDataProvider(): array {

0 commit comments

Comments
 (0)