mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-12-02 11:43:26 +01:00
42 lines
2.0 KiB
JavaScript
42 lines
2.0 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const vm = require('node:vm');
|
|
const test = require('node:test');
|
|
|
|
test('export uses the server-paginated records even when target_host is absent', async () => {
|
|
const downloads = [];
|
|
const context = vm.createContext({
|
|
vulnerabilityBrowserRows: [{ id: 'server-selected', summary_only: true }],
|
|
apiFetch: async url => {
|
|
assert.equal(url, '/api/vulnerabilities/server-selected');
|
|
return { ok: true, json: async () => ({ id: 'server-selected' }) };
|
|
},
|
|
vulnerabilityBrowserSelection: '',
|
|
vulnerabilityView: 'host',
|
|
formatVulnerabilityAsMarkdown: item => item.id,
|
|
triggerTextDownload: (name, content) => downloads.push(content),
|
|
});
|
|
const source = fs.readFileSync('web/static/js/vulnerability.js', 'utf8');
|
|
vm.runInContext(source.slice(
|
|
source.indexOf('function getVisibleVulnerabilityBrowserItems()'),
|
|
source.indexOf('function renderVulnerabilityBrowserTable(')
|
|
), context);
|
|
|
|
context.vulnerabilityBrowserSelection = 'domain:example.com';
|
|
await context.exportVisibleVulnerabilityBrowser();
|
|
assert.deepEqual(downloads, ['server-selected']);
|
|
});
|
|
|
|
test('selecting or clearing a group reloads the first record page and keeps navigation scroll', () => {
|
|
const calls = [];
|
|
const context = vm.createContext({ vulnerabilityBrowserSelection: '', loadVulnerabilities: (...args) => calls.push(args) });
|
|
const source = fs.readFileSync('web/static/js/vulnerability.js', 'utf8');
|
|
vm.runInContext(source.slice(source.indexOf('function selectVulnerabilityBrowserGroup('), source.indexOf('function getVisibleVulnerabilityBrowserItems(')), context);
|
|
for (const key of ['host:example.com', 'task:task-a', '']) {
|
|
context.selectVulnerabilityBrowserGroup(key);
|
|
assert.equal(context.vulnerabilityBrowserSelection, key);
|
|
assert.equal(calls.at(-1)[0], 1);
|
|
assert.equal(calls.at(-1)[1].preserveScroll, true);
|
|
}
|
|
});
|