feat: version 3 support for swift package manager of the resolved files (#3001)

Signed-off-by: Danielle Featherstone <dfeatherstone@fearless.tech>
This commit is contained in:
Danielle Featherstone 2024-07-01 14:27:37 -04:00 committed by GitHub
parent 4d48adfa3f
commit 5283c4687a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 1 deletions

View file

@ -121,7 +121,7 @@ func pinsForVersion(data map[string]interface{}, version float64) ([]packagePin,
pin.State.Version, pin.State.Version,
}) })
} }
case 2: case 2, 3:
t := packageResolvedV2{} t := packageResolvedV2{}
jsonString, err := json.Marshal(data) jsonString, err := json.Marshal(data)
if err != nil { if err != nil {

View file

@ -80,6 +80,40 @@ func TestParsePackageResolved(t *testing.T) {
pkgtest.TestFileParser(t, fixture, parsePackageResolved, expectedPkgs, expectedRelationships) pkgtest.TestFileParser(t, fixture, parsePackageResolved, expectedPkgs, expectedRelationships)
} }
func TestParsePackageResolvedV3(t *testing.T) {
fixture := "test-fixtures/PackageV3.resolved"
locations := file.NewLocationSet(file.NewLocation(fixture))
expectedPkgs := []pkg.Package{
{
Name: "swift-mmio",
Version: "",
PURL: "pkg:swift/github.com/apple/swift-mmio/swift-mmio",
Locations: locations,
Language: pkg.Swift,
Type: pkg.SwiftPkg,
Metadata: pkg.SwiftPackageManagerResolvedEntry{
Revision: "80c109b87511041338a4d8d88064088c8dfc079b",
},
},
{
Name: "swift-syntax",
Version: "509.1.1",
PURL: "pkg:swift/github.com/apple/swift-syntax.git/swift-syntax@509.1.1",
Locations: locations,
Language: pkg.Swift,
Type: pkg.SwiftPkg,
Metadata: pkg.SwiftPackageManagerResolvedEntry{
Revision: "64889f0c732f210a935a0ad7cda38f77f876262d",
},
},
}
// TODO: no relationships are under test yet
var expectedRelationships []artifact.Relationship
pkgtest.TestFileParser(t, fixture, parsePackageResolved, expectedPkgs, expectedRelationships)
}
func TestParsePackageResolved_empty(t *testing.T) { func TestParsePackageResolved_empty(t *testing.T) {
// regression for https://github.com/anchore/syft/issues/2225 // regression for https://github.com/anchore/syft/issues/2225
fixture := "test-fixtures/empty-packages.resolved" fixture := "test-fixtures/empty-packages.resolved"

View file

@ -0,0 +1,24 @@
{
"originHash" : "ea83017c944c7850b8f60207e6143eb17cb6b5e6b734b3fa08787a5d920dba7b",
"pins" : [
{
"identity" : "swift-mmio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-mmio",
"state" : {
"branch" : "swift-embedded-examples",
"revision" : "80c109b87511041338a4d8d88064088c8dfc079b"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
}
}
],
"version" : 3
}