83 lines
4.4 KiB
TypeScript
83 lines
4.4 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
import cisCatFixture from '../../fixtures/cis-cat/assessment.synthetic.html?raw';
|
|
import { importFile } from '../../src/importers/importer';
|
|
import { importProfiles } from '../../src/profiles/profile-catalog';
|
|
|
|
const FILE_NAME = 'SYNTHETIC-HOST-01-CIS_Synthetic_Benchmark.html';
|
|
|
|
async function importReport(content = cisCatFixture) {
|
|
return importFile(new File([content], FILE_NAME, { type: 'text/html' }), { profiles: importProfiles });
|
|
}
|
|
|
|
function observations(imported: Awaited<ReturnType<typeof importFile>>) {
|
|
return imported.extraction?.environmentObservations ?? [];
|
|
}
|
|
|
|
function value(imported: Awaited<ReturnType<typeof importFile>>, property: string) {
|
|
return observations(imported).find(item => item.property === property);
|
|
}
|
|
|
|
describe('CIS-CAT environment context', () => {
|
|
it('captures the assessed system and the benchmark identity from the report cover page', async () => {
|
|
const imported = await importReport();
|
|
|
|
expect(imported.extraction?.extractor.id).toBe('cis-cat-html-source-extractor');
|
|
expect(imported.extraction?.candidates.length).toBeGreaterThan(0);
|
|
expect(value(imported, 'host.name')?.originalValue).toBe('SYNTHETIC-HOST-01');
|
|
expect(value(imported, 'host.ip_address')?.originalValue).toBe('203.0.113.10');
|
|
expect(value(imported, 'benchmark.name')?.originalValue).toBe('Synthetic CIS Benchmark');
|
|
expect(value(imported, 'benchmark.version')?.originalValue).toBe('2.0.0');
|
|
expect(value(imported, 'benchmark.profile')?.originalValue).toBe('Level 1 - Synthetic Member Server');
|
|
expect(value(imported, 'report.generated_at')?.originalValue).toBe('Friday, July 17 2026 08:00:00');
|
|
expect(value(imported, 'benchmark.assessment_duration')?.originalValue).toBe('1 minutes, 5 seconds');
|
|
expect(value(imported, 'report.engine_version')?.originalValue).toBe('4.61.0');
|
|
// Der Bericht nennt kein Betriebssystem; eine Ableitung aus dem Benchmark
|
|
// waere eine Behauptung.
|
|
expect(value(imported, 'operating_system.name')).toBeUndefined();
|
|
});
|
|
|
|
it('reads a benchmark name out of the XCCDF result identifier when the title carries no readable name', async () => {
|
|
const identifierTitle = cisCatFixture
|
|
.replace('<title>Benchmark Result - Synthetic CIS Benchmark</title>',
|
|
'<title>Benchmark Result xccdf_org.cisecurity.benchmarks_testresult_2.0.0_Synthetic_CIS_Benchmark</title>')
|
|
.replace(/<div id="coverPageSubTitle">[\s\S]*?<\/div>/, '');
|
|
const imported = await importReport(identifierTitle);
|
|
|
|
expect(value(imported, 'benchmark.name')?.originalValue).toBe('Synthetic CIS Benchmark');
|
|
});
|
|
|
|
it('records the declared result counts and the report score as numbers', async () => {
|
|
const imported = await importReport();
|
|
|
|
expect(value(imported, 'benchmark.score')?.normalizedValue).toBe(50);
|
|
expect(value(imported, 'benchmark.result_count.pass')?.normalizedValue).toBe(1);
|
|
expect(value(imported, 'benchmark.result_count.fail')?.normalizedValue).toBe(1);
|
|
expect(value(imported, 'benchmark.result_count.manual')?.normalizedValue).toBe(0);
|
|
expect(value(imported, 'benchmark.scored_passed')?.normalizedValue).toBe(1);
|
|
expect(value(imported, 'benchmark.scored_total')?.normalizedValue).toBe(2);
|
|
});
|
|
|
|
it('keeps only the top level of the section overview as an observation and the full table as a section', async () => {
|
|
const imported = await importReport();
|
|
|
|
expect(value(imported, 'benchmark.section_score.1')).toMatchObject({ label: 'Account Policies', normalizedValue: 50 });
|
|
expect(value(imported, 'benchmark.section_score.2')).toMatchObject({ label: 'Local Policies', normalizedValue: 0 });
|
|
expect(observations(imported).filter(item => item.property.startsWith('benchmark.section_score.'))).toHaveLength(2);
|
|
|
|
const section = imported.extraction?.reportSections?.find(item => item.sectionKey === 'cis-cat-section-scores');
|
|
expect(section?.tables[0].rows).toHaveLength(3);
|
|
expect(section?.tables[0].headers).toContain('Percent');
|
|
});
|
|
|
|
it('reports no system facts when the report carries no cover page', async () => {
|
|
const withoutCover = cisCatFixture.replace(/<div id="coverPageTitle">[\s\S]*?<\/div>/, '');
|
|
const imported = await importReport(withoutCover);
|
|
|
|
expect(value(imported, 'host.name')).toBeUndefined();
|
|
expect(value(imported, 'host.ip_address')).toBeUndefined();
|
|
expect(value(imported, 'benchmark.name')?.originalValue).toBe('Synthetic CIS Benchmark');
|
|
});
|
|
});
|