Skip to content

Commit

Permalink
🟢 fix resolver test checksums
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
arlimus committed Sep 10, 2023
1 parent 72c78d1 commit b59025d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cli/reporter/render_advisory_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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"))
return b.String()
}

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()
Expand Down
2 changes: 1 addition & 1 deletion cli/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
type mqlCode string

const (
vulnReport mqlCode = "asset.VulnerabilityReport"
vulnReport mqlCode = "asset.vulnerabilityReport"
kernelInstalled mqlCode = "kernel.installed"
)

Expand Down
11 changes: 8 additions & 3 deletions policy/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
})
}

Expand Down

0 comments on commit b59025d

Please sign in to comment.