Skip to content

Commit 76b7011

Browse files
authored
VTA-635: Add OpenSearch DoesNotExist to querybuilder (#264)
## What Add OpenSearch DoesNotExist to querybuilder ## Why Since we now want to filter for an Exists/MustNotExists property, we need the according OpenSearch querybuilder. ## References [VTA-635](https://jira.greenbone.net/browse/VTI-635) greenbone/vulnerability-intelligence-backend#565 ## Checklist - [ ] Tests
2 parents de26e92 + 6a1cfbc commit 76b7011

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

pkg/openSearch/osquery/boolQueryBuilder.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (q *BoolQueryBuilder) AddFilterRequest(request *filter.Request) error {
151151
if handler, ok := operatorMapping[field.Operator]; ok {
152152
value := field.Value
153153

154-
if field.Operator == filter.CompareOperatorExists {
154+
if field.Operator == filter.CompareOperatorExists || field.Operator == filter.CompareOperatorDoesNotExist {
155155
value = "" // exists operator does not need a value, but for more consistent handling just pass a dummy value
156156
}
157157
if value == nil {
@@ -289,5 +289,9 @@ func defaultCompareOperators() []CompareOperator {
289289
Operator: filter.CompareOperatorExists,
290290
Handler: HandleCompareOperatorExists, MustCondition: true,
291291
},
292+
{
293+
Operator: filter.CompareOperatorDoesNotExist,
294+
Handler: HandleCompareOperatorExists, MustCondition: false,
295+
},
292296
}
293297
}

pkg/openSearch/osquery/boolQueryBuilder_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,15 @@ func TestBoolQueryBuilder_AddFilterRequest(t *testing.T) {
608608
wantDocuments: []ostesting.TestType{doc0, doc1, doc2},
609609
})
610610

611+
// MustNotExists operator
612+
addTest("operator must not Exists", testCase{
613+
filterRequest: singleFilter(filter.RequestField{
614+
Name: "keywordOmitEmptyField",
615+
Operator: filter.CompareOperatorDoesNotExist,
616+
}),
617+
wantDocuments: []ostesting.TestType{doc0},
618+
})
619+
611620
// BetweenDates operator
612621
addTest("operator BetweenDates (date time string)", testCase{
613622
filterRequest: singleFilter(filter.RequestField{

pkg/query/filter/type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ CompareOperator ENUM(
7575
betweenDates
7676
7777
exists
78+
doesNotExist
7879
7980
isEqualToRating
8081
isNotEqualToRating

pkg/query/filter/type_enum.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)