diff --git a/policy/resolver_test.go b/policy/resolver_test.go index d8d19d7f..ec551fe8 100644 --- a/policy/resolver_test.go +++ b/policy/resolver_test.go @@ -264,6 +264,75 @@ policies: } } +func TestResolve_IgnoredQuery(t *testing.T) { + b := parseBundle(t, ` +owner_mrn: //test.sth +policies: +- uid: policy-1 + owner_mrn: //test.sth + groups: + - type: chapter + filters: "true" + checks: + - uid: check1 + mql: 1 == 1 +- mrn: asset1 + owner_mrn: //test.sth + groups: + - policies: + - uid: policy-1 + - checks: + - uid: check1 + action: 4 +`) + + _, srv, err := inmemory.NewServices(providers.DefaultRuntime(), nil) + require.NoError(t, err) + + ctx := context.Background() + _, err = srv.SetBundle(ctx, b) + require.NoError(t, err) + + bundleMap, err := b.Compile(context.Background(), schema, nil) + require.NoError(t, err) + + rp, err := srv.Resolve(context.Background(), &policy.ResolveReq{ + PolicyMrn: "asset1", + AssetFilters: []*explorer.Mquery{{Mql: "true"}}, + }) + + require.NoError(t, err) + require.NotNil(t, rp) + require.Len(t, rp.CollectorJob.ReportingJobs, 3) + + mrnToQueryId := map[string]string{} + for _, q := range bundleMap.Queries { + mrnToQueryId[q.Mrn] = q.CodeId + } + + rjTester := frameworkReportingJobTester{ + t: t, + queryIdToReportingJob: map[string]*policy.ReportingJob{}, + rjIdToReportingJob: rp.CollectorJob.ReportingJobs, + rjIdToDatapointJob: rp.CollectorJob.Datapoints, + dataQueriesMrns: map[string]struct{}{}, + } + + for _, rj := range rjTester.rjIdToReportingJob { + _, ok := rjTester.queryIdToReportingJob[rj.QrId] + require.False(t, ok) + rjTester.queryIdToReportingJob[rj.QrId] = rj + } + + queryRj := rjTester.queryIdToReportingJob[mrnToQueryId[queryMrn("check1")]] + // we ensure that even though ignored, theres an RJ for the query + require.NotNil(t, queryRj) + parent := queryRj.Notify[0] + parentRj := rjTester.rjIdToReportingJob[parent] + require.NotNil(t, parentRj) + require.Equal(t, explorer.ScoringSystem_IGNORE_SCORE, parentRj.ChildJobs[queryRj.Uuid].Scoring) +} + func TestResolve_ExpiredGroups(t *testing.T) { b := parseBundle(t, ` owner_mrn: //test.sth