diff --git a/acceptance/examples/ham.rego b/acceptance/examples/ham.rego new file mode 100644 index 000000000..1244fb035 --- /dev/null +++ b/acceptance/examples/ham.rego @@ -0,0 +1,18 @@ +package ham + +import rego.v1 + +# METADATA +# title: Ham +# description: Ham ham ham +# custom: +# short_name: delicious +# +deny contains result if { + value := object.get(input, "ham", "yucky") + value != "delicious" + result := { + "msg": "ham is not delicious", + "code": "ham.delicious", + } +} diff --git a/acceptance/examples/multiple_sources_config.yaml b/acceptance/examples/multiple_sources_config.yaml new file mode 100644 index 000000000..bf2be9ff2 --- /dev/null +++ b/acceptance/examples/multiple_sources_config.yaml @@ -0,0 +1,6 @@ +--- +sources: + - policy: + - "git::https://${GITHOST}/git/ham-policy" + - policy: + - "git::https://${GITHOST}/git/spam-policy" diff --git a/acceptance/examples/spam.rego b/acceptance/examples/spam.rego new file mode 100644 index 000000000..6f5fe4c7b --- /dev/null +++ b/acceptance/examples/spam.rego @@ -0,0 +1,18 @@ +package spam + +import rego.v1 + +# METADATA +# title: Spam +# description: Spam spam spam +# custom: +# short_name: valid +# +deny contains result if { + value := object.get(input, "spam", false) + not value + result := { + "msg": "spam is not true", + "code": "spam.valid", + } +} diff --git a/features/__snapshots__/validate_input.snap b/features/__snapshots__/validate_input.snap index e28e2e3fd..827f5cb08 100755 --- a/features/__snapshots__/validate_input.snap +++ b/features/__snapshots__/validate_input.snap @@ -39,4 +39,54 @@ Error: 1 error occurred: +--- + +[policy with multiple sources:stdout - 1] +{ + "success": false, + "filepaths": [ + { + "filepath": "input.yaml", + "violations": [ + { + "msg": "ham is not delicious", + "metadata": { + "code": "ham.delicious" + } + }, + { + "msg": "spam is not true", + "metadata": { + "code": "spam.valid" + } + } + ], + "warnings": [], + "successes": null, + "success": false, + "success-count": 0 + } + ], + "policy": { + "sources": [ + { + "policy": [ + "git::https://${GITHOST}/git/ham-policy" + ] + }, + { + "policy": [ + "git::https://${GITHOST}/git/spam-policy" + ] + } + ] + }, + "ec-version": "${EC_VERSION}", + "effective-time": "${TIMESTAMP}" +} +--- + +[policy with multiple sources:stderr - 1] +Error: success criteria not met + --- diff --git a/features/validate_input.feature b/features/validate_input.feature index aa4a74e32..71cf9c546 100644 --- a/features/validate_input.feature +++ b/features/validate_input.feature @@ -1,6 +1,6 @@ Feature: validate input The ec command line should be able to inspect input files - + Background: Given stub git daemon running @@ -49,3 +49,20 @@ Feature: validate input When ec command is run with "validate input --file pipeline_definition.yaml --policy git::https://${GITHOST}/git/sad-day-config.git" Then the exit status should be 1 Then the output should match the snapshot + + Scenario: policy with multiple sources + Given a git repository named "multiple-sources-config" with + | policy.yaml | examples/multiple_sources_config.yaml | + Given a git repository named "spam-policy" with + | main.rego | examples/spam.rego | + Given a git repository named "ham-policy" with + | main.rego | examples/ham.rego | + Given a pipeline definition file named "input.yaml" containing + """ + --- + spam: false + ham: rotten + """ + When ec command is run with "validate input --file input.yaml --policy git::https://${GITHOST}/git/multiple-sources-config.git" + Then the exit status should be 1 + Then the output should match the snapshot