From c47de94bff6a0260c470ffe0e094ce2550ae9855 Mon Sep 17 00:00:00 2001 From: Emily Rodriguez Date: Tue, 25 Feb 2025 13:55:29 -0500 Subject: [PATCH 1/2] add test to describe the ckl severity on output Signed-off-by: Emily Rodriguez --- .../checklist_reverse_mapper_severity.spec.ts | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 libs/hdf-converters/test/mappers/reverse/checklist_reverse_mapper_severity.spec.ts diff --git a/libs/hdf-converters/test/mappers/reverse/checklist_reverse_mapper_severity.spec.ts b/libs/hdf-converters/test/mappers/reverse/checklist_reverse_mapper_severity.spec.ts new file mode 100644 index 000000000..a9dff757c --- /dev/null +++ b/libs/hdf-converters/test/mappers/reverse/checklist_reverse_mapper_severity.spec.ts @@ -0,0 +1,58 @@ +import fs from 'fs'; +import { ChecklistResults } from '../../../src/ckl-mapper/checklist-mapper'; +import { Stigdata, Checklist } from '../../../src/ckl-mapper/checklistJsonix'; +describe('checklist_mapper_severity_mapping', () => { + it('Maps control V-61867 to correct severity category', () => { + const hdfData = loadFile('sample_jsons/attestations/triple_overlay_profile_sample.json'); + const mapper = new ChecklistResults(hdfData); + const jsonixData = mapper.getJsonix(); + const severity = extractSeverity(jsonixData, 2, 1); + const status = extractStatus(jsonixData, 2); + expect(severity).toBe('medium'); + expect(status).toBe('Not_Applicable'); + // Optional: Check the final HDF output as well + // saveCklOutput(mapper, 'sample_jsons/checklist_mapper/triple_overlay_sample_converted_from_hdf_with_overwritten_severity.ckl'); + }); +}); +/** + * Load and parse the HDF file. + * @param filePath Path to the HDF file. + * @returns Parsed HDF data. + */ +function loadFile(filePath: string): any { + return JSON.parse(fs.readFileSync(filePath, { encoding: 'utf-8' })); +} +/** + * Extract the severity string for a specific control from the mapper. + * @param jsonixData Checklist data in jsonix format. + * @param vulnIndex Index of the vulnerability in the list. + * @param stigdataIndex Index of the stigdata element. + * @returns Severity string. + */ +function extractSeverity(jsonixData: Checklist, vulnIndex: number, stigdataIndex: number): string | undefined { + const istig = (jsonixData?.value as Stigdata)?.stigs?.istig[0]; + const vuln = istig?.vuln[vulnIndex]; + const stigdataElement = vuln?.stigdata[stigdataIndex]; + return stigdataElement?.attributedata ?? undefined; +} +/** + * Extract the status string for a specific control from the mapper. + * @param jsonixData Checklist data in jsonix format. + * @param vulnIndex Index of the vulnerability in the list. + * @returns Status string. + */ +function extractStatus(jsonixData: Checklist, vulnIndex: number): string | undefined { + const istig = (jsonixData?.value as Stigdata)?.stigs?.istig[0]; + const vuln = istig?.vuln[vulnIndex]; + const status = vuln?.status; + return status; +} +/** + * Save the CKL output to a file. + * @param mapper ChecklistResults instance. + * @param outputPath Path to save the CKL output. + */ +function saveCklOutput(mapper: ChecklistResults, outputPath: string): void { + const cklOutput = mapper.toCkl(); + fs.writeFileSync(outputPath, cklOutput); +} \ No newline at end of file From 3c8b7e82a4be1cc86eb978f333bf7c202d135f9f Mon Sep 17 00:00:00 2001 From: Emily Rodriguez Date: Tue, 25 Feb 2025 15:09:42 -0500 Subject: [PATCH 2/2] add severity tag in sample triple overlay profile json Signed-off-by: Emily Rodriguez --- .../sample_jsons/attestations/triple_overlay_profile_sample.json | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/hdf-converters/sample_jsons/attestations/triple_overlay_profile_sample.json b/libs/hdf-converters/sample_jsons/attestations/triple_overlay_profile_sample.json index 10c15bd52..2e12637be 100644 --- a/libs/hdf-converters/sample_jsons/attestations/triple_overlay_profile_sample.json +++ b/libs/hdf-converters/sample_jsons/attestations/triple_overlay_profile_sample.json @@ -1081,6 +1081,7 @@ } ], "tags": { + "severity": "medium", "gtitle": "SRG-APP-000133-DB-000179", "gid": "V-61867", "rid": "SV-76357r2_rule",