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.
91 lines
3.3 KiB
JavaScript
91 lines
3.3 KiB
JavaScript
import fs from 'node:fs';
|
|
|
|
globalThis.document = {
|
|
querySelector: () => null,
|
|
getElementById: () => null,
|
|
};
|
|
globalThis.window = {};
|
|
|
|
const source = fs.readFileSync(new URL(
|
|
'../public/cloud/admin-abuse-alert-history.js',
|
|
import.meta.url,
|
|
), 'utf8');
|
|
const module = await import(
|
|
`data:text/javascript;base64,${Buffer.from(source).toString('base64')}`
|
|
);
|
|
|
|
const assert = (condition, message) => {
|
|
if (!condition) throw new Error(message);
|
|
};
|
|
|
|
const payload = module.normalizeAlertHistoryPayload({
|
|
summary: {unknown: 1, total: 1},
|
|
pagination: {page: 1, total_pages: 1, total: 1},
|
|
items: [{
|
|
event_id: '7', instance_id: '41', user_id: '10', host_id: '3',
|
|
instance_name: 'vm-a', user_name: 'owner', host_name: 'host-a',
|
|
created_at: '2026-11-09T01:02:03Z', transition_count: 1,
|
|
highest_severity: {value: 'high'},
|
|
event_key: 'secret-event-key', policy_hash: 'secret-policy-hash',
|
|
sample_key: 'secret-sample-key',
|
|
delivery: {
|
|
status: 'unknown',
|
|
detail: '远端效果未知;系统禁止自动重放,请人工核对 Telegram。',
|
|
automatic_replay_allowed: true,
|
|
chat_id: '99887766', binding_generation: 'secret-binding',
|
|
token: 'secret-token', message_text: 'secret-message',
|
|
content_hash: 'secret-content-hash',
|
|
},
|
|
items: [{
|
|
rule_code: 'outbound_tcp_syn_sweep', direction: 'outbound',
|
|
ip_family: 'ipv4', transition: 'opened',
|
|
from_severity: 'none', to_severity: 'high',
|
|
occurred_at: '2026-11-09T01:02:00Z',
|
|
finding_key: 'secret-finding-key', item_key: 'secret-item-key',
|
|
evidence_json: '{"remote_ip":"203.0.113.7"}',
|
|
evidence: [
|
|
{key: 'tcp_syn_flows', label: 'untrusted', value: 900},
|
|
{key: 'remote_ip', label: 'raw address', value: 1},
|
|
{key: 'nested', value: {token: 'secret'}},
|
|
],
|
|
}],
|
|
}],
|
|
});
|
|
|
|
const encoded = JSON.stringify(payload);
|
|
assert(payload.items[0].delivery.status === 'unknown'
|
|
&& payload.items[0].delivery.automatic_replay_allowed === false
|
|
&& payload.items[0].items[0].evidence.length === 1
|
|
&& payload.items[0].items[0].evidence[0].label === 'TCP SYN Flow',
|
|
'Unknown/no-replay state or aggregate evidence normalization drifted.');
|
|
for (const secret of [
|
|
'99887766', 'secret-binding', 'secret-token', 'secret-message',
|
|
'secret-content-hash', 'secret-event-key', 'secret-policy-hash',
|
|
'secret-sample-key', 'secret-finding-key', 'secret-item-key',
|
|
'203.0.113.7', 'evidence_json',
|
|
]) {
|
|
assert(!encoded.includes(secret), `Normalized history leaked ${secret}.`);
|
|
}
|
|
|
|
const url = module.buildAlertHistoryUrl('/alerts', {
|
|
status: 'unknown', transition: 'opened', direction: 'outbound',
|
|
ip_family: 'ipv4', event_id: '7', instance_id: '41',
|
|
user_id: '10', host_id: '3', query: '',
|
|
}, 2);
|
|
assert(url.includes('status=unknown')
|
|
&& url.includes('event_id=7')
|
|
&& url.includes('instance_id=41')
|
|
&& url.includes('user_id=10')
|
|
&& url.includes('host_id=3')
|
|
&& url.includes('page=2'),
|
|
'Alert history URL lost independent identity filters or pagination.');
|
|
|
|
const invalid = module.normalizeDelivery({
|
|
status: 'future_state', automatic_replay_allowed: true,
|
|
});
|
|
assert(invalid.status === 'unknown'
|
|
&& invalid.automatic_replay_allowed === false,
|
|
'Unknown server enums gained a replay-capable dynamic UI state.');
|
|
|
|
console.log('Administrator abuse-alert history JavaScript behavior passed.');
|