43 lines
1.5 KiB
PHP
43 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Service\Audit;
|
|
|
|
use MintyPHP\Service\Audit\SystemAuditRedactionService;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SystemAuditRedactionServiceTest extends TestCase
|
|
{
|
|
public function testSensitiveKeysAreRedacted(): void
|
|
{
|
|
$service = new SystemAuditRedactionService();
|
|
|
|
$redacted = $service->redactMetadata([
|
|
'email' => 'john@example.com',
|
|
'token' => 'abc',
|
|
'active' => 1,
|
|
'nested' => ['password' => 'secret'],
|
|
]);
|
|
|
|
$this->assertSame('[REDACTED]', $redacted['email']);
|
|
$this->assertSame('[REDACTED]', $redacted['token']);
|
|
$this->assertSame(1, $redacted['active']);
|
|
$this->assertSame('[REDACTED]', $redacted['nested']['password']);
|
|
}
|
|
|
|
public function testBuildChangeSetUsesAllowlistAndRedactsOtherValues(): void
|
|
{
|
|
$service = new SystemAuditRedactionService();
|
|
|
|
$changeSet = $service->buildChangeSet(
|
|
['active' => 0, 'description' => 'old'],
|
|
['active' => 1, 'description' => 'new']
|
|
);
|
|
|
|
$this->assertSame(['active', 'description'], $changeSet['changed_fields']);
|
|
$this->assertSame(0, $changeSet['changes']['active']['before']);
|
|
$this->assertSame(1, $changeSet['changes']['active']['after']);
|
|
$this->assertSame('[REDACTED]', $changeSet['changes']['description']['before']);
|
|
$this->assertSame('[REDACTED]', $changeSet['changes']['description']['after']);
|
|
}
|
|
}
|