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 error check in xccdf_results2hdf mapper #4254

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
12 changes: 9 additions & 3 deletions libs/hdf-converters/src/xccdf-results-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
parseXml
} from './base-converter';
import {CciNistMapping} from './mappings/CciNistMapping';
import {DEFAULT_STATIC_CODE_ANALYSIS_NIST_TAGS} from './utils/global';
import {DEFAULT_STATIC_CODE_ANALYSIS_NIST_TAGS, createWinstonLogger} from './utils/global';

const IMPACT_MAPPING: Map<string, number> = new Map([
['critical', 0.9],
Expand All @@ -28,6 +28,8 @@ const RULE_RESULT_PATHS = ['cdf:rule-result', 'rule-result'];
let idTracker = '';
let valueIdTracker: string | undefined = undefined;

let logger = createWinstonLogger('xccdf_results2hdf', 'INFO');

function getRuleResultItem(
testResult: Record<string, unknown>,
pathRuleResultPossibilities: string[],
Expand Down Expand Up @@ -187,8 +189,12 @@ function extractCci(input: IIdent | IIdent[]): string[] {
const output: string[] = [];
inputArray.forEach((element) => {
const text = _.get(element, 'text');
if (text.match(CCI_REGEX)) {
output.push(text);
if(text) {
if (text.match(CCI_REGEX)) {
output.push(text);
}
} else {
logger.info(`No CCI text found for element: ${element}.`)
}
});
return output;
Expand Down