Skip to content

Commit

Permalink
SSG Test Suite: Add option --profile ALL to rule mode.
Browse files Browse the repository at this point in the history
This value will activate the profile (all) when running oscap and will
make sure that the profile metadata from test scenarios are correctly
overriden.
  • Loading branch information
ggbecker committed Sep 4, 2019
1 parent dcb326b commit b4dbfde
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion tests/ssg_test_suite/oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def generate_fixes_remotely(formatting, verbose_path):
]
command_operands = ['/{arf_file}'.format(** formatting)]
if 'result_id' in formatting:
command_options.extend(['--result-id', formatting['result_id']])
# sanitize id because when using "(all)" profile the parenthesis
# can cause some bash trouble
result_id = formatting['result_id'].replace("(", "").replace(")", "")
command_options.extend(['--result-id', result_id])

command_string = ' '.join(command_base + command_options + command_operands)
rc, stdout = common.run_cmd_remote(
Expand Down
14 changes: 11 additions & 3 deletions tests/ssg_test_suite/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import data


ALL_PROFILE_ID = "(all)"
# Single quotes are needed because this value is used in
# a bash environment when running oscap-ssh command line utility.
# This has been fixed on OpenSCAP side but the fix has not been released yet:
# https://github.com/OpenSCAP/openscap/pull/1366
ALL_PROFILE_ID = "'(all)'"

logging.getLogger(__name__).addHandler(logging.NullHandler())

Expand Down Expand Up @@ -226,7 +230,10 @@ def _test_target(self, target):

def _modify_parameters(self, script, params):
if self.scenarios_profile:
params['profiles'] = [self.scenarios_profile]
if self.scenarios_profile.lower() == "all":
params['profiles'] = [ALL_PROFILE_ID]
else:
params['profiles'] = [self.scenarios_profile]

if not params["profiles"]:
params["profiles"].append(ALL_PROFILE_ID)
Expand Down Expand Up @@ -343,7 +350,8 @@ def perform_rule_check(options):
checker.scenarios_profile = options.scenarios_profile
# check if target is a complete profile ID, if not prepend profile prefix
if (checker.scenarios_profile is not None and
not checker.scenarios_profile.startswith(OSCAP_PROFILE)):
not checker.scenarios_profile.startswith(OSCAP_PROFILE) and
not checker.scenarios_profile.lower() == "all"):
checker.scenarios_profile = OSCAP_PROFILE+options.scenarios_profile

checker.test_target(options.target)
4 changes: 2 additions & 2 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def parse_args():
default=None,
help="Override the profile used for test scenarios."
" Variable selections will be done according "
"to this profile.")

"to this profile. To use the so called "
"virtual '(all)' profile use the value ALL.")

parser_combined = subparsers.add_parser("combined",
help=("Tests all rules in a profile evaluating them "
Expand Down

0 comments on commit b4dbfde

Please sign in to comment.