def _test_target(self, target): try: remote_dir = common.send_scripts(self.test_env.domain_ip) except RuntimeError as exc: msg = "Unable to upload test scripts: {more_info}".format( more_info=str(exc)) raise RuntimeError(msg) self._matching_rule_found = False with test_env.SavedState.create_from_environment( self.test_env, "tests_uploaded") as state: for rule in data.iterate_over_rules(): if not self._matches_target(rule.directory, target): continue self._matching_rule_found = True if not xml_operations.find_rule_in_benchmark( self.datastream, self.benchmark_id, rule.id): logging.error( "Rule '{0}' isn't present in benchmark '{1}' in '{2}'". format(rule.id, self.benchmark_id, self.datastream)) return self._check_rule(rule, remote_dir, state) if not self._matching_rule_found: logging.error("No matching rule ID found for '{0}'".format(target))
def _get_rules_to_test(self, target): rules_to_test = [] for rule in common.iterate_over_rules(): if not self._rule_should_be_tested(rule, target): continue if not xml_operations.find_rule_in_benchmark( self.datastream, self.benchmark_id, rule.id): logging.error( "Rule '{0}' isn't present in benchmark '{1}' in '{2}'" .format(rule.id, self.benchmark_id, self.datastream)) continue rules_to_test.append(rule) return rules_to_test
def _rule_should_be_tested(self, rule, rules_to_be_tested): if 'ALL' in rules_to_be_tested: # don't select rules that are not present in benchmark if not xml_operations.find_rule_in_benchmark( self.datastream, self.benchmark_id, rule.id): return False return True else: for rule_to_be_tested in rules_to_be_tested: # we check for a substring if rule_to_be_tested.startswith(OSCAP_RULE): pattern = rule_to_be_tested else: pattern = OSCAP_RULE + rule_to_be_tested if fnmatch.fnmatch(rule.id, pattern): return True return False