Files
api/services/nginx/app/tests/Unit/Bird/BirdConfigSecretRedactionTest.php
T
Jeppe B a442e70744 Add secure Bird gateway for Pleno Control Plane (#332)
Add the Bird Control Plane gateway, signed webhook ingestion, policy-gated writes, fail-closed production auto-activation, and RSA-OAEP bootstrap credential flow.
2026-07-29 19:59:20 +02:00

91 lines
2.2 KiB
PHP

<?php
app_require('traits/module_config_t.php');
use traits\module_config_t;
if (!class_exists('BirdSecretConfigDefinitionStub')) {
class BirdSecretConfigDefinitionStub
{
public bool $config_variable_is_secret = true;
public function getVariableName(): string
{
return 'api_key';
}
}
}
if (!class_exists('BirdPublicConfigDefinitionStub')) {
class BirdPublicConfigDefinitionStub
{
public bool $config_variable_is_secret = false;
public function getVariableName(): string
{
return 'workspaceId';
}
}
}
if (!class_exists('BirdModuleConfigRedactionHarness')) {
class BirdModuleConfigRedactionHarness
{
use module_config_t;
public function __construct()
{
$this->config_classes = [
BirdSecretConfigDefinitionStub::class,
BirdPublicConfigDefinitionStub::class,
];
}
public function extract(object $db): array
{
return $this->extracted($db, 'SELECT test');
}
}
}
it('redacts configured Bird secrets while preserving isSet metadata', function (): void {
$rows = [
['module' => 'bird', 'variable' => 'api_key', 'type' => 'string', 'value' => 'never-return-this'],
['module' => 'bird', 'variable' => 'workspaceId', 'type' => 'string', 'value' => 'workspace-1'],
];
$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 BirdModuleConfigRedactionHarness())->extract($db);
expect($config[0])->toMatchArray([
'variable' => 'api_key',
'value' => '[redacted]',
'isSecret' => true,
'isSet' => true,
])->and($config[1])->toMatchArray([
'variable' => 'workspaceId',
'value' => 'workspace-1',
'isSecret' => false,
'isSet' => true,
]);
});