42 lines
2.5 KiB
TypeScript
42 lines
2.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { CanonicalAssessmentModel } from '../../src/domain/canonical-model';
|
|
import { datahubScanReadiness, isDatahubScanViewable } from '../../src/features/project-import/datahub-scan-readiness';
|
|
|
|
function model(scanRunIds: string[], occurrenceRunIds: string[]): CanonicalAssessmentModel {
|
|
return {
|
|
scanRuns: scanRunIds.map((id, index) => ({ id, assessmentId: 'assessment', sequence: index + 1, label: id, tool: { id: 'test', name: 'Test' }, importedAt: '2026-08-22T00:00:00.000Z' })),
|
|
findingOccurrences: occurrenceRunIds.map((scanRunId, index) => ({ id: `occurrence-${index}`, scanRunId }))
|
|
} as unknown as CanonicalAssessmentModel;
|
|
}
|
|
|
|
describe('Datahub scan readiness', () => {
|
|
it('only marks persisted runs with canonical Work records as viewable', () => {
|
|
const models = [model(['recognized', 'empty'], ['recognized'])];
|
|
expect(datahubScanReadiness(models, 'recognized', 'pingcastle')).toBe('recognized');
|
|
expect(datahubScanReadiness(models, 'empty', 'pingcastle')).toBe('not-viewable');
|
|
expect(datahubScanReadiness(models, 'missing', 'pingcastle')).toBe('not-viewable');
|
|
expect(isDatahubScanViewable('recognized')).toBe(true);
|
|
expect(isDatahubScanViewable('not-viewable')).toBe(false);
|
|
});
|
|
|
|
it('distinguishes generic-but-viewable data from a recognized scanner', () => {
|
|
const models = [model(['generic-run'], ['generic-run'])];
|
|
expect(datahubScanReadiness(models, 'generic-run', 'generic')).toBe('generic');
|
|
expect(isDatahubScanViewable('generic')).toBe(true);
|
|
expect(isDatahubScanViewable('checking')).toBe(false);
|
|
expect(isDatahubScanViewable('unavailable')).toBe(false);
|
|
});
|
|
|
|
it('keeps a Defender asset summary viewable without fabricating findings', () => {
|
|
const value = model(['defender-summary'], []);
|
|
value.importFiles = [{ id: 'file-1', scanRunId: 'defender-summary' }] as CanonicalAssessmentModel['importFiles'];
|
|
value.sourceTables = [{
|
|
id: 'table-1', importFileId: 'file-1', name: 'Assets', index: 0, rowCount: 1, columnCount: 9, attributes: {},
|
|
rows: [{ index: 1, fields: ['Name', 'IP', 'Site', 'Sensor', 'TotalCVEs', 'Critical', 'High', 'Medium', 'Low'].map((label, columnIndex) => ({ key: `column-${columnIndex}`, label, value: columnIndex > 3 ? 0 : 'synthetic' })) }]
|
|
}];
|
|
|
|
expect(datahubScanReadiness([value], 'defender-summary', 'defender-for-iot-vulnerabilities')).toBe('recognized');
|
|
expect(value.findingOccurrences).toHaveLength(0);
|
|
});
|
|
});
|