mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-04-26 15:39:59 -07:00
web: lint fixes
This commit is contained in:
committed by
Cooper Quintin
parent
1a4deb7524
commit
09d4328dc2
@@ -6,20 +6,18 @@ const SAMPLE_V1_REPORT_NDJSON: NewlineDeliminatedJson = [
|
||||
{
|
||||
analyzers: [
|
||||
{
|
||||
name: "Analyzer 1",
|
||||
description: "A first analyzer",
|
||||
name: 'Analyzer 1',
|
||||
description: 'A first analyzer',
|
||||
},
|
||||
{
|
||||
name: "Analyzer 2",
|
||||
description: "A second analyzer",
|
||||
name: 'Analyzer 2',
|
||||
description: 'A second analyzer',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
timestamp: '2024-10-08T13:25:43.011689003-07:00',
|
||||
skipped_message_reasons: [
|
||||
'The reason why the message was skipped',
|
||||
],
|
||||
skipped_message_reasons: ['The reason why the message was skipped'],
|
||||
analysis: [],
|
||||
},
|
||||
{
|
||||
@@ -44,13 +42,13 @@ const SAMPLE_V2_REPORT_NDJSON: NewlineDeliminatedJson = [
|
||||
{
|
||||
analyzers: [
|
||||
{
|
||||
name: "Analyzer 1",
|
||||
description: "A first analyzer",
|
||||
name: 'Analyzer 1',
|
||||
description: 'A first analyzer',
|
||||
version: 2,
|
||||
},
|
||||
{
|
||||
name: "Analyzer 2",
|
||||
description: "A second analyzer",
|
||||
name: 'Analyzer 2',
|
||||
description: 'A second analyzer',
|
||||
version: 2,
|
||||
},
|
||||
],
|
||||
@@ -78,12 +76,12 @@ describe('analysis report parsing', () => {
|
||||
expect(report.metadata.analyzers).toEqual([
|
||||
{
|
||||
name: 'Analyzer 1',
|
||||
description: "A first analyzer",
|
||||
description: 'A first analyzer',
|
||||
version: 1,
|
||||
},
|
||||
{
|
||||
name: 'Analyzer 2',
|
||||
description: "A second analyzer",
|
||||
description: 'A second analyzer',
|
||||
version: 1,
|
||||
},
|
||||
]);
|
||||
@@ -95,14 +93,14 @@ describe('analysis report parsing', () => {
|
||||
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(row.packet_timestamp.getTime()).toEqual(expected_timestamp.getTime());
|
||||
if (event !== null && event.type === EventType.Warning) {
|
||||
expect(event.severity).toEqual(Severity.Low);
|
||||
} else {
|
||||
throw 'wrong event type';
|
||||
}
|
||||
} else {
|
||||
throw 'wrong row type'
|
||||
throw 'wrong row type';
|
||||
}
|
||||
});
|
||||
|
||||
@@ -112,12 +110,12 @@ describe('analysis report parsing', () => {
|
||||
expect(report.metadata.analyzers).toEqual([
|
||||
{
|
||||
name: 'Analyzer 1',
|
||||
description: "A first analyzer",
|
||||
description: 'A first analyzer',
|
||||
version: 2,
|
||||
},
|
||||
{
|
||||
name: 'Analyzer 2',
|
||||
description: "A second analyzer",
|
||||
description: 'A second analyzer',
|
||||
version: 2,
|
||||
},
|
||||
]);
|
||||
@@ -129,14 +127,14 @@ describe('analysis report parsing', () => {
|
||||
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(row.packet_timestamp.getTime()).toEqual(expected_timestamp.getTime());
|
||||
if (event !== null && event.type === EventType.Warning) {
|
||||
expect(event.severity).toEqual(Severity.Low);
|
||||
} else {
|
||||
throw 'wrong event type';
|
||||
}
|
||||
} else {
|
||||
throw 'wrong row type'
|
||||
throw 'wrong row type';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,14 +23,14 @@ export class ReportMetadata {
|
||||
this.rayhunter = ndjson.rayhunter;
|
||||
if (ndjson.report_version === undefined) {
|
||||
this.report_version = 1;
|
||||
this.analyzers.forEach(analyzer => {
|
||||
this.analyzers.forEach((analyzer) => {
|
||||
analyzer.version = 1;
|
||||
});
|
||||
} else {
|
||||
this.report_version = ndjson.report_version;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export type RayhunterMetadata = {
|
||||
rayhunter_version: string;
|
||||
@@ -53,7 +53,7 @@ export enum AnalysisRowType {
|
||||
export type SkippedPacket = {
|
||||
type: AnalysisRowType.Skipped;
|
||||
reason: string;
|
||||
}
|
||||
};
|
||||
|
||||
export type PacketAnalysis = {
|
||||
type: AnalysisRowType.Analysis;
|
||||
@@ -97,8 +97,8 @@ function get_event(event_json: any): Event {
|
||||
event_json.event_type.severity === 'High'
|
||||
? Severity.High
|
||||
: event_json.event_type.severity === 'Medium'
|
||||
? Severity.Medium
|
||||
: Severity.Low,
|
||||
? Severity.Medium
|
||||
: Severity.Low,
|
||||
message: event_json.message,
|
||||
};
|
||||
}
|
||||
@@ -111,17 +111,16 @@ function get_v1_rows(row_jsons: any[]): AnalysisRow[] {
|
||||
rows.push({
|
||||
type: AnalysisRowType.Skipped,
|
||||
reason,
|
||||
})
|
||||
});
|
||||
}
|
||||
for (const analysis_json of row_json.analysis) {
|
||||
const events: Event[] = analysis_json.events
|
||||
.map((event_json: any): Event | null => {
|
||||
if (event_json === null) {
|
||||
return null;
|
||||
} else {
|
||||
return get_event(event_json);
|
||||
}
|
||||
});
|
||||
const events: Event[] = analysis_json.events.map((event_json: any): Event | null => {
|
||||
if (event_json === null) {
|
||||
return null;
|
||||
} else {
|
||||
return get_event(event_json);
|
||||
}
|
||||
});
|
||||
rows.push({
|
||||
type: AnalysisRowType.Analysis,
|
||||
packet_timestamp: new Date(analysis_json.timestamp),
|
||||
@@ -141,14 +140,13 @@ function get_v2_rows(row_jsons: any[]): AnalysisRow[] {
|
||||
reason: row_json.skipped_message_reason,
|
||||
});
|
||||
} else {
|
||||
const events: Event[] = row_json.events
|
||||
.map((event_json: any): Event | null => {
|
||||
if (event_json === null) {
|
||||
return null;
|
||||
} else {
|
||||
return get_event(event_json);
|
||||
}
|
||||
});
|
||||
const events: Event[] = row_json.events.map((event_json: any): Event | null => {
|
||||
if (event_json === null) {
|
||||
return null;
|
||||
} else {
|
||||
return get_event(event_json);
|
||||
}
|
||||
});
|
||||
rows.push({
|
||||
type: AnalysisRowType.Analysis,
|
||||
packet_timestamp: new Date(row_json.packet_timestamp),
|
||||
@@ -182,7 +180,7 @@ function get_report_stats(rows: AnalysisRow[]): ReportStatistics {
|
||||
num_warnings,
|
||||
num_informational_logs,
|
||||
num_skipped_packets,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function parse_finished_report(report_json: NewlineDeliminatedJson): AnalysisReport {
|
||||
|
||||
Reference in New Issue
Block a user