Skip to content

Commit 3e4980f

Browse files
committed
Update XCCDF mapper and expected XML->HDF test outputs to not include static analysis tags if there are already existing found NIST tags and/or mapped CCI->NIST tags
Signed-off-by: Joyce Quach <[email protected]>
1 parent b48e65a commit 3e4980f

10 files changed

+2052
-2173
lines changed

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-ComplianceAsCode-ubuntu1804-hdf.json

Lines changed: 448 additions & 592 deletions
Large diffs are not rendered by default.

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-rhel7-hdf-withraw.json

Lines changed: 196 additions & 196 deletions
Large diffs are not rendered by default.

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-rhel7-hdf.json

Lines changed: 196 additions & 196 deletions
Large diffs are not rendered by default.

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-rhel8-hdf-withraw.json

Lines changed: 199 additions & 199 deletions
Large diffs are not rendered by default.

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-openscap-rhel8-hdf.json

Lines changed: 199 additions & 199 deletions
Large diffs are not rendered by default.

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-scc-rhel7-hdf-withraw.json

Lines changed: 195 additions & 195 deletions
Large diffs are not rendered by default.

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-scc-rhel7-hdf.json

Lines changed: 195 additions & 195 deletions
Large diffs are not rendered by default.

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-scc-rhel8-hdf-withraw.json

Lines changed: 199 additions & 199 deletions
Large diffs are not rendered by default.

libs/hdf-converters/sample_jsons/xccdf_results_mapper/xccdf-scc-rhel8-hdf.json

Lines changed: 199 additions & 199 deletions
Large diffs are not rendered by default.

libs/hdf-converters/src/xccdf-results-mapper.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ExecJSON} from 'inspecjs';
1+
import {ExecJSON, is_control, NistControl, parse_nist} from 'inspecjs';
22
import * as _ from 'lodash';
33
import {version as HeimdallToolsVersion} from '../package.json';
44
import {
@@ -146,8 +146,31 @@ function extractCci(input: IIdent | IIdent[]): string[] {
146146
return output;
147147
}
148148

149+
function extractNist(input: IIdent | IIdent[]): string[] {
150+
const inputArray = asArray(input);
151+
return inputArray
152+
.map((element) =>
153+
_.get(
154+
element,
155+
'text',
156+
'' // Rules may not always contain references.
157+
)
158+
)
159+
.map(parse_nist)
160+
.filter(is_control)
161+
.flatMap((c) => c.canonize() || []);
162+
}
163+
149164
function nistTag(input: IIdent | IIdent[]): string[] {
150-
return CCI2NIST(extractCci(input), DEFAULT_STATIC_CODE_ANALYSIS_NIST_TAGS);
165+
// The XCCDF results input file might already contain some NIST tags.
166+
const existingNists = extractNist(input);
167+
168+
// It might also have CCI tags adjacent to the NIST tags.
169+
const ccis = extractCci(input);
170+
const nistsFromMappedCcis = CCI2NIST(ccis, []);
171+
172+
const nists = _.uniq([...existingNists, ...nistsFromMappedCcis]);
173+
return nists.length > 0 ? nists : DEFAULT_STATIC_CODE_ANALYSIS_NIST_TAGS;
151174
}
152175

153176
/**
@@ -307,7 +330,7 @@ export class XCCDFResultsMapper extends BaseConverter {
307330
transformer: extractCci
308331
},
309332
nist: {
310-
path: ['ident', 'reference'],
333+
path: ['ident', 'reference'], // WIP: figure out why reference isn't being pulled
311334
transformer: nistTag
312335
},
313336
severity: {path: 'severity'},

0 commit comments

Comments
 (0)