Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit ea822b5

Browse files
committed
better verification on meta tag record upsert
when receiving a new meta tag record upsert request we shouldn't only validate the given query expressions, but also that the given set of expressions can be used to instantiate a query. if that's not the case, then the given meta tag record should be considered invalid and should get rejected.
1 parent 1b895bc commit ea822b5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

expr/tagquery/meta_tag_record.go

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ func ParseMetaTagRecord(metaTags []string, expressions []string) (MetaTagRecord,
2626
return res, err
2727
}
2828

29+
// we don't actually need to instantiate a query at this point, but we want to verify
30+
// that it is possible to instantiate a query from the given meta record expressions.
31+
// if we can't instantiate a query from the given expressions, then the meta record
32+
// upsert request should be considered invalid and should get rejected.
33+
_, err = NewQuery(res.Expressions, 0)
34+
if err != nil {
35+
return res, fmt.Errorf("Failed to instantiate query from given expressions: %s", err)
36+
}
37+
2938
if len(res.Expressions) == 0 {
3039
return res, fmt.Errorf("Meta Tag Record must have at least one query")
3140
}

expr/tagquery/meta_tag_record_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,12 @@ func TestErrorOnParsingMetaTagRecordWithoutQueryy(t *testing.T) {
5858
t.Fatalf("Expected an error, but did not get one")
5959
}
6060
}
61+
62+
func TestErrorOnParsingMetaTagRecordWithValidExpressionsButInvalidQuery(t *testing.T) {
63+
// the given expression is valid, but as a query this set of expressions is not valid
64+
// because every query must have at least one expression requiring a non-empty value
65+
_, err := ParseMetaTagRecord([]string{"meta=tag"}, []string{"a!=b"})
66+
if err == nil {
67+
t.Fatalf("Expected an error, but did not get one")
68+
}
69+
}

0 commit comments

Comments
 (0)