You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudAdminAbuseAlertHistory...

89 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
$root = dirname(__DIR__);
$read = static function (string $path): string {
$source = file_get_contents($path);
if (!is_string($source)) {
throw new RuntimeException('Unable to read ' . $path);
}
return $source;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$template = $read($root
. '/resources/views/venix/admin/cloud/abuse_monitoring.tpl');
$script = $read($root . '/public/cloud/admin-abuse-alert-history.js');
$styles = $read($root . '/public/cloud/admin-abuse-monitoring.css');
$service = $read($root
. '/app/Services/Cloud/CloudAdminAbuseAlertHistoryService.php');
$assert(str_contains($template, 'data-admin-abuse-alert-history')
&& str_contains($template,
'data-alert-api="/api/v1/admin/abuse-monitoring/alerts"')
&& str_contains($template, 'admin-abuse-alert-history.js')
&& str_contains($template, '实例监控与策略配置不受影响'),
'Alert history must be an independently loaded monitoring card.');
foreach ([
'name="status"', 'name="transition"', 'name="severity"',
'name="direction"', 'name="ip_family"', 'name="event_id"',
'name="instance_id"', 'name="user_id"', 'name="host_id"',
] as $filter) {
$assert(str_contains($template, $filter),
'Alert history is missing filter ' . $filter . '.');
}
$assert(str_contains($script,
'window.VenixAdminRequestRuntime?.create?.()')
&& str_contains($script, 'historyRuntime.read(url')
&& str_contains($script, 'timeoutMs: 10000')
&& !preg_match('/historyRuntime\.(?:mutate|commit|enqueue)\s*\(/',
$script)
&& !str_contains($script, '.innerHTML'),
'Alert history must remain a safe, read-only asynchronous module.');
foreach ([
'chat_id', 'binding_generation', 'telegram_message_id',
'message_text', 'content_hash', 'policy_hash', 'sample_key',
'finding_key', 'item_key', 'evidence_json',
] as $privateField) {
$assert(!str_contains($script, $privateField),
'Browser module references private field ' . $privateField . '.');
}
$assert(str_contains($template, '效果未知的发送不会自动重放')
&& str_contains($script,
'远端效果未知;系统禁止自动重放,请人工核对 Telegram。')
&& str_contains($script,
'页面不提供重试或重新发送入口。')
&& preg_match('/<button[^>]*>[^<]*(?:重试|重新发送)/u',
$template) !== 1,
'Unknown delivery must be explicit and must expose no replay action.');
$assert(str_contains($styles,
'[data-admin-abuse-alert-history] .admin-abuse-alert-event')
&& str_contains($styles,
'[data-admin-abuse-alert-history] .admin-abuse-alert-identities')
&& str_contains($styles, '@media (max-width: 767.98px)')
&& str_contains($styles,
'grid-template-columns: repeat(2, minmax(0, 1fr))'),
'Alert history lacks its desktop or mobile card presentation.');
$assert(str_contains($service,
"COALESCE(delivery.state, 'queued')")
&& str_contains($service, "'channel_disabled_or_unavailable'")
&& str_contains($service, "'automatic_replay_allowed' => false")
&& !str_contains($service, "'chat_id'")
&& !str_contains($service, "'message_text'")
&& !str_contains($service, "'content_hash'")
&& !str_contains($service, "'policy_hash'")
&& !str_contains($service, "'evidence_json' =>"),
'Server projection must derive queued and omit sensitive ledger fields.');
echo "Administrator abuse-alert history UI contracts passed.\n";