mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-05-30 17:09:27 -07:00
See https://github.com/EFForg/rayhunter/issues/334 Severity levels low, medium, high are now exposed to the UI in form of dotted, dashed and solid lines. The line on the UI represents the highest-so-far severity seen. Originally this was intended to be represented by Yellow/Orange/Red, but this would mean yet another divergence for colorblind mode. This is colorblind-friendly by default (I think...) As part of this, simplify EventType so that it becomes a flat "level" enum without nested variants. There is also a new debug endpoint that allows one to overwrite the display level directly for testing.
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { AnalysisRowType, parse_finished_report } from './analysis.svelte';
|
|
import { type NewlineDeliminatedJson } from './ndjson';
|
|
|
|
const SAMPLE_V2_REPORT_NDJSON: NewlineDeliminatedJson = [
|
|
{
|
|
analyzers: [
|
|
{
|
|
name: 'Analyzer 1',
|
|
description: 'A first analyzer',
|
|
version: 2,
|
|
},
|
|
{
|
|
name: 'Analyzer 2',
|
|
description: 'A second analyzer',
|
|
version: 2,
|
|
},
|
|
],
|
|
report_version: 2,
|
|
},
|
|
{
|
|
skipped_message_reason: 'The reason why the message was skipped',
|
|
},
|
|
{
|
|
packet_timestamp: '2024-08-19T03:33:54.318Z',
|
|
events: [
|
|
null,
|
|
{
|
|
event_type: 'Low',
|
|
message: 'Something nasty happened',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
describe('analysis report parsing', () => {
|
|
it('parses v2 example analysis', () => {
|
|
const report = parse_finished_report(SAMPLE_V2_REPORT_NDJSON);
|
|
expect(report.metadata.report_version).toEqual(2);
|
|
expect(report.metadata.analyzers).toEqual([
|
|
{
|
|
name: 'Analyzer 1',
|
|
description: 'A first analyzer',
|
|
version: 2,
|
|
},
|
|
{
|
|
name: 'Analyzer 2',
|
|
description: 'A second analyzer',
|
|
version: 2,
|
|
},
|
|
]);
|
|
expect(report.rows).toHaveLength(2);
|
|
expect(report.rows[0].type).toBe(AnalysisRowType.Skipped);
|
|
if (report.rows[1].type === AnalysisRowType.Analysis) {
|
|
const row = report.rows[1];
|
|
expect(row.events).toHaveLength(2);
|
|
expect(row.events[0]).toBeNull();
|
|
const event = row.events[1];
|
|
const expected_timestamp = new Date('2024-08-19T03:33:54.318Z');
|
|
expect(row.packet_timestamp.getTime()).toEqual(expected_timestamp.getTime());
|
|
expect(event!.event_type).toEqual('Low');
|
|
} else {
|
|
throw 'wrong row type';
|
|
}
|
|
});
|
|
});
|