Finalize Conan v2 support (#2587)

* Add support for conan lock v2 (#2461)

* conan lock 2.x requires field support

Signed-off-by: houdini91 <mdstrauss91@gmail.com>

* PR review, struct renaming

Signed-off-by: houdini91 <mdstrauss91@gmail.com>

---------

Signed-off-by: houdini91 <mdstrauss91@gmail.com>

* decompose conanlock parser + add tests

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: houdini91 <mdstrauss91@gmail.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: mikey strauss <mdstrauss91@gmail.com>
This commit is contained in:
Alex Goodman
2024-02-07 08:24:02 -05:00
committed by GitHub
co-authored by mikey strauss
parent 00d6269e3c
commit c61f59e7b7
12 changed files with 2509 additions and 37 deletions
+49 -8
View File
@@ -9,7 +9,7 @@ import (
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
)
func TestParseConanlock(t *testing.T) {
func TestParseConanLock(t *testing.T) {
fixture := "test-fixtures/conan.lock"
expected := []pkg.Package{
{
@@ -19,7 +19,7 @@ func TestParseConanlock(t *testing.T) {
Locations: file.NewLocationSet(file.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
Metadata: pkg.ConanLockEntry{
Metadata: pkg.ConanV1LockEntry{
Ref: "mfast/1.2.2@my_user/my_channel#c6f6387c9b99780f0ee05e25f99d0f39",
Options: pkg.KeyValues{
{Key: "fPIC", Value: "True"},
@@ -110,7 +110,7 @@ func TestParseConanlock(t *testing.T) {
Locations: file.NewLocationSet(file.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
Metadata: pkg.ConanLockEntry{
Metadata: pkg.ConanV1LockEntry{
Ref: "boost/1.75.0#a9c318f067216f900900e044e7af4ab1",
Options: pkg.KeyValues{
{Key: "addr2line_location", Value: "/usr/bin/addr2line"},
@@ -196,7 +196,7 @@ func TestParseConanlock(t *testing.T) {
Locations: file.NewLocationSet(file.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
Metadata: pkg.ConanLockEntry{
Metadata: pkg.ConanV1LockEntry{
Ref: "zlib/1.2.12#c67ce17f2e96b972d42393ce50a76a1a",
Options: pkg.KeyValues{
{
@@ -220,7 +220,7 @@ func TestParseConanlock(t *testing.T) {
Locations: file.NewLocationSet(file.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
Metadata: pkg.ConanLockEntry{
Metadata: pkg.ConanV1LockEntry{
Ref: "bzip2/1.0.8#62a8031289639043797cf53fa876d0ef",
Options: []pkg.KeyValue{
{
@@ -248,7 +248,7 @@ func TestParseConanlock(t *testing.T) {
Locations: file.NewLocationSet(file.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
Metadata: pkg.ConanLockEntry{
Metadata: pkg.ConanV1LockEntry{
Ref: "libbacktrace/cci.20210118#76e40b760e0bcd602d46db56b22820ab",
Options: []pkg.KeyValue{
{
@@ -272,7 +272,7 @@ func TestParseConanlock(t *testing.T) {
Locations: file.NewLocationSet(file.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
Metadata: pkg.ConanLockEntry{
Metadata: pkg.ConanV1LockEntry{
Ref: "tinyxml2/9.0.0#9f13a36ebfc222cd55fe531a0a8d94d1",
Options: []pkg.KeyValue{
{
@@ -330,5 +330,46 @@ func TestParseConanlock(t *testing.T) {
},
}
pkgtest.TestFileParser(t, fixture, parseConanlock, expected, expectedRelationships)
pkgtest.TestFileParser(t, fixture, parseConanLock, expected, expectedRelationships)
}
func TestParseConanLockV2(t *testing.T) {
fixture := "test-fixtures/conanlock-v2/conan.lock"
expected := []pkg.Package{
{
Name: "matrix",
Version: "1.1",
PURL: "pkg:conan/matrix@1.1",
Locations: file.NewLocationSet(file.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
Metadata: pkg.ConanV2LockEntry{
Ref: "matrix/1.1#905c3f0babc520684c84127378fefdd0%1675278901.7527816",
RecipeRevision: "905c3f0babc520684c84127378fefdd0",
TimeStamp: "1675278901.7527816",
},
},
{
Name: "sound32",
Version: "1.0",
PURL: "pkg:conan/sound32@1.0",
Locations: file.NewLocationSet(file.NewLocation(fixture)),
Language: pkg.CPP,
Type: pkg.ConanPkg,
Metadata: pkg.ConanV2LockEntry{
Ref: "sound32/1.0#83d4b7bf607b3b60a6546f8b58b5cdd7%1675278904.0791488",
RecipeRevision: "83d4b7bf607b3b60a6546f8b58b5cdd7",
TimeStamp: "1675278904.0791488",
},
},
}
// relationships require IDs to be set to be sorted similarly
for i := range expected {
expected[i].SetID()
}
var expectedRelationships []artifact.Relationship
pkgtest.TestFileParser(t, fixture, parseConanLock, expected, expectedRelationships)
}