From 0c8dad95021dd218f270a620a7f1c6b4003aebf9 Mon Sep 17 00:00:00 2001 From: indifferentketchup Date: Fri, 1 May 2026 14:38:26 +0000 Subject: [PATCH] feat: add Steam ID redaction pass Co-Authored-By: Claude Sonnet 4.6 --- .../ProjectZomboid/ProjectZomboidRedactor.php | 8 ++- .../ProjectZomboidRedactorSteamIdTest.php | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/tests/Util/Redactor/ProjectZomboidRedactorSteamIdTest.php diff --git a/src/Util/ProjectZomboid/ProjectZomboidRedactor.php b/src/Util/ProjectZomboid/ProjectZomboidRedactor.php index a4e96f6..b0dd91c 100644 --- a/src/Util/ProjectZomboid/ProjectZomboidRedactor.php +++ b/src/Util/ProjectZomboid/ProjectZomboidRedactor.php @@ -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 = '/(?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 diff --git a/test/tests/Util/Redactor/ProjectZomboidRedactorSteamIdTest.php b/test/tests/Util/Redactor/ProjectZomboidRedactorSteamIdTest.php new file mode 100644 index 0000000..4c1c8c2 --- /dev/null +++ b/test/tests/Util/Redactor/ProjectZomboidRedactorSteamIdTest.php @@ -0,0 +1,52 @@ +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.'); + } +}