diff --git a/syft/pkg/cataloger/swift/parse_package_resolved.go b/syft/pkg/cataloger/swift/parse_package_resolved.go index 71ccb13ea..cba7f54b3 100644 --- a/syft/pkg/cataloger/swift/parse_package_resolved.go +++ b/syft/pkg/cataloger/swift/parse_package_resolved.go @@ -121,7 +121,7 @@ func pinsForVersion(data map[string]interface{}, version float64) ([]packagePin, pin.State.Version, }) } - case 2: + case 2, 3: t := packageResolvedV2{} jsonString, err := json.Marshal(data) if err != nil { diff --git a/syft/pkg/cataloger/swift/parse_package_resolved_test.go b/syft/pkg/cataloger/swift/parse_package_resolved_test.go index 6cd77c2e5..499e705f6 100644 --- a/syft/pkg/cataloger/swift/parse_package_resolved_test.go +++ b/syft/pkg/cataloger/swift/parse_package_resolved_test.go @@ -80,6 +80,40 @@ func TestParsePackageResolved(t *testing.T) { 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) { // regression for https://github.com/anchore/syft/issues/2225 fixture := "test-fixtures/empty-packages.resolved" diff --git a/syft/pkg/cataloger/swift/test-fixtures/PackageV3.resolved b/syft/pkg/cataloger/swift/test-fixtures/PackageV3.resolved new file mode 100644 index 000000000..9b17d82d8 --- /dev/null +++ b/syft/pkg/cataloger/swift/test-fixtures/PackageV3.resolved @@ -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 +}