71 lines
4.6 KiB
TypeScript
71 lines
4.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { UnifiedResultProjection } from '../../src/domain/unified-result';
|
|
import type { ImportedDataset } from '../../src/domain/dataset';
|
|
import { makeSheet } from '../../src/importers/sheet-factory';
|
|
import { appendPolicyObservationsToDataset } from '../../src/features/project-import/policy-observations-to-dataset';
|
|
|
|
describe('GPO Work projection', () => {
|
|
it('creates a selectable Work sheet without presenting observations as findings', () => {
|
|
const result = {
|
|
resultProjectionId: 'policy-observation:one', sourceKind: 'policy-observation', sourceResultId: 'one',
|
|
projectId: 'project-one', assessmentId: 'assessment-one', collectionRunId: 'processing-one',
|
|
sourceTool: 'group-policy', title: 'System Access · MinimumPasswordLength',
|
|
severityOriginal: null, severityNormalized: 'unknown', outcomeOriginal: 'configured', outcomeNormalized: 'warning',
|
|
technicalExecutionState: 'completed', resultType: 'informational', isIoe: false, isDeviation: false,
|
|
lifecycleState: 'unknown', mappingConfidence: 0, reviewStatus: 'open', importedAt: '2026-09-03T12:00:00.000Z',
|
|
createdAt: '2026-09-03T12:00:00.000Z', categories: [], policyScope: 'computer',
|
|
policyDeliveryMechanism: 'security-template', policyState: 'configured', policyIdentityStatus: 'unresolved',
|
|
policyIdentityKey: 'security-template:System Access:MinimumPasswordLength',
|
|
policyValues: [{ kind: 'scalar', raw: '14' }], policyDiagnosticCodes: ['identity-review-required'],
|
|
policyBackupInstanceId: 'backup-one', sourceLocator: { objectPath: 'GPO/Machine/GptTmpl.inf#lines=3' }
|
|
} satisfies UnifiedResultProjection;
|
|
|
|
const dataset = appendPolicyObservationsToDataset(null, 'Synthetic client', [result]);
|
|
|
|
expect(dataset?.scanTool).toBe('Group Policy');
|
|
expect(dataset?.sheets).toHaveLength(1);
|
|
expect(dataset?.sheets[0]).toMatchObject({ name: 'Group Policy · Observations', toolId: 'group-policy' });
|
|
expect(dataset?.sheets[0].analysis.headers).toEqual(expect.arrayContaining([
|
|
'Title', 'Status', 'Configured Value', 'Identity Status', 'Source Path'
|
|
]));
|
|
expect(dataset?.sheets[0].analysis.records[0]).toMatchObject({
|
|
title: 'System Access · MinimumPasswordLength'
|
|
});
|
|
expect(dataset?.sheets[0].rows[1]).toContain('Investigate');
|
|
});
|
|
|
|
it('adds Group Policy to the project-wide Work source facet and keeps a dedicated sheet', () => {
|
|
const result = {
|
|
resultProjectionId: 'policy-observation:two', sourceKind: 'policy-observation', sourceResultId: 'two',
|
|
projectId: 'project-one', assessmentId: 'assessment-one', collectionRunId: 'processing-one',
|
|
sourceTool: 'group-policy', title: 'Privilege Rights · SeSecurityPrivilege',
|
|
severityOriginal: null, severityNormalized: 'unknown', outcomeOriginal: 'configured', outcomeNormalized: 'warning',
|
|
technicalExecutionState: 'completed', resultType: 'informational', isIoe: false, isDeviation: false,
|
|
lifecycleState: 'unknown', mappingConfidence: 0, reviewStatus: 'open', importedAt: '2026-09-03T12:00:00.000Z',
|
|
createdAt: '2026-09-03T12:00:00.000Z', categories: [], policyScope: 'computer',
|
|
policyDeliveryMechanism: 'security-template', policyState: 'configured', policyIdentityStatus: 'unresolved',
|
|
policyIdentityKey: 'security-template:Privilege Rights:SeSecurityPrivilege', policyValues: [{ kind: 'principal-set', principals: ['S-1-5-19'] }],
|
|
policyDiagnosticCodes: [], policyBackupInstanceId: 'backup-two'
|
|
} satisfies UnifiedResultProjection;
|
|
const aggregate = makeSheet('Synthetic · All Records', [
|
|
['Source: File', 'Source: Sheet', 'Source: Scan', 'Title', 'Status'],
|
|
['scanner.csv', 'Findings', 'Scanner · 2026-09-03', 'Scanner finding', 'Failed']
|
|
], '', 'Synthetic client', { isProjectSheet: true });
|
|
const scannerDataset: ImportedDataset = {
|
|
fileName: 'Synthetic', fileSize: 10, lastModified: 0, format: 'Project', rawText: '',
|
|
sheets: [aggregate], profileId: 'generic', scanTool: 'Scanner'
|
|
};
|
|
|
|
const dataset = appendPolicyObservationsToDataset(scannerDataset, 'Synthetic client', [result]);
|
|
const sourceIndex = dataset!.sheets[0].analysis.headers.indexOf('Source: Scan');
|
|
|
|
expect(dataset?.sheets.map(sheet => sheet.name)).toEqual([
|
|
'Synthetic · All Records', 'Group Policy · Observations'
|
|
]);
|
|
expect(dataset?.sheets[0].rows.slice(1).map(row => row[sourceIndex])).toEqual([
|
|
'Scanner · 2026-09-03', 'Group Policy · 2026-09-03T12:00:00.000Z'
|
|
]);
|
|
expect(dataset?.sheets[0].analysis.records.map(record => record.title)).toContain('Privilege Rights · SeSecurityPrivilege');
|
|
});
|
|
});
|