From b59025d5d40433b396b693f1ab170459bc2b9cee Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Sun, 10 Sep 2023 11:38:33 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=9F=A2=20fix=20resolver=20test=20checksum?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. double-check that elements exist with a require call (to avoid nil panics) 2. checksums changed because `asset{*}` is different for v9 (since fields were changed in this resource) Signed-off-by: Dominik Richter --- cli/reporter/render_advisory_policy.go | 4 ++-- cli/reporter/reporter.go | 2 +- policy/resolver_test.go | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cli/reporter/render_advisory_policy.go b/cli/reporter/render_advisory_policy.go index eec1f3c4..b80086ec 100644 --- a/cli/reporter/render_advisory_policy.go +++ b/cli/reporter/render_advisory_policy.go @@ -37,7 +37,7 @@ func renderAdvisoryPolicy(print *printer.Printer, policyObj *policy.Policy, repo score := report.Scores[policyObj.Mrn] schema := providers.DefaultRuntime().Schema() - vulnCheckpoint, err := defaultChecksum(vulnReport, schema) + vulnChecksum, err := defaultChecksum(vulnReport, schema) if err != nil { log.Debug().Err(err).Msg("could not determine vulnerability report checksum") b.WriteString(print.Error("no vulnerabilities for this provider")) @@ -45,7 +45,7 @@ func renderAdvisoryPolicy(print *printer.Printer, policyObj *policy.Policy, repo } results := report.Data - value, ok := results[vulnCheckpoint] + value, ok := results[vulnChecksum] if !ok { b.WriteString(print.Error("could not find advisory report" + NewLineCharacter + NewLineCharacter)) return b.String() diff --git a/cli/reporter/reporter.go b/cli/reporter/reporter.go index f16c0b33..99ec93d9 100644 --- a/cli/reporter/reporter.go +++ b/cli/reporter/reporter.go @@ -23,7 +23,7 @@ import ( type mqlCode string const ( - vulnReport mqlCode = "asset.VulnerabilityReport" + vulnReport mqlCode = "asset.vulnerabilityReport" kernelInstalled mqlCode = "kernel.installed" ) diff --git a/policy/resolver_test.go b/policy/resolver_test.go index 12975439..6dae1c3b 100644 --- a/policy/resolver_test.go +++ b/policy/resolver_test.go @@ -14,6 +14,7 @@ import ( "go.mondoo.com/cnquery/explorer" "go.mondoo.com/cnquery/mrn" "go.mondoo.com/cnquery/providers" + "go.mondoo.com/cnquery/providers-sdk/v1/testutils" "go.mondoo.com/cnspec/internal/datalakes/inmemory" "go.mondoo.com/cnspec/policy" ) @@ -31,7 +32,8 @@ func parseBundle(t *testing.T, data string) *policy.Bundle { } func initResolver(t *testing.T, assets []*testAsset, bundles []*policy.Bundle) *policy.LocalServices { - _, srv, err := inmemory.NewServices(providers.DefaultRuntime(), nil) + runtime := testutils.LinuxMock() + _, srv, err := inmemory.NewServices(runtime, nil) require.NoError(t, err) for i := range bundles { @@ -221,8 +223,11 @@ policies: require.NoError(t, err) require.NotNil(t, rp) require.Len(t, rp.CollectorJob.ReportingJobs, 4) - ignoreJob := rp.CollectorJob.ReportingJobs["jGWUFIvetOg="] - require.Equal(t, explorer.ScoringSystem_IGNORE_SCORE, ignoreJob.ChildJobs["lgJDqBZEz+M="].Scoring) + ignoreJob := rp.CollectorJob.ReportingJobs["KA46R+nvZXs="] + require.NotNil(t, ignoreJob) + childJob := ignoreJob.ChildJobs["0yAvYregRkA="] + require.NotNil(t, childJob) + require.Equal(t, explorer.ScoringSystem_IGNORE_SCORE, childJob.Scoring) }) }