diff --git a/services/nginx/app/tests/Unit/MiniMax/MiniMaxConfigSecretRedactionTest.php b/services/nginx/app/tests/Unit/MiniMax/MiniMaxConfigSecretRedactionTest.php new file mode 100644 index 00000000..8c78a6d1 --- /dev/null +++ b/services/nginx/app/tests/Unit/MiniMax/MiniMaxConfigSecretRedactionTest.php @@ -0,0 +1,131 @@ +config_classes = [ + MiniMaxSecretConfigDefinitionStub::class, + MiniMaxBoolConfigDefinitionStub::class, + ]; + } + + public function extract(object $db): array + { + return $this->extracted($db, 'SELECT test'); + } + } +} + +it('redacts configured MiniMax secrets while preserving isSet metadata', function (): void { + $rows = [ + ['module' => 'miniMax', 'variable' => 'api_key', 'type' => 'string', 'value' => 'never-return-this'], + ['module' => 'miniMax', 'variable' => 'enabled', 'type' => 'bool', 'value' => 'true'], + ]; + $result = new class($rows) { + public function __construct(private array $rows) + { + } + + public function fetch_assoc(): ?array + { + return array_shift($this->rows); + } + }; + $db = new class($result) { + public function __construct(private object $result) + { + } + + public function query(string $sql): object + { + return $this->result; + } + }; + + $config = (new MiniMaxModuleConfigRedactionHarness())->extract($db); + + expect($config[0])->toMatchArray([ + 'module' => 'miniMax', + 'variable' => 'api_key', + 'type' => 'string', + 'value' => '[redacted]', + 'isSecret' => true, + 'isSet' => true, + ])->and($config[1])->toMatchArray([ + 'module' => 'miniMax', + 'variable' => 'enabled', + 'type' => 'bool', + 'value' => true, + 'isSecret' => false, + 'isSet' => true, + ]); +}); + +it('reports isSet=false when the stored MiniMax api_key is empty', function (): void { + $rows = [ + ['module' => 'miniMax', 'variable' => 'api_key', 'type' => 'string', 'value' => ''], + ]; + $result = new class($rows) { + public function __construct(private array $rows) + { + } + + public function fetch_assoc(): ?array + { + return array_shift($this->rows); + } + }; + $db = new class($result) { + public function __construct(private object $result) + { + } + + public function query(string $sql): object + { + return $this->result; + } + }; + + $config = (new MiniMaxModuleConfigRedactionHarness())->extract($db); + + expect($config[0])->toMatchArray([ + 'module' => 'miniMax', + 'variable' => 'api_key', + 'type' => 'string', + 'value' => '', + 'isSecret' => true, + 'isSet' => false, + ]); +});