Skip to content

Commit

Permalink
refactor(redhat-oval): return an error if the CPE is not found (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen authored Sep 2, 2024
1 parent 77e1fde commit 54beb6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/vulnsrc/redhat-oval/redhat-oval.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func (vs VulnSrc) Get(pkgName string, repositories, nvrs []string) ([]types.Advi
return nil, xerrors.Errorf("CPE convert error: %w", err)
}

if len(cpeIndices) == 0 {
return nil, xerrors.Errorf("unable to find CPE indices. See https://github.com/aquasecurity/trivy-db/issues/435 for details")
}

rawAdvisories, err := vs.dbc.ForEachAdvisory([]string{rootBucket}, pkgName)
if err != nil {
return nil, xerrors.Errorf("unable to iterate advisories: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/vulnsrc/redhat-oval/redhat-oval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ func TestVulnSrc_Get(t *testing.T) {
"testdata/fixtures/happy.yaml",
"testdata/fixtures/cpe.yaml",
},
want: []types.Advisory(nil),
wantErr: "unable to find CPE indices.",
},
{
name: "no advisory bucket",
Expand All @@ -936,7 +936,7 @@ func TestVulnSrc_Get(t *testing.T) {
repositories: []string{"rhel-8-for-x86_64-baseos-rpms"},
},
fixtures: []string{"testdata/fixtures/happy.yaml"},
want: []types.Advisory(nil),
wantErr: "unable to find CPE indices.",
},
{
name: "broken JSON",
Expand Down

0 comments on commit 54beb6c

Please sign in to comment.