-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add FromQueryPackBundle, allowing conversion of an explorer bundle …
…to a policy bundle. Signed-off-by: Preslav <[email protected]>
- Loading branch information
1 parent
3ed6c68
commit c30ff8d
Showing
2 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,9 +90,9 @@ func TestBundleCompile_ConvertQueryPacks(t *testing.T) { | |
email: [email protected] | ||
filters: 2 == 2 | ||
queries: | ||
- uid: built-in q | ||
- uid: built-in-q | ||
mql: 1 == 1 | ||
title: built-in q | ||
title: built-in-q | ||
groups: | ||
- filters: "true" | ||
queries: | ||
|
@@ -116,6 +116,7 @@ func TestBundleCompile_ConvertQueryPacks(t *testing.T) { | |
}, | ||
} | ||
require.Equal(t, expectedAuthors, bundle.Policies[0].Authors) | ||
require.Equal(t, explorer.ScoringSystem_DATA_ONLY, bundle.Policies[0].ScoringSystem) | ||
|
||
// built in group | ||
expectedBuiltInFilters := &explorer.Filters{ | ||
|
@@ -128,7 +129,7 @@ func TestBundleCompile_ConvertQueryPacks(t *testing.T) { | |
|
||
require.Equal(t, 1, len(bundle.Policies[0].Groups[0].Queries)) | ||
require.Equal(t, "Default Queries", bundle.Policies[0].Groups[0].Title) | ||
require.Equal(t, "built-in q", bundle.Policies[0].Groups[0].Queries[0].Title) | ||
require.Equal(t, "built-in-q", bundle.Policies[0].Groups[0].Queries[0].Title) | ||
require.Equal(t, "1 == 1", bundle.Policies[0].Groups[0].Queries[0].Mql) | ||
require.Equal(t, expectedBuiltInFilters, bundle.Policies[0].Groups[0].Filters) | ||
|
||
|
@@ -145,6 +146,45 @@ func TestBundleCompile_ConvertQueryPacks(t *testing.T) { | |
require.Equal(t, expectedGrpFilters, bundle.Policies[0].Groups[1].Filters) | ||
} | ||
|
||
func TestBundleCompile_FromQueryPackBundle(t *testing.T) { | ||
// this bundle has both built-in queries and group queries | ||
qBundleStr := ` | ||
owner_mrn: //test.sth | ||
packs: | ||
- uid: pack-1 | ||
authors: | ||
- name: author1 | ||
email: [email protected] | ||
filters: 2 == 2 | ||
queries: | ||
- uid: built-in-q | ||
mql: 1 == 1 | ||
title: built-in-q | ||
groups: | ||
- filters: "true" | ||
queries: | ||
- uid: check-1 | ||
mql: 1 == 2 | ||
- uid: check-2 | ||
queries: | ||
- uid: check-2 | ||
mql: 3 == 3 | ||
title: check-2 | ||
` | ||
|
||
qBundle, err := explorer.BundleFromYAML([]byte(qBundleStr)) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, len(qBundle.Packs)) | ||
require.Equal(t, 1, len(qBundle.Queries)) | ||
|
||
converted := policy.FromQueryPackBundle(qBundle) | ||
require.Equal(t, 1, len(converted.Packs)) | ||
require.Equal(t, 1, len(converted.Policies)) | ||
require.Equal(t, 1, len(converted.Queries)) | ||
// built-in group + group from pack | ||
require.Equal(t, 2, len(converted.Policies[0].Groups)) | ||
} | ||
|
||
func TestBundleCompile_RemoveFailingQueries(t *testing.T) { | ||
bundleStr := ` | ||
owner_mrn: //test.sth | ||
|