Skip to content

Commit

Permalink
fix: set revision string optionally (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
cd-rite authored Dec 20, 2022
1 parent d429923 commit 6cc01ca
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/ReviewParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@
iStigElement.forEach(iStig => {
let checklist = {}
// get benchmarkId
let stigIdElement = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'stigid' )[0]
let stigIdElement = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'stigid' )?.[0]
checklist.benchmarkId = stigIdElement.SID_DATA.replace('xccdf_mil.disa.stig_benchmark_', '')
// get revision
const stigVersion = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'version' )[0].SID_DATA
let stigReleaseInfo = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'releaseinfo' )[0].SID_DATA
const stigRelease = stigReleaseInfo.match(/Release:\s*(.+?)\s/)[1]
const stigRevisionStr = `V${stigVersion}R${stigRelease}`
// get revision data. Extract digits from version and release fields to create revisionStr, if possible.
const stigVersionData = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'version' )?.[0].SID_DATA
let stigVersion = stigVersionData.match(/(\d+)/)?.[1]
let stigReleaseInfo = iStig.STIG_INFO[0].SI_DATA.filter( d => d.SID_NAME === 'releaseinfo' )?.[0].SID_DATA
const stigRelease = stigReleaseInfo.match(/Release:\s*(.+?)\s/)?.[1]
const stigRevisionStr = stigVersion && stigRelease ? `V${stigVersion}R${stigRelease}` : null
checklist.revisionStr = stigRevisionStr

if (checklist.benchmarkId) {
Expand Down Expand Up @@ -399,7 +400,7 @@
const parser = new XMLParser(parseOptions)
let parsed = parser.parse(data)

// Baic sanity checks
// Basic sanity checks
if (!parsed.Benchmark) throw (new Error("No Benchmark element"))
if (!parsed.Benchmark.TestResult) throw (new Error("No TestResult element"))
if (!parsed.Benchmark.TestResult['target']) throw (new Error("No target element"))
Expand Down

0 comments on commit 6cc01ca

Please sign in to comment.