def test_no_failures_are_raised(good_template): rule = PolicyOnUserRule(None) result = rule.invoke(good_template) assert result.valid assert len(result.failed_rules) == 0 assert len(result.failed_monitored_rules) == 0
def test_failures_are_raised(bad_template: CFModel): rule = PolicyOnUserRule(None) result = rule.invoke(bad_template) assert not result.valid assert len(result.failed_rules) == 1 assert len(result.failed_monitored_rules) == 0 assert result.failed_rules[0].rule == "PolicyOnUserRule" assert result.failed_rules[0].reason == "IAM policy Policy should not apply directly to users. Should be on group"
def test_failures_are_raised(bad_template: CFModel): rule = PolicyOnUserRule(None) result = rule.invoke(bad_template) assert not result.valid assert compare_lists_of_failures( result.failures, [ Failure( granularity=RuleGranularity.RESOURCE, reason="IAM policy Policy should not apply directly to users. Should be on group", risk_value=RuleRisk.MEDIUM, rule="PolicyOnUserRule", rule_mode=RuleMode.BLOCKING, actions=None, resource_ids={"Policy"}, ) ], )
def test_rule_supports_filter_config(bad_template, default_allow_all_config): rule = PolicyOnUserRule(default_allow_all_config) result = rule.invoke(bad_template) assert result.valid assert compare_lists_of_failures(result.failures, [])
def test_no_failures_are_raised(good_template): rule = PolicyOnUserRule(None) result = rule.invoke(good_template) assert result.valid assert compare_lists_of_failures(result.failures, [])