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/AdminAbuseMonitoringBehavio...

52 lines
1.6 KiB
JavaScript

import fs from 'node:fs';
globalThis.document = {
querySelector: () => null,
getElementById: () => null,
querySelectorAll: () => [],
};
globalThis.window = {};
const source = fs.readFileSync(new URL(
'../public/cloud/admin-abuse-monitoring.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);
};
assert(module.directionLabel('outbound').startsWith('对外可疑行为'),
'Outbound behavior lost its canonical label.');
assert(module.directionLabel('inbound').startsWith('正在遭受攻击'),
'Inbound victim traffic lost its canonical label.');
assert(module.directionLabel('both').startsWith('双向异常'),
'Bidirectional evidence was collapsed into a one-sided label.');
const normalized = module.normalize({
item: {
instance_id: '1',
direction: 'future_value',
metrics: {},
sample: {},
},
series: [],
findings: [{severity: 'future_value'}, {severity: 'info'}],
});
assert(normalized.direction === 'none'
&& normalized.findings[0].severity === 'info'
&& normalized.findings[1].severity === 'info',
'Unknown server enums must not become dynamic CSS classes.');
const scales = module.trendScales([
{tx_bps: 10_000_000, tx_pps: 10},
{tx_bps: 100, tx_pps: 2_000},
]);
assert(scales.maxBps === 10_000_000 && scales.maxPps === 2_000,
'Throughput and packet-rate trends must use independent scales.');
console.log('Administrator abuse-monitoring JavaScript behavior passed.');