Skip to content

Commit

Permalink
Update the toRuby Process (#25)
Browse files Browse the repository at this point in the history
* Updated the toRuby to prevent from setting empty tags to nil

Signed-off-by: George Dias <gdias@mitre.org>

* allow severity and satisifies to have nil values on the tag

Signed-off-by: Emily Rodriguez <ecrodriguez@mm279976-pc.lan>

---------

Signed-off-by: George Dias <gdias@mitre.org>
Signed-off-by: Emily Rodriguez <ecrodriguez@mm279976-pc.lan>
Co-authored-by: Emily Rodriguez <ecrodriguez@mm279976-pc.lan>
  • Loading branch information
georgedias and Emily Rodriguez authored Apr 21, 2023
1 parent 868f1fc commit 27b9148
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/objects/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ export default class Control {
} else {
result += ` ref ${escapeQuotes(ref.ref?.toString() || '')}, url: ${escapeQuotes(ref.url || '')}`
}

});
}

Expand Down Expand Up @@ -228,7 +227,14 @@ export default class Control {
result += ` tag ${tag}: ${escapeQuotes(value)}\n`;
}
} else {
result += ` tag ${tag}: nil\n`;
const nilTagList = ['severity', 'satisfies']
if (nilTagList.includes(tag)) {
result += ` tag ${tag}: nil\n`;
}
else {
result += ` tag '${tag}'\n`;
}
if (verbose) {logger.info(`${this.id} does not have a value for tag: ${tag}`);}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
tag cci: ['CCI-001494', 'CCI-001496', 'CCI-002165', 'CCI-002235']
tag nist: ['AU-9', 'AU-9 (3)', 'AC-3 (4)', 'AC-6 (10)']
tag subsystems: ['permissions', 'package', 'rpm']
tag host: nil
tag container: nil
tag 'host'
tag 'container'

if input('disable_slow_controls')
describe "This control consistently takes a long time to run and has been disabled
Expand Down
6 changes: 4 additions & 2 deletions test/tests/control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ TEST_USE_CASES.set('V-93149','should properly write a control with special chara
describe('The control functionality', () => {
const cookstyle_profile = processInSpecProfile(fs.readFileSync('test/sample_data/inspec/json/cookstyle-controls-profile.json', 'utf-8'))

const allKeys =[ ...TEST_USE_CASES.keys() ];
cookstyle_profile.controls.forEach(control => {
// Write the new control to the controls folder
fs.writeFileSync(path.join('test/sample_data/', 'controls-test-results', `${control.id}.rb`), control.toRuby(true))
if (allKeys.includes(control.id)) {
fs.writeFileSync(path.join('test/sample_data/', 'controls-test-results', `${control.id}.rb`), control.toRuby(true))
}
})

// These checks are comparing what the function "toRuby" is outputting with a small sample profile created from
Expand Down

0 comments on commit 27b9148

Please sign in to comment.