Assessor_2.0/tests/importers/source-fixtures.test.ts

105 lines
5.4 KiB
TypeScript

// @vitest-environment jsdom
import { describe, expect, it } from 'vitest';
import cisCatFixture from '../../fixtures/cis-cat/assessment.synthetic.html?raw';
import maesterFixture from '../../fixtures/maester/test-results.synthetic.csv?raw';
import pingCastleFixture from '../../fixtures/pingcastle/healthcheck.synthetic.html?raw';
import { importFile } from '../../src/importers/importer';
import { cisCatProfile } from '../../src/profiles/cis-cat/cis-cat-profile';
import { genericProfile } from '../../src/profiles/generic/generic-profile';
const options = { profiles: [genericProfile] };
describe('synthetic source fixtures', () => {
it('imports the documented PingCastle healthcheck structure', async () => {
const file = new File([pingCastleFixture], 'ad_hc_synthetic.example.html', { type: 'text/html' });
const imported = await importFile(file, options);
expect(imported.format).toBe('HTML');
expect(imported.recognition?.source.selected).toMatchObject({ toolId: 'pingcastle', toolName: 'PingCastle' });
expect(imported.recognition?.source.selected.confidence.level).toBe('high');
expect(imported.recognition?.tables.find(table => table.tableName === 'Risk Scores')?.selected).toBe(true);
expect(imported.sheets.map(sheet => sheet.name)).toEqual(['Risk Scores', 'Domain information']);
expect(imported.sheets[0].analysis.records).toHaveLength(4);
expect(imported.sheets[0].analysis.records[0].title).toBe('Stale Objects');
expect(imported.rawText).toContain('Rule ID:</strong> S-Synthetic');
});
it('imports the documented CIS-CAT report sections and results', async () => {
const file = new File([cisCatFixture], 'CIS-CAT-SYNTHETIC.html', { type: 'text/html' });
const imported = await importFile(file, options);
const results = imported.sheets.find(sheet => sheet.name === 'assessmentResultTable');
const firstCandidate = imported.extraction?.candidates[0];
const candidateValue = (label: string) => firstCandidate?.fields.find(field => field.label === label)?.decodedValue;
expect(imported.format).toBe('HTML');
expect(imported.recognition?.source.selected).toMatchObject({ toolId: 'cis-cat', toolName: 'CIS-CAT Pro' });
expect(imported.recognition?.source.selected.confidence.level).toBe('high');
expect(imported.recognition?.tables.find(table => table.tableName === 'assessmentResultTable')?.selected).toBe(true);
expect(imported.sheets.map(sheet => sheet.name)).toEqual(expect.arrayContaining([
'Assessment Summary',
'Selected Profiles',
'assessmentResultTable',
'Complex Check',
'Synthetic Item',
'XML Evidence',
'Tabelle 9',
'Tabelle 10'
]));
expect(results?.analysis.records).toHaveLength(2);
expect(cisCatProfile.defaults(results).titleColumn).toBe('Benchmark Item');
expect(results?.analysis.records[0].fields.find(field => field.label === 'Benchmark Item')?.value)
.toBe('1.1.1 Ensure the synthetic setting is enabled');
expect(imported.extraction?.extractor.id).toBe('cis-cat-html-source-extractor');
expect(imported.extraction?.candidates).toHaveLength(2);
expect(candidateValue('Rule ID')).toBe('1.1.1');
expect(candidateValue('Benchmark Item')).toBe('1.1.1 Ensure the synthetic setting is enabled');
expect(candidateValue('Result')).toBe('Fail');
expect(candidateValue('Results')).toMatch(/source-table:\d+ "Assessment Evidence/);
expect(candidateValue('Results')).toMatch(/source-table:\d+ "CIS Controls V7\.0/);
expect(candidateValue('Results')).toMatch(/source-table:\d+ "CIS Critical Security Controls V8\.0/);
expect(candidateValue('Results')).not.toContain('XML Evidence');
expect(candidateValue('Description')).toContain('Synthetic recommendation');
expect(candidateValue('Rationale')).toContain('reduces a synthetic risk');
expect(candidateValue('Remediation')).toContain('Enable the setting');
expect(candidateValue('References')).toContain('SYNTHETIC-CONTROL-1');
expect(candidateValue('Rule Result XML')).toContain('```xml');
expect(candidateValue('Rule Result XML')).toContain('synthetic-1.1.1');
expect(candidateValue('CIS-CAT Details')).toBeUndefined();
expect(imported.rawText).toContain('Assessment Details');
});
it('imports the official Maester flat export columns', async () => {
const file = new File([maesterFixture], 'TestResults-synthetic.csv', { type: 'text/csv' });
const imported = await importFile(file, options);
expect(imported.format).toBe('CSV');
expect(imported.recognition?.source.selected).toMatchObject({ toolId: 'maester', toolName: 'Maester' });
expect(imported.recognition?.source.selected.confidence.level).toBe('high');
expect(imported.recognition?.fields.find(field => field.sourceHeader === 'Title')?.appliedRole).toBe('title');
expect(imported.recognition?.fields.find(field => field.sourceHeader === 'Result')?.appliedRole).toBe('status');
expect(imported.sheets[0].analysis.headers).toEqual([
'ID',
'Title',
'Result',
'Severity',
'Tag',
'Block',
'Duration',
'Description',
'ResultDetail',
'TestSkipped',
'SkippedReason',
'ErrorMessage',
'Name',
'HelpUrl',
'TestScriptFile'
]);
expect(imported.sheets[0].analysis.records).toHaveLength(2);
expect(imported.sheets[0].analysis.records[0].title).toBe('Ensure multifactor authentication is configured');
});
});