From 0597f666e4f706e7d8fc1fb90861fe5aae87f02e Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Fri, 7 Apr 2023 00:34:39 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20computed=20filters=20after?= =?UTF-8?q?=20compile=20(#1138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- explorer/bundle.go | 1 + explorer/filters_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/explorer/bundle.go b/explorer/bundle.go index 654c0d087a..6b9cd5ea66 100644 --- a/explorer/bundle.go +++ b/explorer/bundle.go @@ -251,6 +251,7 @@ func (p *Bundle) Compile(ctx context.Context) (*BundleMap, error) { if err = pack.Filters.Compile(ownerMrn); err != nil { return nil, errors.Wrap(err, "failed to compile querypack filters") } + pack.ComputedFilters.AddFilters(pack.Filters) if err := cache.compileQueries(pack.Queries, pack); err != nil { return nil, err diff --git a/explorer/filters_test.go b/explorer/filters_test.go index a13989c623..bf912f7b80 100644 --- a/explorer/filters_test.go +++ b/explorer/filters_test.go @@ -1,6 +1,7 @@ package explorer import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -41,3 +42,17 @@ func TestSummarize(t *testing.T) { assert.Equal(t, "asset.name, filter 2", f.Summarize()) }) } + +func TestBundleAssetFilter(t *testing.T) { + // load the raw bundle + bundle, err := BundleFromPaths("../examples/os.mql.yaml") + require.NoError(t, err) + assert.Equal(t, 1, len(bundle.Packs)) + assert.Equal(t, "asset.family.contains(\"unix\")", bundle.Packs[0].Filters.Items["0"].Mql) + assert.Equal(t, (*Filters)(nil), bundle.Packs[0].ComputedFilters) + + // check that the computed asset filters are set + pbm, err := bundle.Compile(context.Background()) + require.NoError(t, err) + assert.Equal(t, "asset.family.contains(\"unix\")", pbm.Packs["//local.cnquery.io/run/local-execution/querypacks/linux-mixed-queries"].ComputedFilters.Summarize()) +}