Files
nextcloud-server-mirror/apps/settings/tests/Controller/AISettingsControllerTest.php
Ghassen kefi 81ce503a20 feat(settings): log credential, security and server settings changes
Audit entries are added for app password creation, deletion and scope
changes, remote wipe requests, WebAuthn devices, two-factor
enforcement, mail server settings and credentials, admin delegation,
presets, declarative settings and log file downloads.

The existing AI settings entry keeps its message and now carries an
operation (settings.ai.updated) and named parameters.

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

55 lines
1.7 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\Settings\Tests\Controller;
use OCA\Settings\Controller\AISettingsController;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IRequest;
use OCP\Log\Audit\CriticalActionPerformedEvent;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AISettingsControllerTest extends TestCase {
private IAppConfig&MockObject $appConfig;
private IEventDispatcher&MockObject $eventDispatcher;
private AISettingsController $controller;
protected function setUp(): void {
parent::setUp();
$this->appConfig = $this->createMock(IAppConfig::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->controller = new AISettingsController(
'settings',
$this->createMock(IRequest::class),
'admin',
$this->appConfig,
$this->eventDispatcher,
);
}
public function testUpdateAuditsChangedKeys(): void {
$this->appConfig->method('setValueString')
->willReturnCallback(fn (string $app, string $key): bool => $key === 'ai.stt_provider');
$this->eventDispatcher->expects($this->once())
->method('dispatchTyped')
->with($this->callback(fn (CriticalActionPerformedEvent $event): bool => $event->getOperation() === 'settings.ai.updated'
&& $event->getParameters() === ['userId' => 'admin', 'configKey' => 'ai.stt_provider', 'configValue' => '"provider"']
&& $event->getLogMessage() === 'AI configuration was changed by user %s: %s was set to %s'));
$this->controller->update([
'ai.stt_provider' => 'provider',
'ai.text2image_provider' => 'unchanged',
]);
}
}