feat: add Steam ID redaction pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 14:38:26 +00:00
parent 7755d8385c
commit 0c8dad9502
2 changed files with 59 additions and 1 deletions

View File

@@ -24,6 +24,12 @@ use IndifferentKetchup\Codex\Util\RedactorInterface;
*/
class ProjectZomboidRedactor implements RedactorInterface
{
/** Regex matching a 17-digit SteamID64 anchored on the 76561198 universe prefix, with lookaround boundaries that reject embedded occurrences. */
public const string STEAM_ID_REGEX = '/(?<![A-Za-z0-9])76561198\d{9}(?![A-Za-z0-9])/u';
/** Zeroed-out SteamID64 placeholder; syntactically valid but refers to no real account. */
public const string STEAM_ID_REPLACEMENT = '76561198000000000';
private bool $redactSteamIds = true;
private bool $redactPlayerNames = true;
private bool $redactCoordinates = true;
@@ -76,7 +82,7 @@ class ProjectZomboidRedactor implements RedactorInterface
public function redact(string $content): string
{
if ($this->redactSteamIds) {
// Steam ID pass added in Task 2
$content = preg_replace(self::STEAM_ID_REGEX, self::STEAM_ID_REPLACEMENT, $content);
}
if ($this->redactPlayerNames) {
// Player name pass added in Task 3

View File

@@ -0,0 +1,52 @@
<?php
namespace IndifferentKetchup\Codex\Test\Tests\Util\Redactor;
use IndifferentKetchup\Codex\Util\ProjectZomboid\ProjectZomboidRedactor;
use PHPUnit\Framework\TestCase;
class ProjectZomboidRedactorSteamIdTest extends TestCase
{
public function testCollapsesDistinctSteamIdsToZeroPlaceholder(): void
{
$input = 'Players: 76561198111111111, 76561198222222222, 76561198333333333 connected.';
$expected = 'Players: 76561198000000000, 76561198000000000, 76561198000000000 connected.';
$output = (new ProjectZomboidRedactor())->redact($input);
$this->assertSame($expected, $output, 'All three distinct Steam IDs should be replaced with the zero placeholder.');
}
public function testNonSteamIdLongDigitsAreNotTouched(): void
{
// 13-digit Unix-millisecond timestamp (PZ log t: shape) and a 17-digit number
// that does not begin with 76561198 — neither should be altered.
$input = 't:1776297642406 score=12345678901234567';
$output = (new ProjectZomboidRedactor())->redact($input);
$this->assertSame($input, $output, 'Non-SteamID digit sequences must not be modified.');
}
public function testEmbeddedSteamIdInsideLongerAlphanumericTokenIsNotTouched(): void
{
// The SteamID64 pattern is embedded inside a longer alphanumeric token;
// the negative lookaround boundaries should prevent a match.
$input = 'token=abc76561198000000001def other=data';
$output = (new ProjectZomboidRedactor())->redact($input);
$this->assertSame($input, $output, 'A Steam ID embedded inside an alphanumeric token must not be redacted.');
}
public function testToggleOffLeavesSteamIdsIntact(): void
{
$input = 'Connected: 76561198111111111 and 76561198222222222.';
$output = (new ProjectZomboidRedactor())
->redactSteamIds(false)
->redact($input);
$this->assertSame($input, $output, 'With the Steam ID toggle disabled the original input must be returned unchanged.');
}
}