Skip to content

Commit

Permalink
chore: break assumption that syft cpe.CPE is wfn.Attributes (#1675)
Browse files Browse the repository at this point in the history
* chore: break assumption that syft cpe.CPE is wfn.Attributes

Previously, Syft's cpe.CPE type was an alias for wfn.Attributes. Fix a
couple places where Grype's compilation depended on that fact, since it
will stop being true in the next Syft release.

Signed-off-by: Will Murphy <[email protected]>

* chore: fix linter

Signed-off-by: Will Murphy <[email protected]>

---------

Signed-off-by: Will Murphy <[email protected]>
  • Loading branch information
willmurphyscode authored Jan 25, 2024
1 parent 636248d commit 73cb5f6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
7 changes: 5 additions & 2 deletions grype/cpe/cpe.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cpe

import (
"github.com/facebookincubator/nvdtools/wfn"

"github.com/anchore/grype/internal/log"
"github.com/anchore/syft/syft/cpe"
)
Expand All @@ -21,9 +23,10 @@ func NewSlice(cpeStrs ...string) ([]cpe.CPE, error) {

func MatchWithoutVersion(c cpe.CPE, candidates []cpe.CPE) []cpe.CPE {
matches := make([]cpe.CPE, 0)
a := wfn.Attributes(c) // nolint:unconvert // TODO: remove nolint when syft upgrade in grype
for _, candidate := range candidates {
canCopy := candidate
if c.MatchWithoutVersion(&canCopy) {
canCopy := wfn.Attributes(candidate) // nolint:unconvert // TODO: remove nolint when syft upgrade in grype
if a.MatchWithoutVersion(&canCopy) {
matches = append(matches, candidate)
}
}
Expand Down
3 changes: 1 addition & 2 deletions grype/pkg/purl_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"strings"

"github.com/facebookincubator/nvdtools/wfn"
"github.com/mitchellh/go-homedir"

"github.com/anchore/packageurl-go"
Expand Down Expand Up @@ -53,7 +52,7 @@ func decodePurlFile(reader io.Reader) ([]Package, error) {
return nil, fmt.Errorf("unable to decode purl %s: %w", rawLine, err)
}

cpes := []wfn.Attributes{}
cpes := []cpe.CPE{}
epoch := "0"
for _, qualifier := range purl.Qualifiers {
if qualifier.Key == cpesQualifierKey {
Expand Down
12 changes: 3 additions & 9 deletions test/integration/match_by_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"

"github.com/facebookincubator/nvdtools/wfn"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
Expand All @@ -23,6 +22,7 @@ import (
"github.com/anchore/stereoscope/pkg/imagetest"
"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/cataloging/pkgcataloging"
"github.com/anchore/syft/syft/cpe"
"github.com/anchore/syft/syft/linux"
syftPkg "github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/source"
Expand Down Expand Up @@ -142,7 +142,6 @@ func addPythonMatches(t *testing.T, theSource source.Source, catalog *syftPkg.Co
require.NoError(t, err)

theResult.Add(match.Match{

Vulnerability: *vulnObj,
Package: thePkg,
Details: []match.Detail{
Expand Down Expand Up @@ -183,7 +182,6 @@ func addDotnetMatches(t *testing.T, theSource source.Source, catalog *syftPkg.Co
require.NoError(t, err)

theResult.Add(match.Match{

Vulnerability: *vulnObj,
Package: thePkg,
Details: []match.Detail{
Expand Down Expand Up @@ -220,7 +218,6 @@ func addRubyMatches(t *testing.T, theSource source.Source, catalog *syftPkg.Coll
require.NoError(t, err)

theResult.Add(match.Match{

Vulnerability: *vulnObj,
Package: thePkg,
Details: []match.Detail{
Expand Down Expand Up @@ -363,7 +360,6 @@ func addDpkgMatches(t *testing.T, theSource source.Source, catalog *syftPkg.Coll
require.NoError(t, err)

theResult.Add(match.Match{

Vulnerability: *vulnObj,
Package: thePkg,
Details: []match.Detail{
Expand Down Expand Up @@ -442,7 +438,6 @@ func addRhelMatches(t *testing.T, theSource source.Source, catalog *syftPkg.Coll
require.NoError(t, err)

theResult.Add(match.Match{

Vulnerability: *vulnObj,
Package: thePkg,
Details: []match.Detail{
Expand Down Expand Up @@ -764,7 +759,6 @@ func TestMatchByImage(t *testing.T) {

t.Log(cmp.Diff(defs, obs))
}

}

// testIgnoredMatches returns an list of ignored matches to test the vex
Expand All @@ -783,7 +777,7 @@ func testIgnoredMatches() []match.IgnoredMatch {
Version: "0.9.9",
Licenses: []string{"GPL-2.0-or-later"},
Type: "apk",
CPEs: []wfn.Attributes{
CPEs: []cpe.CPE{
{
Part: "a",
Vendor: "libvncserver",
Expand Down Expand Up @@ -858,7 +852,7 @@ func vexMatches(t *testing.T, ignoredMatches []match.IgnoredMatch, vexStatus vex

func assertMatches(t *testing.T, expected, actual []match.Match) {
t.Helper()
var opts = []cmp.Option{
opts := []cmp.Option{
cmpopts.IgnoreFields(vulnerability.Vulnerability{}, "Constraint"),
cmpopts.IgnoreFields(pkg.Package{}, "Locations"),
cmpopts.SortSlices(func(a, b match.Match) bool {
Expand Down

0 comments on commit 73cb5f6

Please sign in to comment.