Assessor_2.0/tests/importers/same-scan-report.test.ts

43 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { isSameScanReportName, scanReportName } from '../../src/domain/import-duplicates';
const CSV_PART = 'Security_Assessment_Report_sevenkingdoms.local_2026_07_22_08_23_22_(Indicators_results).csv';
const CSV_DETAIL = 'Security_Assessment_Report_sevenkingdoms.local_2026_07_22_08_23_22_(SI000011_UsersCanAddComputers).csv';
const HTML_REPORT = 'Security_Assessment_Report_sevenkingdoms.local_2026_07_22_08_23_22.html';
describe('same scan report detection', () => {
it('reads the assessment timestamp embedded in a Purple Knight file name', () => {
expect(scanReportName(HTML_REPORT)?.timestamp).toBe(Date.parse('2026-07-22T08:23:22'));
});
it('recognises the same report exported in another format', () => {
expect(isSameScanReportName(HTML_REPORT, CSV_PART)).toBe(true);
expect(isSameScanReportName(HTML_REPORT, CSV_DETAIL)).toBe(true);
});
it('tolerates a deviation of up to two hours', () => {
const twoHoursLater = 'Security_Assessment_Report_sevenkingdoms.local_2026_07_22_10_23_22.html';
const threeHoursLater = 'Security_Assessment_Report_sevenkingdoms.local_2026_07_22_11_23_22.html';
expect(isSameScanReportName(HTML_REPORT, twoHoursLater)).toBe(true);
expect(isSameScanReportName(HTML_REPORT, threeHoursLater)).toBe(false);
});
it('keeps a genuinely newer assessment of the same domain importable', () => {
const nextDay = 'Security_Assessment_Report_sevenkingdoms.local_2026_07_23_08_23_22.html';
expect(isSameScanReportName(HTML_REPORT, nextDay)).toBe(false);
});
it('does not confuse different domains', () => {
const otherDomain = 'Security_Assessment_Report_winterfell.local_2026_07_22_08_23_22.html';
expect(isSameScanReportName(HTML_REPORT, otherDomain)).toBe(false);
});
// PingCastle schreibt bei jedem Lauf denselben Dateinamen ohne Zeitstempel.
// Ueber den Namen darf deshalb nicht verglichen werden, sonst gaelte jeder
// neue Scan als Wiederholung.
it('never matches file names without an embedded timestamp', () => {
expect(scanReportName('ad_hc_sevenkingdoms.local.html')).toBeUndefined();
expect(isSameScanReportName('ad_hc_sevenkingdoms.local.html', 'ad_hc_sevenkingdoms.local.html')).toBe(false);
});
});