Skip to content
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

validator: prevent multiple filters/predicates per yaml item #2691

Merged
merged 5 commits into from
Oct 25, 2023

Conversation

MustafaSaber
Copy link
Member

Related to #1618.

@MustafaSaber MustafaSaber changed the base branch from master to cw2023freeze October 18, 2023 15:57
Comment on lines 66 to 69
filters, err := eskip.ParseFilters(f)
if len(filters) > 1 {
errs = append(errs, errMultipleFilters)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can check len(filters) == 1 and make error message like "single filter expected".
This would cover both chain and empty string case (not sure if ParseFilters fails on empty string or not).

I also think we should not mention json/yaml in the error message as it is ambiguous and also routegroup could be created programmatically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we check empty first > 1 makes more sense because if the filter was invalid, ParseFilters will return empty filter which will then push 2 errors (parsing & single)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe we should move empty check here to have filter validation in one place.

Note that value might also contain only whitespaces " " which would produce zero filters but will not be empty - currently we do not catch this case. Here parse would correctly handle empty value like that

@@ -56,7 +63,10 @@ func (rgv *RouteGroupValidator) filtersValidation(item *RouteGroupItem) error {
var errs []error
for _, r := range item.Spec.Routes {
for _, f := range r.Filters {
_, err := eskip.ParseFilters(f)
filters, err := eskip.ParseFilters(f)
if len(filters) > 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check number of filters only when err is nil.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I think we should send both errors to decrease roundtrips of fixes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a test case for empty value, maybe eskip.Parse already handles it

Copy link
Member Author

@MustafaSaber MustafaSaber Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without validation ParseFilter/predicate return no error for empty string

Signed-off-by: Mustafa Abdelrahman <[email protected]>
Comment on lines 13 to 14
errMultipleFilters = errors.New("single filter expected")
errMultiplePredicates = errors.New("single predicate expected")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we use this for both no filter and multiple filters I think it should be named like errSingleFilterExpected

Signed-off-by: Mustafa Abdelrahman <[email protected]>
Signed-off-by: Mustafa Abdelrahman <[email protected]>
@RomanZavodskikh
Copy link
Contributor

👍

1 similar comment
@MustafaSaber
Copy link
Member Author

👍

@MustafaSaber MustafaSaber merged commit e7e22ed into cw2023freeze Oct 25, 2023
4 checks passed
@MustafaSaber MustafaSaber deleted the prohibite-multiple-items-per-yaml-item branch October 25, 2023 14:14
MustafaSaber added a commit that referenced this pull request Oct 27, 2023
* Don't allow more than one filter/predicate per yaml/json item

Signed-off-by: Mustafa Abdelrahman <[email protected]>
MustafaSaber added a commit that referenced this pull request Oct 27, 2023
* Don't allow more than one filter/predicate per yaml/json item

Signed-off-by: Mustafa Saber <[email protected]>
szuecs pushed a commit that referenced this pull request Nov 7, 2023
* Don't allow more than one filter/predicate per yaml/json item

Signed-off-by: Mustafa Abdelrahman <[email protected]>
@MustafaSaber MustafaSaber changed the title Prevent multiple items per yaml item validator: Prevent multiple filters/predicates per yaml item Nov 16, 2023
@MustafaSaber MustafaSaber changed the title validator: Prevent multiple filters/predicates per yaml item validator: prevent multiple filters/predicates per yaml item Nov 16, 2023
RomanZavodskikh pushed a commit that referenced this pull request Nov 27, 2023
* Don't allow more than one filter/predicate per yaml/json item

Signed-off-by: Mustafa Abdelrahman <[email protected]>
AlexanderYastrebov pushed a commit that referenced this pull request Nov 27, 2023
* Don't allow more than one filter/predicate per yaml/json item

Signed-off-by: Mustafa Abdelrahman <[email protected]>
AlexanderYastrebov pushed a commit that referenced this pull request Nov 27, 2023
* Don't allow more than one filter/predicate per yaml/json item

Signed-off-by: Mustafa Abdelrahman <[email protected]>
@MustafaSaber MustafaSaber self-assigned this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants