feat: init commit

This commit is contained in:
2023-01-17 22:45:23 +08:00
commit 94130c107c
72 changed files with 7568 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
test: policy.wasm
bats e2e.bats
policy.wasm: policy.rego
opa build -t wasm -e policy/main -o policy.tar.gz policy.rego
tar -xf policy.tar.gz /policy.wasm
rm policy.tar.gz
clean:
rm -f *.wasm *.tar.gz

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bats
@test "input message is not valid" {
run cargo run --example cli -- -v eval policy.wasm -i '{ "message": "mondo" }'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request rejected
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*"result":.*false') -ne 0 ]
[ $(expr "$output" : ".*input\.message has been set to 'mondo'") -ne 0 ]
}
@test "input message is valid" {
run cargo run --example cli -- -v eval policy.wasm -i '{ "message": "world" }'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request rejected
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*"result":.*true') -ne 0 ]
[ $(expr "$output" : ".*input\.message has been set to 'world'") -ne 0 ]
}

View File

@@ -0,0 +1,9 @@
package policy
default main = false
main {
trace(sprintf("input.message has been set to '%v'", [input.message]));
m := input.message;
m == "world"
}