Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for ckl severity #6666

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@
}
],
"tags": {
"severity": "medium",
"gtitle": "SRG-APP-000133-DB-000179",
"gid": "V-61867",
"rid": "SV-76357r2_rule",
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Loading