Skip to content

Commit

Permalink
Add a warning to AutoMatus
Browse files Browse the repository at this point in the history
This adds a warning that prevents a confusion in situation when
a test scenario has a profile in its header but the rule isn't
a part of that profile but is present in the built data stream.

For more context, see:
ComplianceAsCode#10369
  • Loading branch information
jan-cerny committed Mar 30, 2023
1 parent 94fb584 commit a8f42b9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/ssg_test_suite/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,19 @@ def _change_variable_value(self, varname, value):
os.rename(temp_datastream, self.datastream)
os.unlink(xslt_filename)

def _verify_rule_presence(self, rule_id, script, profiles):
for profile_id in profiles:
if profile_id == OSCAP_PROFILE_ALL_ID:
continue
rules_in_profile = xml_operations.get_all_rule_ids_in_profile(
self.datastream, self.benchmark_id, profile_id, logging)
short_rule_id = rule_id.replace(OSCAP_RULE, "")
if short_rule_id not in rules_in_profile:
logging.warning(
"Rule {0} isn't part of profile {1} requested by "
"script {2}.".format(rule_id, profile_id, script)
)

def _check_rule_scenario(self, scenario, remote_rule_dir, rule_id, remediation_available):
if not _apply_script(
remote_rule_dir, self.test_env, scenario.script):
Expand All @@ -541,6 +554,7 @@ def _check_rule_scenario(self, scenario, remote_rule_dir, rule_id, remediation_a
if scenario.script_params['profiles']:
profiles = get_viable_profiles(
scenario.script_params['profiles'], self.datastream, self.benchmark_id, scenario.script)
self._verify_rule_presence(rule_id, scenario.script, profiles)
else:
# Special case for combined mode when scenario.script_params['profiles']
# is empty which means scenario is not applicable on given profile.
Expand Down

0 comments on commit a8f42b9

Please sign in to comment.