-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WASM "glob" is caching results #2962
Comments
Thanks for reporting this with a repro example 👍 Haven't yet dug into this, but the behaviour surely isn't correct. I wonder if it's a problem with the npm-opa-sdk or the WASM module. Investigation needed |
diff --git a/internal/wasm/sdk/opa/opa_test.go b/internal/wasm/sdk/opa/opa_test.go
index daf9163c..9199f5cb 100644
--- a/internal/wasm/sdk/opa/opa_test.go
+++ b/internal/wasm/sdk/opa/opa_test.go
@@ -52,6 +52,22 @@ func TestOPA(t *testing.T) {
},
WantErr: "",
},
+ {
+ Description: "Only input changing, glob.match",
+ Policy: `
+ default hello = false
+ hello {
+ x := input.message
+ glob.match("world", [":"], x)
+ }`,
+ Query: "data.p.hello = x",
+ Evals: []Eval{
+ Eval{Input: `{"message": "world"}`, Result: `{{"x": true}}`},
+ Eval{Input: `{"message": "no-world"}`, Result: `{{"x": false}}`},
+ Eval{Input: `{"message": "world"}`, Result: `{{"x": true}}`},
+ },
+ WantErr: "",
+ },
{
Description: "Only data changing",
Policy: `a = data.q`,
@@ -145,6 +161,9 @@ a = "c" { input > 2 }`,
}
for _, test := range tests {
+ if test.Description != "Only input changing, glob.match" {
+ continue
+ }
t.Run(test.Description, func(t *testing.T) {
policy := compileRegoToWasm(test.Policy, test.Query)
data := []byte(test.Data) I was able to replicate the problem without node and the npm-opa-wasm package, with the included WASM SDK (Run |
Sharing my notes while digging into this here:
Progress:
Working on the PR now, expect it shortly 😃 |
…ngth string casts Before, the opa_string_t's *char was used as-is; disregarding its length. With certain inputs in consequent evaluations, this would end up using old characters from a previous evaluation. For example, evaluation regex.match("^world$", input.message) with input.message going through the sequence "no-world" "world" would end up running the RE2 PartialMatch against the values "no-world" "worldrld" and the second evaluation would thus wrongly fail. Since glob.match is using regex.match underneath, it would show a similar behaviour, as noted in open-policy-agent#2962 Note: for regex.is_valid, there is no test case. I had been seeing garbage data trailing the pattern string before fixing this: opa_print(): ^foobfdfd[ard� Fixes open-policy-agent#2962. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
…ngth string casts Before, the opa_string_t's *char was used as-is; disregarding its length. With certain inputs in consequent evaluations, this would end up using old characters from a previous evaluation. For example, evaluation regex.match("^world$", input.message) with input.message going through the sequence "no-world" "world" would end up running the RE2 PartialMatch against the values "no-world" "worldrld" and the second evaluation would thus wrongly fail. Since glob.match is using regex.match underneath, it would show a similar behaviour, as noted in #2962 Note: for regex.is_valid, there is no test case. I had been seeing garbage data trailing the pattern string before fixing this: opa_print(): ^foobfdfd[ard� Fixes #2962. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Expected Behavior
To be able to run multiple times the same policy on the JS lib
Actual Behavior
Once it fails, all the rest are
false
Steps to Reproduce the Problem
I've copied the example on https://github.com/open-policy-agent/npm-opa-wasm/tree/master/examples/nodejs-app and made my own small example to display it:
https://github.com/xescugc/opa-wasm-error
This was build using
master
just to be sure as theglobs
where added on #2682The steps are the ones on the README but it's basically to run
node app.js
.Additional Info
If you need more info just ask 😄
The text was updated successfully, but these errors were encountered: