示例#1
0
def test_no_failures_are_raised(good_template):
    result = Result()
    rule = PolicyOnUserRule(None, result)
    rule.invoke(good_template)

    assert result.valid
    assert len(result.failed_rules) == 0
    assert len(result.failed_monitored_rules) == 0
示例#2
0
def test_failures_are_raised(bad_template: CFModel):
    result = Result()
    rule = PolicyOnUserRule(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 == "PolicyOnUserRule"
    assert (
        result.failed_monitored_rules[0].reason
        == "IAM policy Policy should not apply directly to users. Should be on group"
    )
示例#3
0
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"},
            )
        ],
    )
示例#4
0
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, [])
示例#5
0
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, [])