mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
feat(user_ldap): Introduce user id assigned typed events for LDAP usage
Based on work from https://github.com/nextcloud/server/pull/32019 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
82ba7d763b
commit
986a3d45f8
11 changed files with 240 additions and 192 deletions
|
|
@ -5,8 +5,13 @@
|
|||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
use OCA\User_LDAP\Mapping\GroupMapping;
|
||||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Server;
|
||||
use OCP\User\Events\BeforeUserIdUnassignedEvent;
|
||||
use OCP\User\Events\UserIdUnassignedEvent;
|
||||
|
||||
// Check user and app status
|
||||
\OC_JSON::checkAdminUser();
|
||||
|
|
@ -17,12 +22,16 @@ $subject = (string)$_POST['ldap_clear_mapping'];
|
|||
$mapping = null;
|
||||
try {
|
||||
if ($subject === 'user') {
|
||||
$mapping = \OCP\Server::get(UserMapping::class);
|
||||
$mapping = Server::get(UserMapping::class);
|
||||
/** @var IEventDispatcher $dispatcher */
|
||||
$dispatcher = Server::get(IEventDispatcher::class);
|
||||
$result = $mapping->clearCb(
|
||||
function ($uid) {
|
||||
function (string $uid) use ($dispatcher): void {
|
||||
$dispatcher->dispatchTyped(new BeforeUserIdUnassignedEvent($uid));
|
||||
\OC::$server->getUserManager()->emit('\OC\User', 'preUnassignedUserId', [$uid]);
|
||||
},
|
||||
function ($uid) {
|
||||
function (string $uid) use ($dispatcher): void {
|
||||
$dispatcher->dispatchTyped(new UserIdUnassignedEvent($uid));
|
||||
\OC::$server->getUserManager()->emit('\OC\User', 'postUnassignedUserId', [$uid]);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -15,10 +15,12 @@ use OCA\User_LDAP\Exceptions\NoMoreResults;
|
|||
use OCA\User_LDAP\Mapping\AbstractMapping;
|
||||
use OCA\User_LDAP\User\Manager;
|
||||
use OCA\User_LDAP\User\OfflineUser;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\HintException;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUserManager;
|
||||
use OCP\User\Events\UserIdAssignedEvent;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
|
|
@ -42,6 +44,7 @@ class Access extends LDAPUtility {
|
|||
|
||||
/** @var ?AbstractMapping */
|
||||
protected $groupMapper;
|
||||
|
||||
private string $lastCookie = '';
|
||||
|
||||
public function __construct(
|
||||
|
|
@ -53,15 +56,10 @@ class Access extends LDAPUtility {
|
|||
private IUserManager $ncUserManager,
|
||||
private LoggerInterface $logger,
|
||||
private IAppConfig $appConfig,
|
||||
private IEventDispatcher $dispatcher,
|
||||
) {
|
||||
parent::__construct($ldap);
|
||||
$this->connection = $connection;
|
||||
$this->userManager = $userManager;
|
||||
$this->userManager->setLdapAccess($this);
|
||||
$this->helper = $helper;
|
||||
$this->config = $config;
|
||||
$this->ncUserManager = $ncUserManager;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -630,10 +628,13 @@ class Access extends LDAPUtility {
|
|||
bool $isUser
|
||||
): bool {
|
||||
if ($mapper->map($fdn, $name, $uuid)) {
|
||||
if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
|
||||
if ($isUser) {
|
||||
$this->cacheUserExists($name);
|
||||
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
|
||||
} elseif (!$isUser) {
|
||||
$this->dispatcher->dispatchTyped(new UserIdAssignedEvent($name));
|
||||
if ($this->ncUserManager instanceof PublicEmitter) {
|
||||
$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
|
||||
}
|
||||
} else {
|
||||
$this->cacheGroupExists($name);
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
namespace OCA\User_LDAP;
|
||||
|
||||
use OCA\User_LDAP\User\Manager;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUserManager;
|
||||
|
|
@ -21,12 +22,8 @@ class AccessFactory {
|
|||
private IAppConfig $appConfig,
|
||||
private IUserManager $ncUserManager,
|
||||
private LoggerInterface $logger,
|
||||
private IEventDispatcher $dispatcher,
|
||||
) {
|
||||
$this->ldap = $ldap;
|
||||
$this->helper = $helper;
|
||||
$this->config = $config;
|
||||
$this->ncUserManager = $ncUserManager;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function get(Connection $connection): Access {
|
||||
|
|
@ -40,6 +37,7 @@ class AccessFactory {
|
|||
$this->ncUserManager,
|
||||
$this->logger,
|
||||
$this->appConfig,
|
||||
$this->dispatcher,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\User_LDAP\Jobs;
|
||||
|
||||
use OC\ServerNotAvailableException;
|
||||
|
|
@ -14,6 +16,7 @@ use OCA\User_LDAP\LDAP;
|
|||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\BackgroundJob\TimedJob;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IAvatarManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
|
|
@ -24,44 +27,38 @@ use Psr\Log\LoggerInterface;
|
|||
class Sync extends TimedJob {
|
||||
public const MAX_INTERVAL = 12 * 60 * 60; // 12h
|
||||
public const MIN_INTERVAL = 30 * 60; // 30min
|
||||
/** @var Helper */
|
||||
protected $ldapHelper;
|
||||
/** @var LDAP */
|
||||
protected $ldap;
|
||||
/** @var UserMapping */
|
||||
protected $mapper;
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
/** @var IAvatarManager */
|
||||
protected $avatarManager;
|
||||
/** @var IDBConnection */
|
||||
protected $dbc;
|
||||
/** @var IUserManager */
|
||||
protected $ncUserManager;
|
||||
/** @var LoggerInterface */
|
||||
protected $logger;
|
||||
/** @var IManager */
|
||||
protected $notificationManager;
|
||||
/** @var ConnectionFactory */
|
||||
protected $connectionFactory;
|
||||
/** @var AccessFactory */
|
||||
protected $accessFactory;
|
||||
|
||||
public function __construct(ITimeFactory $time) {
|
||||
parent::__construct($time);
|
||||
protected LDAP $ldap;
|
||||
|
||||
public function __construct(
|
||||
ITimeFactory $timeFactory,
|
||||
private IEventDispatcher $dispatcher,
|
||||
private IConfig $config,
|
||||
private IDBConnection $dbc,
|
||||
private IAvatarManager $avatarManager,
|
||||
private IUserManager $ncUserManager,
|
||||
private LoggerInterface $logger,
|
||||
private IManager $notificationManager,
|
||||
private UserMapping $mapper,
|
||||
private Helper $ldapHelper,
|
||||
private ConnectionFactory $connectionFactory,
|
||||
private AccessFactory $accessFactory,
|
||||
) {
|
||||
parent::__construct($timeFactory);
|
||||
$this->setInterval(
|
||||
(int)\OC::$server->getConfig()->getAppValue(
|
||||
(int)$this->config->getAppValue(
|
||||
'user_ldap',
|
||||
'background_sync_interval',
|
||||
(string)self::MIN_INTERVAL
|
||||
)
|
||||
);
|
||||
$this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the interval
|
||||
* Updates the interval
|
||||
*
|
||||
* the idea is to adjust the interval depending on the amount of known users
|
||||
* The idea is to adjust the interval depending on the amount of known users
|
||||
* and the attempt to update each user one day. At most it would run every
|
||||
* 30 minutes, and at least every 12 hours.
|
||||
*/
|
||||
|
|
@ -79,9 +76,8 @@ class Sync extends TimedJob {
|
|||
|
||||
/**
|
||||
* returns the smallest configured paging size
|
||||
* @return int
|
||||
*/
|
||||
protected function getMinPagingSize() {
|
||||
protected function getMinPagingSize(): int {
|
||||
$configKeys = $this->config->getAppKeys('user_ldap');
|
||||
$configKeys = array_filter($configKeys, function ($key) {
|
||||
return str_contains($key, 'ldap_paging_size');
|
||||
|
|
@ -98,8 +94,6 @@ class Sync extends TimedJob {
|
|||
* @param array $argument
|
||||
*/
|
||||
public function run($argument) {
|
||||
$this->setArgument($argument);
|
||||
|
||||
$isBackgroundJobModeAjax = $this->config
|
||||
->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
|
||||
if ($isBackgroundJobModeAjax) {
|
||||
|
|
@ -134,10 +128,10 @@ class Sync extends TimedJob {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $cycleData
|
||||
* @param array{offset: int, prefix: string} $cycleData
|
||||
* @return bool whether more results are expected from the same configuration
|
||||
*/
|
||||
public function runCycle($cycleData) {
|
||||
public function runCycle(array $cycleData): bool {
|
||||
$connection = $this->connectionFactory->get($cycleData['prefix']);
|
||||
$access = $this->accessFactory->get($connection);
|
||||
$access->setUserMapper($this->mapper);
|
||||
|
|
@ -162,24 +156,22 @@ class Sync extends TimedJob {
|
|||
}
|
||||
|
||||
/**
|
||||
* returns the info about the current cycle that should be run, if any,
|
||||
* Returns the info about the current cycle that should be run, if any,
|
||||
* otherwise null
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getCycle() {
|
||||
public function getCycle(): ?array {
|
||||
$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
|
||||
if (count($prefixes) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cycleData = [
|
||||
'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', null),
|
||||
'prefix' => $this->config->getAppValue('user_ldap', 'background_sync_prefix', 'none'),
|
||||
'offset' => (int)$this->config->getAppValue('user_ldap', 'background_sync_offset', '0'),
|
||||
];
|
||||
|
||||
if (
|
||||
$cycleData['prefix'] !== null
|
||||
$cycleData['prefix'] !== 'none'
|
||||
&& in_array($cycleData['prefix'], $prefixes)
|
||||
) {
|
||||
return $cycleData;
|
||||
|
|
@ -191,21 +183,21 @@ class Sync extends TimedJob {
|
|||
/**
|
||||
* Save the provided cycle information in the DB
|
||||
*
|
||||
* @param array $cycleData
|
||||
* @param array{prefix: ?string, offset: int} $cycleData
|
||||
*/
|
||||
public function setCycle(array $cycleData) {
|
||||
public function setCycle(array $cycleData): void {
|
||||
$this->config->setAppValue('user_ldap', 'background_sync_prefix', $cycleData['prefix']);
|
||||
$this->config->setAppValue('user_ldap', 'background_sync_offset', $cycleData['offset']);
|
||||
$this->config->setAppValue('user_ldap', 'background_sync_offset', (string)$cycleData['offset']);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns data about the next cycle that should run, if any, otherwise
|
||||
* null. It also always goes for the next LDAP configuration!
|
||||
*
|
||||
* @param array|null $cycleData the old cycle
|
||||
* @return array|null
|
||||
* @param ?array{prefix: string, offset: int} $cycleData the old cycle
|
||||
* @return ?array{prefix: string, offset: int}
|
||||
*/
|
||||
public function determineNextCycle(?array $cycleData = null) {
|
||||
public function determineNextCycle(?array $cycleData = null): ?array {
|
||||
$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
|
||||
if (count($prefixes) === 0) {
|
||||
return null;
|
||||
|
|
@ -225,13 +217,12 @@ class Sync extends TimedJob {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks whether the provided cycle should be run. Currently only the
|
||||
* Checks whether the provided cycle should be run. Currently, only the
|
||||
* last configuration change goes into account (at least one hour).
|
||||
*
|
||||
* @param $cycleData
|
||||
* @return bool
|
||||
* @param array{prefix: string} $cycleData
|
||||
*/
|
||||
public function qualifiesToRun($cycleData) {
|
||||
public function qualifiesToRun(array $cycleData): bool {
|
||||
$lastChange = (int)$this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', '0');
|
||||
if ((time() - $lastChange) > 60 * 30) {
|
||||
return true;
|
||||
|
|
@ -240,23 +231,20 @@ class Sync extends TimedJob {
|
|||
}
|
||||
|
||||
/**
|
||||
* increases the offset of the current cycle for the next run
|
||||
* Increases the offset of the current cycle for the next run
|
||||
*
|
||||
* @param $cycleData
|
||||
* @param array{prefix: string, offset: int} $cycleData
|
||||
*/
|
||||
protected function increaseOffset($cycleData) {
|
||||
protected function increaseOffset(array $cycleData): void {
|
||||
$ldapConfig = new Configuration($cycleData['prefix']);
|
||||
$cycleData['offset'] += (int)$ldapConfig->ldapPagingSize;
|
||||
$this->setCycle($cycleData);
|
||||
}
|
||||
|
||||
/**
|
||||
* determines the next configuration prefix based on the last one (if any)
|
||||
*
|
||||
* @param string|null $lastPrefix
|
||||
* @return string|null
|
||||
* Determines the next configuration prefix based on the last one (if any)
|
||||
*/
|
||||
protected function getNextPrefix($lastPrefix) {
|
||||
protected function getNextPrefix(?string $lastPrefix): ?string {
|
||||
$prefixes = $this->ldapHelper->getServerConfigurationPrefixes(true);
|
||||
$noOfPrefixes = count($prefixes);
|
||||
if ($noOfPrefixes === 0) {
|
||||
|
|
@ -276,73 +264,9 @@ class Sync extends TimedJob {
|
|||
}
|
||||
|
||||
/**
|
||||
* "fixes" DI
|
||||
* Only used in tests
|
||||
*/
|
||||
public function setArgument($argument) {
|
||||
if (isset($argument['config'])) {
|
||||
$this->config = $argument['config'];
|
||||
} else {
|
||||
$this->config = \OC::$server->getConfig();
|
||||
}
|
||||
|
||||
if (isset($argument['helper'])) {
|
||||
$this->ldapHelper = $argument['helper'];
|
||||
} else {
|
||||
$this->ldapHelper = new Helper($this->config, \OC::$server->getDatabaseConnection());
|
||||
}
|
||||
|
||||
if (isset($argument['ldapWrapper'])) {
|
||||
$this->ldap = $argument['ldapWrapper'];
|
||||
} else {
|
||||
$this->ldap = new LDAP($this->config->getSystemValueString('ldap_log_file'));
|
||||
}
|
||||
|
||||
if (isset($argument['avatarManager'])) {
|
||||
$this->avatarManager = $argument['avatarManager'];
|
||||
} else {
|
||||
$this->avatarManager = \OC::$server->get(IAvatarManager::class);
|
||||
}
|
||||
|
||||
if (isset($argument['dbc'])) {
|
||||
$this->dbc = $argument['dbc'];
|
||||
} else {
|
||||
$this->dbc = \OC::$server->getDatabaseConnection();
|
||||
}
|
||||
|
||||
if (isset($argument['ncUserManager'])) {
|
||||
$this->ncUserManager = $argument['ncUserManager'];
|
||||
} else {
|
||||
$this->ncUserManager = \OC::$server->getUserManager();
|
||||
}
|
||||
|
||||
if (isset($argument['logger'])) {
|
||||
$this->logger = $argument['logger'];
|
||||
} else {
|
||||
$this->logger = \OC::$server->get(LoggerInterface::class);
|
||||
}
|
||||
|
||||
if (isset($argument['notificationManager'])) {
|
||||
$this->notificationManager = $argument['notificationManager'];
|
||||
} else {
|
||||
$this->notificationManager = \OC::$server->getNotificationManager();
|
||||
}
|
||||
|
||||
if (isset($argument['mapper'])) {
|
||||
$this->mapper = $argument['mapper'];
|
||||
} else {
|
||||
$this->mapper = \OCP\Server::get(UserMapping::class);
|
||||
}
|
||||
|
||||
if (isset($argument['connectionFactory'])) {
|
||||
$this->connectionFactory = $argument['connectionFactory'];
|
||||
} else {
|
||||
$this->connectionFactory = new ConnectionFactory($this->ldap);
|
||||
}
|
||||
|
||||
if (isset($argument['accessFactory'])) {
|
||||
$this->accessFactory = $argument['accessFactory'];
|
||||
} else {
|
||||
$this->accessFactory = \OCP\Server::get(AccessFactory::class);
|
||||
}
|
||||
public function overwritePropertiesForTest(LDAP $ldapWrapper): void {
|
||||
$this->ldap = $ldapWrapper;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ 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\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\IAvatarManager;
|
||||
use OCP\IConfig;
|
||||
|
|
@ -37,29 +38,31 @@ use Test\TestCase;
|
|||
* @package OCA\User_LDAP\Tests
|
||||
*/
|
||||
class AccessTest extends TestCase {
|
||||
/** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var UserMapping|MockObject */
|
||||
protected $userMapper;
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var IManager|MockObject */
|
||||
protected $shareManager;
|
||||
/** @var GroupMapping|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var GroupMapping|MockObject */
|
||||
protected $groupMapper;
|
||||
/** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var Connection|MockObject */
|
||||
private $connection;
|
||||
/** @var LDAP|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var LDAP|MockObject */
|
||||
private $ldap;
|
||||
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var Manager|MockObject */
|
||||
private $userManager;
|
||||
/** @var Helper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var Helper|MockObject */
|
||||
private $helper;
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var IUserManager|MockObject */
|
||||
private $ncUserManager;
|
||||
|
||||
private LoggerInterface&MockObject $logger;
|
||||
|
||||
private IAppConfig&MockObject $appConfig;
|
||||
|
||||
/** @var IEventDispatcher|MockObject */
|
||||
private $dispatcher;
|
||||
private Access $access;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
@ -74,6 +77,7 @@ class AccessTest extends TestCase {
|
|||
$this->shareManager = $this->createMock(IManager::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->appConfig = $this->createMock(IAppConfig::class);
|
||||
$this->dispatcher = $this->createMock(IEventDispatcher::class);
|
||||
|
||||
$this->access = new Access(
|
||||
$this->ldap,
|
||||
|
|
@ -84,7 +88,9 @@ class AccessTest extends TestCase {
|
|||
$this->ncUserManager,
|
||||
$this->logger,
|
||||
$this->appConfig,
|
||||
$this->dispatcher,
|
||||
);
|
||||
$this->dispatcher->expects($this->any())->method('dispatchTyped');
|
||||
$this->access->setUserMapper($this->userMapper);
|
||||
$this->access->setGroupMapper($this->groupMapper);
|
||||
}
|
||||
|
|
@ -227,9 +233,9 @@ class AccessTest extends TestCase {
|
|||
*/
|
||||
public function testStringResemblesDN($case) {
|
||||
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock();
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject $config */
|
||||
/** @var IConfig|MockObject $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig);
|
||||
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
|
||||
|
||||
$lw->expects($this->exactly(1))
|
||||
->method('explodeDN')
|
||||
|
|
@ -249,10 +255,10 @@ class AccessTest extends TestCase {
|
|||
*/
|
||||
public function testStringResemblesDNLDAPmod($case) {
|
||||
[, $con, $um, $helper] = $this->getConnectorAndLdapMock();
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject $config */
|
||||
/** @var IConfig|MockObject $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$lw = new LDAP();
|
||||
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig);
|
||||
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
|
||||
|
||||
if (!function_exists('ldap_explode_dn')) {
|
||||
$this->markTestSkipped('LDAP Module not available');
|
||||
|
|
@ -282,7 +288,7 @@ class AccessTest extends TestCase {
|
|||
->method('getAttributes')
|
||||
->willReturn(['displayname' => ['bar', 'count' => 1]]);
|
||||
|
||||
/** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject $mapperMock */
|
||||
/** @var UserMapping|MockObject $mapperMock */
|
||||
$mapperMock = $this->createMock(UserMapping::class);
|
||||
$mapperMock->expects($this->any())
|
||||
->method('getNameByDN')
|
||||
|
|
@ -327,7 +333,7 @@ class AccessTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testBatchApplyUserAttributesSkipped() {
|
||||
/** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject $mapperMock */
|
||||
/** @var UserMapping|MockObject $mapperMock */
|
||||
$mapperMock = $this->createMock(UserMapping::class);
|
||||
$mapperMock->expects($this->any())
|
||||
->method('getNameByDN')
|
||||
|
|
@ -368,7 +374,7 @@ class AccessTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testBatchApplyUserAttributesDontSkip() {
|
||||
/** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject $mapperMock */
|
||||
/** @var UserMapping|MockObject $mapperMock */
|
||||
$mapperMock = $this->createMock(UserMapping::class);
|
||||
$mapperMock->expects($this->any())
|
||||
->method('getNameByDN')
|
||||
|
|
@ -424,7 +430,7 @@ class AccessTest extends TestCase {
|
|||
*/
|
||||
public function testSanitizeDN($attribute) {
|
||||
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock();
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject $config */
|
||||
/** @var IConfig|MockObject $config */
|
||||
$config = $this->createMock(IConfig::class);
|
||||
|
||||
$dnFromServer = 'cn=Mixed Cases,ou=Are Sufficient To,ou=Test,dc=example,dc=org';
|
||||
|
|
@ -438,7 +444,7 @@ class AccessTest extends TestCase {
|
|||
$attribute => ['count' => 1, $dnFromServer]
|
||||
]);
|
||||
|
||||
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig);
|
||||
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig, $this->dispatcher);
|
||||
$values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute);
|
||||
$this->assertSame($values[0], strtolower($dnFromServer));
|
||||
}
|
||||
|
|
@ -744,7 +750,7 @@ class AccessTest extends TestCase {
|
|||
->with('detta')
|
||||
->willReturnOnConsecutiveCalls($offlineUserMock, $regularUserMock);
|
||||
|
||||
/** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject $mapperMock */
|
||||
/** @var UserMapping|MockObject $mapperMock */
|
||||
$mapperMock = $this->createMock(UserMapping::class);
|
||||
$mapperMock->expects($this->any())
|
||||
->method('getNameByDN')
|
||||
|
|
|
|||
|
|
@ -15,39 +15,42 @@ use OCA\User_LDAP\LDAP;
|
|||
use OCA\User_LDAP\Mapping\UserMapping;
|
||||
use OCA\User_LDAP\User\Manager;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IAvatarManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Notification\IManager;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class SyncTest extends TestCase {
|
||||
/** @var array */
|
||||
protected $arguments;
|
||||
/** @var Helper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var Helper|MockObject */
|
||||
protected $helper;
|
||||
/** @var LDAP|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var LDAP|MockObject */
|
||||
protected $ldapWrapper;
|
||||
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var Manager|MockObject */
|
||||
protected $userManager;
|
||||
/** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var UserMapping|MockObject */
|
||||
protected $mapper;
|
||||
/** @var Sync */
|
||||
protected $sync;
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected Sync $sync;
|
||||
/** @var IConfig|MockObject */
|
||||
protected $config;
|
||||
/** @var IAvatarManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var IAvatarManager|MockObject */
|
||||
protected $avatarManager;
|
||||
/** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var IDBConnection|MockObject */
|
||||
protected $dbc;
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var IUserManager|MockObject */
|
||||
protected $ncUserManager;
|
||||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var IManager|MockObject */
|
||||
protected $notificationManager;
|
||||
/** @var ConnectionFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var ConnectionFactory|MockObject */
|
||||
protected $connectionFactory;
|
||||
/** @var AccessFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var AccessFactory|MockObject */
|
||||
protected $accessFactory;
|
||||
|
||||
protected function setUp(): void {
|
||||
|
|
@ -65,23 +68,25 @@ class SyncTest extends TestCase {
|
|||
$this->connectionFactory = $this->createMock(ConnectionFactory::class);
|
||||
$this->accessFactory = $this->createMock(AccessFactory::class);
|
||||
|
||||
$this->arguments = [
|
||||
'helper' => $this->helper,
|
||||
'ldapWrapper' => $this->ldapWrapper,
|
||||
'mapper' => $this->mapper,
|
||||
'config' => $this->config,
|
||||
'avatarManager' => $this->avatarManager,
|
||||
'dbc' => $this->dbc,
|
||||
'ncUserManager' => $this->ncUserManager,
|
||||
'notificationManager' => $this->notificationManager,
|
||||
'connectionFactory' => $this->connectionFactory,
|
||||
'accessFactory' => $this->accessFactory,
|
||||
];
|
||||
$this->sync = new Sync(
|
||||
Server::get(ITimeFactory::class),
|
||||
Server::get(IEventDispatcher::class),
|
||||
$this->config,
|
||||
$this->dbc,
|
||||
$this->avatarManager,
|
||||
$this->ncUserManager,
|
||||
Server::get(LoggerInterface::class),
|
||||
$this->notificationManager,
|
||||
$this->mapper,
|
||||
$this->helper,
|
||||
$this->connectionFactory,
|
||||
$this->accessFactory,
|
||||
);
|
||||
|
||||
$this->sync = new Sync($this->createMock(ITimeFactory::class));
|
||||
$this->sync->overwritePropertiesForTest($this->ldapWrapper);
|
||||
}
|
||||
|
||||
public function intervalDataProvider() {
|
||||
public function intervalDataProvider(): array {
|
||||
return [
|
||||
[
|
||||
0, 1000, 750
|
||||
|
|
@ -104,7 +109,7 @@ class SyncTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider intervalDataProvider
|
||||
*/
|
||||
public function testUpdateInterval($userCount, $pagingSize1, $pagingSize2) {
|
||||
public function testUpdateInterval(int $userCount, int $pagingSize1, int $pagingSize2): void {
|
||||
$this->config->expects($this->once())
|
||||
->method('setAppValue')
|
||||
->with('user_ldap', 'background_sync_interval', $this->anything())
|
||||
|
|
@ -161,7 +166,7 @@ class SyncTest extends TestCase {
|
|||
return null;
|
||||
});
|
||||
|
||||
/** @var Access|\PHPUnit\Framework\MockObject\MockObject $access */
|
||||
/** @var Access|MockObject $access */
|
||||
$access = $this->createMock(Access::class);
|
||||
$this->accessFactory->expects($this->any())
|
||||
->method('get')
|
||||
|
|
@ -231,7 +236,7 @@ class SyncTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function testQualifiesToRun() {
|
||||
public function testQualifiesToRun(): void {
|
||||
$cycleData = ['prefix' => 's01'];
|
||||
|
||||
$this->config->expects($this->exactly(2))
|
||||
|
|
@ -243,7 +248,7 @@ class SyncTest extends TestCase {
|
|||
$this->assertFalse($this->sync->qualifiesToRun($cycleData));
|
||||
}
|
||||
|
||||
public function runDataProvider() {
|
||||
public function runDataProvider(): array {
|
||||
return [
|
||||
#0 - one LDAP server, reset
|
||||
[[
|
||||
|
|
@ -335,7 +340,7 @@ class SyncTest extends TestCase {
|
|||
return null;
|
||||
});
|
||||
|
||||
/** @var Access|\PHPUnit\Framework\MockObject\MockObject $access */
|
||||
/** @var Access|MockObject $access */
|
||||
$access = $this->createMock(Access::class);
|
||||
$this->accessFactory->expects($this->any())
|
||||
->method('get')
|
||||
|
|
|
|||
|
|
@ -854,6 +854,7 @@ return array(
|
|||
'OCP\\User\\Events\\BeforePasswordUpdatedEvent' => $baseDir . '/lib/public/User/Events/BeforePasswordUpdatedEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserCreatedEvent' => $baseDir . '/lib/public/User/Events/BeforeUserCreatedEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserDeletedEvent' => $baseDir . '/lib/public/User/Events/BeforeUserDeletedEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserIdUnassignedEvent' => $baseDir . '/lib/public/User/Events/BeforeUserIdUnassignedEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserLoggedInEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserLoggedOutEvent' => $baseDir . '/lib/public/User/Events/BeforeUserLoggedOutEvent.php',
|
||||
|
|
@ -868,6 +869,8 @@ return array(
|
|||
'OCP\\User\\Events\\UserCreatedEvent' => $baseDir . '/lib/public/User/Events/UserCreatedEvent.php',
|
||||
'OCP\\User\\Events\\UserDeletedEvent' => $baseDir . '/lib/public/User/Events/UserDeletedEvent.php',
|
||||
'OCP\\User\\Events\\UserFirstTimeLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserFirstTimeLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\UserIdAssignedEvent' => $baseDir . '/lib/public/User/Events/UserIdAssignedEvent.php',
|
||||
'OCP\\User\\Events\\UserIdUnassignedEvent' => $baseDir . '/lib/public/User/Events/UserIdUnassignedEvent.php',
|
||||
'OCP\\User\\Events\\UserLiveStatusEvent' => $baseDir . '/lib/public/User/Events/UserLiveStatusEvent.php',
|
||||
'OCP\\User\\Events\\UserLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php',
|
||||
|
|
|
|||
|
|
@ -887,6 +887,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\User\\Events\\BeforePasswordUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforePasswordUpdatedEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserCreatedEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserDeletedEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserIdUnassignedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserIdUnassignedEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserLoggedInWithCookieEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedInWithCookieEvent.php',
|
||||
'OCP\\User\\Events\\BeforeUserLoggedOutEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/BeforeUserLoggedOutEvent.php',
|
||||
|
|
@ -901,6 +902,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\User\\Events\\UserCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserCreatedEvent.php',
|
||||
'OCP\\User\\Events\\UserDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserDeletedEvent.php',
|
||||
'OCP\\User\\Events\\UserFirstTimeLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserFirstTimeLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\UserIdAssignedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserIdAssignedEvent.php',
|
||||
'OCP\\User\\Events\\UserIdUnassignedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserIdUnassignedEvent.php',
|
||||
'OCP\\User\\Events\\UserLiveStatusEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLiveStatusEvent.php',
|
||||
'OCP\\User\\Events\\UserLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedInEvent.php',
|
||||
'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php',
|
||||
|
|
|
|||
33
lib/public/User/Events/BeforeUserIdUnassignedEvent.php
Normal file
33
lib/public/User/Events/BeforeUserIdUnassignedEvent.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\User\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
class BeforeUserIdUnassignedEvent extends Event {
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private string $userId,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function getUserId(): string {
|
||||
return $this->userId;
|
||||
}
|
||||
}
|
||||
33
lib/public/User/Events/UserIdAssignedEvent.php
Normal file
33
lib/public/User/Events/UserIdAssignedEvent.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\User\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
class UserIdAssignedEvent extends Event {
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private string $userId,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function getUserId(): string {
|
||||
return $this->userId;
|
||||
}
|
||||
}
|
||||
33
lib/public/User/Events/UserIdUnassignedEvent.php
Normal file
33
lib/public/User/Events/UserIdUnassignedEvent.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCP\User\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
class UserIdUnassignedEvent extends Event {
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private string $userId,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function getUserId(): string {
|
||||
return $this->userId;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue