From daae88287b033e583fec1496a0661970166917d4 Mon Sep 17 00:00:00 2001 From: Paternity Leave Date: Fri, 15 Sep 2023 23:58:10 +0300 Subject: [PATCH] fix(purl): handle rust types (#5186) Signed-off-by: knqyf263 --- pkg/purl/purl.go | 2 ++ pkg/purl/purl_test.go | 29 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/purl/purl.go b/pkg/purl/purl.go index 2ab2e4e49c5c..d54d2dffd795 100644 --- a/pkg/purl/purl.go +++ b/pkg/purl/purl.go @@ -375,6 +375,8 @@ func purlType(t string) string { return packageurl.TypeConan case ftypes.Pub: return TypeDart // TODO: replace with packageurl.TypeDart once they add it. + case ftypes.RustBinary, ftypes.Cargo: + return packageurl.TypeCargo case os.Alpine: return TypeAPK case os.Debian, os.Ubuntu: diff --git a/pkg/purl/purl_test.go b/pkg/purl/purl_test.go index defd24a309e8..4c3688237d7a 100644 --- a/pkg/purl/purl_test.go +++ b/pkg/purl/purl_test.go @@ -185,10 +185,15 @@ func TestNewPackageURL(t *testing.T) { name: "hex package", typ: ftypes.Hex, pkg: ftypes.Package{ - ID: "bunt@0.2.0", - Name: "bunt", - Version: "0.2.0", - Locations: []ftypes.Location{{StartLine: 2, EndLine: 2}}, + ID: "bunt@0.2.0", + Name: "bunt", + Version: "0.2.0", + Locations: []ftypes.Location{ + { + StartLine: 2, + EndLine: 2, + }, + }, }, want: purl.PackageURL{ PackageURL: packageurl.PackageURL{ @@ -247,6 +252,22 @@ func TestNewPackageURL(t *testing.T) { }, }, }, + { + name: "rust binary", + typ: ftypes.RustBinary, + pkg: ftypes.Package{ + ID: "abomonation@0.7.3", + Name: "abomonation", + Version: "0.7.3", + }, + want: purl.PackageURL{ + PackageURL: packageurl.PackageURL{ + Type: packageurl.TypeCargo, + Name: "abomonation", + Version: "0.7.3", + }, + }, + }, { name: "os package", typ: os.RedHat,