def test_no_failures_are_raised(good_template):
    rule = ManagedPolicyOnUserRule(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):
    rule = ManagedPolicyOnUserRule(None)
    result = rule.invoke(bad_template)

    assert result.valid
    assert len(result.failed_rules) == 0
    assert len(result.failed_monitored_rules) == 1
    assert result.failed_monitored_rules[0].rule == "ManagedPolicyOnUserRule"
    assert (
        result.failed_monitored_rules[0].reason ==
        "IAM managed policy DirectManagedPolicy should not apply directly to users. Should be on group"
    )
Пример #3
0
def test_failures_are_raised(bad_template):
    rule = ManagedPolicyOnUserRule(None)
    result = rule.invoke(bad_template)

    assert not result.valid
    assert compare_lists_of_failures(
        result.failures,
        [
            Failure(
                granularity=RuleGranularity.RESOURCE,
                reason=
                "IAM managed policy DirectManagedPolicy should not apply directly to users. Should be on group",
                risk_value=RuleRisk.MEDIUM,
                rule="ManagedPolicyOnUserRule",
                rule_mode=RuleMode.BLOCKING,
                actions=None,
                resource_ids={"DirectManagedPolicy"},
            )
        ],
    )
Пример #4
0
def test_rule_supports_filter_config(bad_template, default_allow_all_config):
    rule = ManagedPolicyOnUserRule(default_allow_all_config)
    result = rule.invoke(bad_template)

    assert result.valid
    assert compare_lists_of_failures(result.failures, [])
Пример #5
0
def test_no_failures_are_raised(good_template):
    rule = ManagedPolicyOnUserRule(None)
    result = rule.invoke(good_template)

    assert result.valid
    assert compare_lists_of_failures(result.failures, [])