44 lines
1.9 KiB
JavaScript
44 lines
1.9 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const vm = require('node:vm');
|
|
const test = require('node:test');
|
|
|
|
test('domain export includes exactly the visible records from the loaded page', () => {
|
|
const rows = [
|
|
{ id: 'a', target_host: 'api.example.com', target_domain: 'example.com', task_id:'task-a', task_queue_id:'queue' },
|
|
{ id: 'b', target_host: 'www.example.com', target_domain: 'example.com', task_id:'task-b', task_queue_id:'queue' },
|
|
{ id: 'c', target_host: 'example.net', target_domain: 'example.net' },
|
|
{ id: 'unknown', target_host: '' },
|
|
{ id: 'assessment', assessment_id: 'task-a', assessment_name: 'Assessment', target_host: 'assessment.example.test' },
|
|
];
|
|
const downloads = [];
|
|
const context = vm.createContext({
|
|
vulnerabilityBrowserRows: rows,
|
|
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 renderVulnerabilityHostRiskDot(')
|
|
), context);
|
|
|
|
for (const [selection, expected] of [
|
|
['', ['a', 'b', 'c', 'unknown', 'assessment']],
|
|
['host:api.example.com', ['a']],
|
|
['domain:example.com', ['a', 'b']],
|
|
['host:', ['unknown']],
|
|
['host:missing.example.com', []],
|
|
['task:task-a',['a']],
|
|
['assessment:task-a',['assessment']],
|
|
['queue:queue',['a','b']],
|
|
]) {
|
|
context.vulnerabilityBrowserSelection = selection;
|
|
downloads.length = 0;
|
|
context.exportVisibleVulnerabilityBrowser();
|
|
assert.deepEqual(downloads, expected.length ? [expected.join('\n\n---\n\n')] : []);
|
|
}
|
|
});
|