-
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
fix: returns error with illegal args with unknowns flag (#7127) #7149
fix: returns error with illegal args with unknowns flag (#7127) #7149
Conversation
212dbd1
to
13205b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this! It's got the right shape, I'm just wondering if we could attempt to parse the argument, to have exactly the same guards as would happen later on 🤔 Would you be up for trying this approach?
Thanks again for contributing. 🎉
cmd/eval.go
Outdated
//* check if illegal arguments is passed with unknowns flag | ||
regexArr := regexp.MustCompile(`^\[.*\]$`) | ||
for _, unknwn := range p.unknowns { | ||
if regexArr.MatchString(unknwn) { | ||
return errors.New(errIllegalUnknownsArg.Error()) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can attempt to parse it using ast.ParseTerm
, like
t, err := ast.ParseTerm(unknwn)
if err != nil { ... }
and then check t.Value
's type, like
switch t.Value.(type) {
case ast.Ref: // OK
default:
return errors.New(errIllegalUnknownsArg.Error())
}
That way, we should be able to capture more illegal inputs than using the regexp. For example, proficient rego users could attempt to pass a set of things like {data.unknown, input.foobar}
using {..}
which isn't captured by the regular expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure...will look into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ca4d344
to
b0d4c94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Just one small ask for the tests. This is a nice contribution 👏
name: "happy path: passing ref as unknown", | ||
unknowns: "data.posts", | ||
expectedErr: nil, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, could you add cases for these?
input
input.users
just to be sure that it'll all end up a ref.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the required changes in the test cases. could you plz review
…agent#7127) Signed-off-by: kunal.das <[email protected]>
Signed-off-by: kunal.das <[email protected]>
Signed-off-by: kunal.das <[email protected]>
b0d4c94
to
f34fb2a
Compare
cmd/eval.go
Outdated
case ast.Ref: | ||
return nil | ||
default: | ||
return errors.New(errIllegalUnknownsArg.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Can't we simplify this? 🤔
return errors.New(errIllegalUnknownsArg.Error()) | |
return errIllegalUnknownsArg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/eval.go
Outdated
@@ -132,6 +137,21 @@ func validateEvalParams(p *evalCommandParams, cmdArgs []string) error { | |||
return errors.New("invalid output format for evaluation") | |||
} | |||
|
|||
//* check if illegal arguments is passed with unknowns flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
//* check if illegal arguments is passed with unknowns flag | |
// check if illegal arguments is passed with unknowns flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: kunal.das <[email protected]>
Signed-off-by: kunal.das <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
Why the changes in this PR are needed?
What are the changes in this PR?
Notes to assist PR review:
Further comments: