github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/internal/cpegenerate/pe_test.go (about) 1 package cpegenerate 2 3 import ( 4 "testing" 5 6 "github.com/anchore/syft/syft/pkg" 7 ) 8 9 func TestGhostscriptPEGeneratesArtifexCPE(t *testing.T) { 10 // construct a BinaryPkg with PE metadata resembling Ghostscript 11 p := pkg.Package{ 12 Name: "GPL Ghostscript", 13 Version: "9.54.0", 14 Type: pkg.BinaryPkg, 15 Metadata: pkg.PEBinary{ 16 VersionResources: pkg.KeyValues{ 17 {Key: "CompanyName", Value: "Artifex Software, Inc."}, 18 {Key: "ProductName", Value: "GPL Ghostscript"}, 19 {Key: "FileDescription", Value: "Ghostscript Interpreter"}, 20 }, 21 }, 22 } 23 24 cpes := FromPackageAttributes(p) 25 if len(cpes) == 0 { 26 t.Fatalf("expected at least one CPE, got none") 27 } 28 29 found := false 30 for _, c := range cpes { 31 if c.Attributes.Vendor == "artifex" && c.Attributes.Product == "ghostscript" && c.Attributes.Version == p.Version { 32 found = true 33 break 34 } 35 } 36 if !found { 37 t.Fatalf("expected to find CPE with vendor 'artifex' and product 'ghostscript' for Ghostscript PE binary; got: %+v", cpes) 38 } 39 }