mirror of
https://github.com/nextcloud/server.git
synced 2026-11-04 22:17:32 +01:00
Audit entries now carry the parameters they are built from as a nested "params" object in their data (e.g. data.params.shareWith), so log consumers no longer need to parse the human-readable message. Numbers and booleans keep their type. Parameters are left out when the call asks for obfuscation. The audit logger requests a custom logger with structured context, so only audit.log is affected. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ghassen kefi <ghassen.kefi.dev@gmail.com>
40 lines
1.3 KiB
PHP
40 lines
1.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\AdminAudit\Tests;
|
|
|
|
use OCA\AdminAudit\AuditLogger;
|
|
use OCP\AppFramework\Services\IAppConfig;
|
|
use OCP\IConfig;
|
|
use OCP\Log\ILogFactory;
|
|
use Psr\Log\LoggerInterface;
|
|
use Test\TestCase;
|
|
|
|
class AuditLoggerTest extends TestCase {
|
|
public function testUsesStructuredContextLogger(): void {
|
|
$config = $this->createMock(IConfig::class);
|
|
$config->method('getSystemValueString')
|
|
->willReturnCallback(static fn (string $key, string $default): string => $key === 'logfile_audit' ? '/var/log/nextcloud-audit.log' : $default);
|
|
|
|
$parentLogger = $this->createMock(LoggerInterface::class);
|
|
$logFactory = $this->createMock(ILogFactory::class);
|
|
$logFactory->expects($this->once())
|
|
->method('getCustomPsrLogger')
|
|
->with('/var/log/nextcloud-audit.log', 'file', 'Nextcloud', true)
|
|
->willReturn($parentLogger);
|
|
|
|
$parentLogger->expects($this->once())
|
|
->method('info')
|
|
->with('File deleted', ['app' => 'admin_audit', 'params' => ['path' => '/a.txt']]);
|
|
|
|
$auditLogger = new AuditLogger($logFactory, $this->createMock(IAppConfig::class), $config);
|
|
$auditLogger->info('File deleted', ['app' => 'admin_audit', 'params' => ['path' => '/a.txt']]);
|
|
}
|
|
}
|