|
| 1 | +package compliance_framework.cloud_custodian_resources_detected_test |
| 2 | + |
| 3 | +import data.compliance_framework.cloud_custodian_resources_detected |
| 4 | + |
| 5 | +test_violation_when_resources_detected if { |
| 6 | + fixture := { |
| 7 | + "check": {"name": "ec2-public-ip-check"}, |
| 8 | + "execution": {"status": "success", "error": "", "errors": []}, |
| 9 | + "result": { |
| 10 | + "resources": [{"InstanceId": "i-123"}] |
| 11 | + } |
| 12 | + } |
| 13 | + |
| 14 | + cloud_custodian_resources_detected.violation[{ |
| 15 | + "remarks": "Cloud Custodian check \"ec2-public-ip-check\" matched 1 resource(s)." |
| 16 | + }] with input as fixture |
| 17 | +} |
| 18 | + |
| 19 | +test_violation_when_execution_error_detected if { |
| 20 | + fixture := { |
| 21 | + "check": {"name": "ec2-public-ip-check"}, |
| 22 | + "execution": { |
| 23 | + "status": "error", |
| 24 | + "error": "custodian execution failed", |
| 25 | + "errors": ["custodian execution failed"] |
| 26 | + }, |
| 27 | + "result": { |
| 28 | + "resources": [] |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + cloud_custodian_resources_detected.violation[{ |
| 33 | + "remarks": "Cloud Custodian check \"ec2-public-ip-check\" failed during execution (status=\"error\"). error=custodian execution failed errors=[\"custodian execution failed\"]" |
| 34 | + }] with input as fixture |
| 35 | +} |
| 36 | + |
| 37 | +test_violation_when_only_execution_errors_list_present if { |
| 38 | + fixture := { |
| 39 | + "check": {"name": "ec2-public-ip-check"}, |
| 40 | + "execution": { |
| 41 | + "status": "error", |
| 42 | + "error": "", |
| 43 | + "errors": ["custodian execution failed"] |
| 44 | + }, |
| 45 | + "result": { |
| 46 | + "resources": [] |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + count(cloud_custodian_resources_detected.violation) == 1 with input as fixture |
| 51 | + |
| 52 | + cloud_custodian_resources_detected.violation[{ |
| 53 | + "remarks": "Cloud Custodian check \"ec2-public-ip-check\" failed during execution (status=\"error\"). error= errors=[\"custodian execution failed\"]" |
| 54 | + }] with input as fixture |
| 55 | +} |
| 56 | + |
| 57 | +test_dynamic_title_and_description if { |
| 58 | + fixture := { |
| 59 | + "check": {"name": "ec2-public-ip-check"}, |
| 60 | + "execution": {"status": "error", "error": "boom", "errors": ["boom"]}, |
| 61 | + "result": { |
| 62 | + "resources": [{"InstanceId": "i-123"}, {"InstanceId": "i-456"}] |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + cloud_custodian_resources_detected.title == "Cloud Custodian check \"ec2-public-ip-check\" status=\"error\"" with input as fixture |
| 67 | + cloud_custodian_resources_detected.description == "Cloud Custodian check \"ec2-public-ip-check\" evaluated with status \"error\" and matched 2 resource(s). Execution errors (if any) are treated as violations." with input as fixture |
| 68 | + |
| 69 | + count(cloud_custodian_resources_detected.violation) == 2 with input as fixture |
| 70 | + |
| 71 | + cloud_custodian_resources_detected.violation[{ |
| 72 | + "remarks": "Cloud Custodian check \"ec2-public-ip-check\" matched 2 resource(s)." |
| 73 | + }] with input as fixture |
| 74 | + |
| 75 | + cloud_custodian_resources_detected.violation[{ |
| 76 | + "remarks": "Cloud Custodian check \"ec2-public-ip-check\" failed during execution (status=\"error\"). error=boom errors=[\"boom\"]" |
| 77 | + }] with input as fixture |
| 78 | +} |
| 79 | + |
| 80 | +test_no_violation_when_no_resources if { |
| 81 | + fixture := { |
| 82 | + "check": {"name": "ec2-public-ip-check"}, |
| 83 | + "execution": {"status": "success", "error": "", "errors": []}, |
| 84 | + "result": { |
| 85 | + "resources": [] |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + count(cloud_custodian_resources_detected.violation) == 0 with input as fixture |
| 90 | +} |
| 91 | + |
| 92 | +test_violation_when_check_missing_uses_unknown_check if { |
| 93 | + fixture := { |
| 94 | + "execution": {"status": "success", "error": "", "errors": []}, |
| 95 | + "result": { |
| 96 | + "resources": [{"InstanceId": "i-123"}] |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + cloud_custodian_resources_detected.violation[{ |
| 101 | + "remarks": "Cloud Custodian check \"unknown-check\" matched 1 resource(s)." |
| 102 | + }] with input as fixture |
| 103 | +} |
| 104 | + |
| 105 | +test_no_violation_when_resources_is_not_array if { |
| 106 | + fixture := { |
| 107 | + "check": {"name": "ec2-public-ip-check"}, |
| 108 | + "execution": {"status": "success", "error": "", "errors": []}, |
| 109 | + "result": { |
| 110 | + "resources": null |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + count(cloud_custodian_resources_detected.violation) == 0 with input as fixture |
| 115 | + cloud_custodian_resources_detected.title == "Cloud Custodian check \"ec2-public-ip-check\" status=\"success\"" with input as fixture |
| 116 | + cloud_custodian_resources_detected.description == "Cloud Custodian check \"ec2-public-ip-check\" evaluated with status \"success\" and matched 0 resource(s). Execution errors (if any) are treated as violations." with input as fixture |
| 117 | +} |
0 commit comments