web: lint fixes

This commit is contained in:
Will Greenberg
2025-07-15 15:03:56 -07:00
committed by Cooper Quintin
parent 1a4deb7524
commit 09d4328dc2
2 changed files with 38 additions and 42 deletions
+17 -19
View File
@@ -6,20 +6,18 @@ const SAMPLE_V1_REPORT_NDJSON: NewlineDeliminatedJson = [
{ {
analyzers: [ analyzers: [
{ {
name: "Analyzer 1", name: 'Analyzer 1',
description: "A first analyzer", description: 'A first analyzer',
}, },
{ {
name: "Analyzer 2", name: 'Analyzer 2',
description: "A second analyzer", description: 'A second analyzer',
}, },
], ],
}, },
{ {
timestamp: '2024-10-08T13:25:43.011689003-07:00', timestamp: '2024-10-08T13:25:43.011689003-07:00',
skipped_message_reasons: [ skipped_message_reasons: ['The reason why the message was skipped'],
'The reason why the message was skipped',
],
analysis: [], analysis: [],
}, },
{ {
@@ -44,13 +42,13 @@ const SAMPLE_V2_REPORT_NDJSON: NewlineDeliminatedJson = [
{ {
analyzers: [ analyzers: [
{ {
name: "Analyzer 1", name: 'Analyzer 1',
description: "A first analyzer", description: 'A first analyzer',
version: 2, version: 2,
}, },
{ {
name: "Analyzer 2", name: 'Analyzer 2',
description: "A second analyzer", description: 'A second analyzer',
version: 2, version: 2,
}, },
], ],
@@ -78,12 +76,12 @@ describe('analysis report parsing', () => {
expect(report.metadata.analyzers).toEqual([ expect(report.metadata.analyzers).toEqual([
{ {
name: 'Analyzer 1', name: 'Analyzer 1',
description: "A first analyzer", description: 'A first analyzer',
version: 1, version: 1,
}, },
{ {
name: 'Analyzer 2', name: 'Analyzer 2',
description: "A second analyzer", description: 'A second analyzer',
version: 1, version: 1,
}, },
]); ]);
@@ -95,14 +93,14 @@ describe('analysis report parsing', () => {
expect(row.events[0]).toBeNull(); expect(row.events[0]).toBeNull();
const event = row.events[1]; const event = row.events[1];
const expected_timestamp = new Date('2024-08-19T03:33:54.318Z'); const expected_timestamp = new Date('2024-08-19T03:33:54.318Z');
expect(row.packet_timestamp.getTime()).toEqual(expected_timestamp.getTime()) expect(row.packet_timestamp.getTime()).toEqual(expected_timestamp.getTime());
if (event !== null && event.type === EventType.Warning) { if (event !== null && event.type === EventType.Warning) {
expect(event.severity).toEqual(Severity.Low); expect(event.severity).toEqual(Severity.Low);
} else { } else {
throw 'wrong event type'; throw 'wrong event type';
} }
} else { } else {
throw 'wrong row type' throw 'wrong row type';
} }
}); });
@@ -112,12 +110,12 @@ describe('analysis report parsing', () => {
expect(report.metadata.analyzers).toEqual([ expect(report.metadata.analyzers).toEqual([
{ {
name: 'Analyzer 1', name: 'Analyzer 1',
description: "A first analyzer", description: 'A first analyzer',
version: 2, version: 2,
}, },
{ {
name: 'Analyzer 2', name: 'Analyzer 2',
description: "A second analyzer", description: 'A second analyzer',
version: 2, version: 2,
}, },
]); ]);
@@ -129,14 +127,14 @@ describe('analysis report parsing', () => {
expect(row.events[0]).toBeNull(); expect(row.events[0]).toBeNull();
const event = row.events[1]; const event = row.events[1];
const expected_timestamp = new Date('2024-08-19T03:33:54.318Z'); const expected_timestamp = new Date('2024-08-19T03:33:54.318Z');
expect(row.packet_timestamp.getTime()).toEqual(expected_timestamp.getTime()) expect(row.packet_timestamp.getTime()).toEqual(expected_timestamp.getTime());
if (event !== null && event.type === EventType.Warning) { if (event !== null && event.type === EventType.Warning) {
expect(event.severity).toEqual(Severity.Low); expect(event.severity).toEqual(Severity.Low);
} else { } else {
throw 'wrong event type'; throw 'wrong event type';
} }
} else { } else {
throw 'wrong row type' throw 'wrong row type';
} }
}); });
}); });
+7 -9
View File
@@ -23,14 +23,14 @@ export class ReportMetadata {
this.rayhunter = ndjson.rayhunter; this.rayhunter = ndjson.rayhunter;
if (ndjson.report_version === undefined) { if (ndjson.report_version === undefined) {
this.report_version = 1; this.report_version = 1;
this.analyzers.forEach(analyzer => { this.analyzers.forEach((analyzer) => {
analyzer.version = 1; analyzer.version = 1;
}); });
} else { } else {
this.report_version = ndjson.report_version; this.report_version = ndjson.report_version;
} }
} }
}; }
export type RayhunterMetadata = { export type RayhunterMetadata = {
rayhunter_version: string; rayhunter_version: string;
@@ -53,7 +53,7 @@ export enum AnalysisRowType {
export type SkippedPacket = { export type SkippedPacket = {
type: AnalysisRowType.Skipped; type: AnalysisRowType.Skipped;
reason: string; reason: string;
} };
export type PacketAnalysis = { export type PacketAnalysis = {
type: AnalysisRowType.Analysis; type: AnalysisRowType.Analysis;
@@ -111,11 +111,10 @@ function get_v1_rows(row_jsons: any[]): AnalysisRow[] {
rows.push({ rows.push({
type: AnalysisRowType.Skipped, type: AnalysisRowType.Skipped,
reason, reason,
}) });
} }
for (const analysis_json of row_json.analysis) { for (const analysis_json of row_json.analysis) {
const events: Event[] = analysis_json.events const events: Event[] = analysis_json.events.map((event_json: any): Event | null => {
.map((event_json: any): Event | null => {
if (event_json === null) { if (event_json === null) {
return null; return null;
} else { } else {
@@ -141,8 +140,7 @@ function get_v2_rows(row_jsons: any[]): AnalysisRow[] {
reason: row_json.skipped_message_reason, reason: row_json.skipped_message_reason,
}); });
} else { } else {
const events: Event[] = row_json.events const events: Event[] = row_json.events.map((event_json: any): Event | null => {
.map((event_json: any): Event | null => {
if (event_json === null) { if (event_json === null) {
return null; return null;
} else { } else {
@@ -182,7 +180,7 @@ function get_report_stats(rows: AnalysisRow[]): ReportStatistics {
num_warnings, num_warnings,
num_informational_logs, num_informational_logs,
num_skipped_packets, num_skipped_packets,
} };
} }
export function parse_finished_report(report_json: NewlineDeliminatedJson): AnalysisReport { export function parse_finished_report(report_json: NewlineDeliminatedJson): AnalysisReport {