Skip to content

Commit a6c6055

Browse files
authored
fix: examples/compose - a deny rule was incorrectly implemented (#841)
The conversion to a number of the version string evaluated to a boolean. Subsequently the boolean was compared to a number, which always resulted in a failure to comply to that rule. This PR fixes the conversion error so that the comparison now works as expected. This PR also adds some tests to prevent regression. Signed-off-by: Dennis Geurts <github@dennisg.nl>
1 parent ea57007 commit a6c6055

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

acceptance.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,18 @@ EOF"
378378
[[ "$output" =~ "No images tagged latest" ]]
379379
}
380380

381+
@test "Can validate a docker-compose file that does not conform to the policy" {
382+
run ./conftest test -p examples/compose/policy examples/compose/docker-compose.yml --no-color
383+
[ "$status" -eq 1 ]
384+
[[ "$output" =~ "2 tests, 0 passed, 0 warnings, 2 failures, 0 exceptions" ]]
385+
}
386+
387+
@test "Can validate a docker-compose file that conforms to the policy" {
388+
run ./conftest test -p examples/compose/policy examples/compose/docker-compose-valid.yml --no-color
389+
[ "$status" -eq 0 ]
390+
[[ "$output" =~ "2 tests, 2 passed, 0 warnings, 0 failures, 0 exceptions" ]]
391+
}
392+
381393
@test "The number of tests run is accurate" {
382394
run ./conftest test -p examples/kubernetes/policy examples/kubernetes/service.yaml --no-color
383395
[ "$status" -eq 0 ]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3.5'
2+
services:
3+
web:
4+
build: .
5+
ports:
6+
- "5000:5000"
7+
redis:
8+
image: "redis:some-hash"

examples/compose/policy/deny.rego

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package main
22

3-
version {
4-
to_number(input.version)
5-
}
3+
version := to_number(input.version)
64

75
deny[msg] {
86
endswith(input.services[_].image, ":latest")

0 commit comments

Comments
 (0)