fix(purl): handle rust types (#5186)

Signed-off-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
Paternity Leave
2023-09-15 23:58:10 +03:00
committed by GitHub
parent 81240cf080
commit daae88287b
2 changed files with 27 additions and 4 deletions

View File

@@ -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:

View File

@@ -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,