Skip to content

Commit

Permalink
enforce encryption flag to be string for CKV_AZURE_97
Browse files Browse the repository at this point in the history
  • Loading branch information
gruebel committed Oct 20, 2023
1 parent bdf356b commit aa06ea9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion checkov/arm/checks/resource/VMEncryptionAtHostEnabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def scan_resource_conf(self, conf: dict[str, Any]) -> CheckResult:
input_dict=conf, key_path="properties/virtualMachineProfile/securityProfile/encryptionAtHost"
)

if encryption == "true":
if str(encryption).lower() == "true":
return CheckResult.PASSED

return CheckResult.FAILED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// pass

resource enabled 'Microsoft.Compute/virtualMachines@2021-11-01' = {
name: virtualMachineName
location: location
properties: {
securityProfile: {
encryptionAtHost: true
}
}
}

// fail

resource disabled 'Microsoft.Compute/virtualMachines@2021-11-01' = {
name: virtualMachineName
location: location
properties: {
securityProfile: {
encryptionAtHost: false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path

from checkov.bicep.runner import Runner
from checkov.arm.checks.resource.VMEncryptionAtHostEnabled import check
from checkov.runner_filter import RunnerFilter


def test_examples():
# given
test_files_dir = Path(__file__).parent / "example_VMEncryptionAtHostEnabled"

# when
report = Runner().run(root_folder=str(test_files_dir), runner_filter=RunnerFilter(checks=[check.id]))

# then
summary = report.get_summary()

passing_resources = {
"Microsoft.Compute/virtualMachines.enabled",
}

failing_resources = {
"Microsoft.Compute/virtualMachines.disabled",
}

passed_check_resources = {c.resource for c in report.passed_checks}
failed_check_resources = {c.resource for c in report.failed_checks}

assert summary["passed"] == len(passing_resources)
assert summary["failed"] == len(failing_resources)
assert summary["skipped"] == 0
assert summary["parsing_errors"] == 0

assert passed_check_resources == passing_resources
assert failed_check_resources == failing_resources

0 comments on commit aa06ea9

Please sign in to comment.