Files
nextcloud-server-mirror/apps/user_ldap/tests/Controller/WizardControllerTest.php
Ghassen kefi 41faa5bda5 feat(user_ldap): log LDAP configuration changes
Creating, updating, copying and deleting LDAP configurations through
the API, revealing the bind password and clearing user or group
mappings are now audited. For updates only the names of the changed
keys are logged, never their values.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ghassen kefi <ghassen.kefi.dev@gmail.com>
2026-11-05 16:35:13 +01:00

80 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\User_LDAP\Tests\Controller;
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Controller\WizardController;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\WizardFactory;
use OCP\AppFramework\OCS\OCSException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\IRequest;
use OCP\Log\Audit\CriticalActionPerformedEvent;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class WizardControllerTest extends TestCase {
private GroupMapping&MockObject $groupMapping;
private IEventDispatcher&MockObject $eventDispatcher;
private WizardController $controller;
protected function setUp(): void {
parent::setUp();
$this->groupMapping = $this->createMock(GroupMapping::class);
$this->overwriteService(GroupMapping::class, $this->groupMapping);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->controller = new WizardController(
'user_ldap',
$this->createMock(IRequest::class),
$this->createMock(LoggerInterface::class),
$this->createMock(ConnectionFactory::class),
$this->createMock(IL10N::class),
$this->createMock(WizardFactory::class),
$this->eventDispatcher,
);
}
protected function tearDown(): void {
$this->restoreService(GroupMapping::class);
parent::tearDown();
}
public function testClearGroupMappings(): void {
$this->groupMapping->expects($this->once())
->method('clear')
->willReturn(true);
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with($this->callback(fn (CriticalActionPerformedEvent $event): bool
=> $event->getOperation() === 'user_ldap.mapping.cleared'
&& $event->getLogMessage() === 'LDAP %s mappings were cleared'
&& $event->getParameters() === ['subject' => 'group']));
$this->controller->clearMappings('group');
}
public function testClearGroupMappingsFailed(): void {
$this->groupMapping->expects($this->once())
->method('clear')
->willReturn(false);
$this->eventDispatcher->expects($this->never())
->method('dispatchTyped');
$this->expectException(OCSException::class);
$this->controller->clearMappings('group');
}
}