From 27b9148f3c863302ea302a493a5f5108facd1315 Mon Sep 17 00:00:00 2001 From: "George M. Dias" Date: Fri, 21 Apr 2023 09:56:25 -0500 Subject: [PATCH] Update the toRuby Process (#25) * Updated the toRuby to prevent from setting empty tags to nil Signed-off-by: George Dias * allow severity and satisifies to have nil values on the tag Signed-off-by: Emily Rodriguez --------- Signed-off-by: George Dias Signed-off-by: Emily Rodriguez Co-authored-by: Emily Rodriguez --- package-lock.json | 4 ++-- src/objects/control.ts | 10 ++++++++-- .../inputs-interpolation/SV-204392.rb | 4 ++-- test/tests/control.spec.ts | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index fd2765b0..4e6b62b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mitre/inspec-objects", - "version": "0.0.34", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@mitre/inspec-objects", - "version": "0.0.34", + "version": "1.0.0", "license": "Apache-2.0", "dependencies": { "@types/flat": "^5.0.2", diff --git a/src/objects/control.ts b/src/objects/control.ts index e058d096..17b3e7d7 100644 --- a/src/objects/control.ts +++ b/src/objects/control.ts @@ -200,7 +200,6 @@ export default class Control { } else { result += ` ref ${escapeQuotes(ref.ref?.toString() || '')}, url: ${escapeQuotes(ref.url || '')}` } - }); } @@ -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}`);} } }); diff --git a/test/sample_data/controls-cookstyle/inputs-interpolation/SV-204392.rb b/test/sample_data/controls-cookstyle/inputs-interpolation/SV-204392.rb index bdc5dcfc..c1165fda 100644 --- a/test/sample_data/controls-cookstyle/inputs-interpolation/SV-204392.rb +++ b/test/sample_data/controls-cookstyle/inputs-interpolation/SV-204392.rb @@ -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 diff --git a/test/tests/control.spec.ts b/test/tests/control.spec.ts index 23df5a95..0f22c0cc 100644 --- a/test/tests/control.spec.ts +++ b/test/tests/control.spec.ts @@ -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