github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/cpp/parse_conanlock_test.go (about)

     1  package cpp
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/anchore/syft/syft/artifact"
     7  	"github.com/anchore/syft/syft/file"
     8  	"github.com/anchore/syft/syft/pkg"
     9  	"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
    10  )
    11  
    12  func TestParseConanLock(t *testing.T) {
    13  	fixture := "test-fixtures/conan.lock"
    14  	expected := []pkg.Package{
    15  		{
    16  			Name:      "mfast",
    17  			Version:   "1.2.2",
    18  			PURL:      "pkg:conan/my_user/mfast@1.2.2?channel=my_channel",
    19  			Locations: file.NewLocationSet(file.NewLocation(fixture)),
    20  			Language:  pkg.CPP,
    21  			Type:      pkg.ConanPkg,
    22  			Metadata: pkg.ConanV1LockEntry{
    23  				Ref: "mfast/1.2.2@my_user/my_channel#c6f6387c9b99780f0ee05e25f99d0f39",
    24  				Options: pkg.KeyValues{
    25  					{Key: "fPIC", Value: "True"},
    26  					{Key: "shared", Value: "False"},
    27  					{Key: "with_sqlite3", Value: "False"},
    28  					{Key: "boost:addr2line_location", Value: "/usr/bin/addr2line"},
    29  					{Key: "boost:asio_no_deprecated", Value: "False"},
    30  					{Key: "boost:buildid", Value: "None"},
    31  					{Key: "boost:bzip2", Value: "True"},
    32  					{Key: "boost:debug_level", Value: "0"},
    33  					{Key: "boost:diagnostic_definitions", Value: "False"},
    34  					{Key: "boost:error_code_header_only", Value: "False"},
    35  					{Key: "boost:extra_b2_flags", Value: "None"},
    36  					{Key: "boost:fPIC", Value: "True"},
    37  					{Key: "boost:filesystem_no_deprecated", Value: "False"},
    38  					{Key: "boost:header_only", Value: "False"},
    39  					{Key: "boost:i18n_backend", Value: "deprecated"},
    40  					{Key: "boost:i18n_backend_iconv", Value: "libc"},
    41  					{Key: "boost:i18n_backend_icu", Value: "False"},
    42  					{Key: "boost:layout", Value: "system"},
    43  					{Key: "boost:lzma", Value: "False"},
    44  					{Key: "boost:magic_autolink", Value: "False"},
    45  					{Key: "boost:multithreading", Value: "True"},
    46  					{Key: "boost:namespace", Value: "boost"},
    47  					{Key: "boost:namespace_alias", Value: "False"},
    48  					{Key: "boost:numa", Value: "True"},
    49  					{Key: "boost:pch", Value: "True"},
    50  					{Key: "boost:python_executable", Value: "None"},
    51  					{Key: "boost:python_version", Value: "None"},
    52  					{Key: "boost:segmented_stacks", Value: "False"},
    53  					{Key: "boost:shared", Value: "False"},
    54  					{Key: "boost:system_no_deprecated", Value: "False"},
    55  					{Key: "boost:system_use_utf8", Value: "False"},
    56  					{Key: "boost:visibility", Value: "hidden"},
    57  					{Key: "boost:with_stacktrace_backtrace", Value: "True"},
    58  					{Key: "boost:without_atomic", Value: "False"},
    59  					{Key: "boost:without_chrono", Value: "False"},
    60  					{Key: "boost:without_container", Value: "False"},
    61  					{Key: "boost:without_context", Value: "False"},
    62  					{Key: "boost:without_contract", Value: "False"},
    63  					{Key: "boost:without_coroutine", Value: "False"},
    64  					{Key: "boost:without_date_time", Value: "False"},
    65  					{Key: "boost:without_exception", Value: "False"},
    66  					{Key: "boost:without_fiber", Value: "False"},
    67  					{Key: "boost:without_filesystem", Value: "False"},
    68  					{Key: "boost:without_graph", Value: "False"},
    69  					{Key: "boost:without_graph_parallel", Value: "True"},
    70  					{Key: "boost:without_iostreams", Value: "False"},
    71  					{Key: "boost:without_json", Value: "False"},
    72  					{Key: "boost:without_locale", Value: "False"},
    73  					{Key: "boost:without_log", Value: "False"},
    74  					{Key: "boost:without_math", Value: "False"},
    75  					{Key: "boost:without_mpi", Value: "True"},
    76  					{Key: "boost:without_nowide", Value: "False"},
    77  					{Key: "boost:without_program_options", Value: "False"},
    78  					{Key: "boost:without_python", Value: "True"},
    79  					{Key: "boost:without_random", Value: "False"},
    80  					{Key: "boost:without_regex", Value: "False"},
    81  					{Key: "boost:without_serialization", Value: "False"},
    82  					{Key: "boost:without_stacktrace", Value: "False"},
    83  					{Key: "boost:without_system", Value: "False"},
    84  					{Key: "boost:without_test", Value: "False"},
    85  					{Key: "boost:without_thread", Value: "False"},
    86  					{Key: "boost:without_timer", Value: "False"},
    87  					{Key: "boost:without_type_erasure", Value: "False"},
    88  					{Key: "boost:without_wave", Value: "False"},
    89  					{Key: "boost:zlib", Value: "True"},
    90  					{Key: "boost:zstd", Value: "False"},
    91  					{Key: "bzip2:build_executable", Value: "True"},
    92  					{Key: "bzip2:fPIC", Value: "True"},
    93  					{Key: "bzip2:shared", Value: "False"},
    94  					{Key: "libbacktrace:fPIC", Value: "True"},
    95  					{Key: "libbacktrace:shared", Value: "False"},
    96  					{Key: "tinyxml2:fPIC", Value: "True"},
    97  					{Key: "tinyxml2:shared", Value: "False"},
    98  					{Key: "zlib:fPIC", Value: "True"},
    99  					{Key: "zlib:shared", Value: "False"},
   100  				},
   101  				Context:   "host",
   102  				PackageID: "9d1f076b471417647c2022a78d5e2c1f834289ac",
   103  				Prev:      "0ca9799450422cc55a92ccc6ffd57fba",
   104  			},
   105  		},
   106  		{
   107  			Name:      "boost",
   108  			Version:   "1.75.0",
   109  			PURL:      "pkg:conan/boost@1.75.0",
   110  			Locations: file.NewLocationSet(file.NewLocation(fixture)),
   111  			Language:  pkg.CPP,
   112  			Type:      pkg.ConanPkg,
   113  			Metadata: pkg.ConanV1LockEntry{
   114  				Ref: "boost/1.75.0#a9c318f067216f900900e044e7af4ab1",
   115  				Options: pkg.KeyValues{
   116  					{Key: "addr2line_location", Value: "/usr/bin/addr2line"},
   117  					{Key: "asio_no_deprecated", Value: "False"},
   118  					{Key: "buildid", Value: "None"},
   119  					{Key: "bzip2", Value: "True"},
   120  					{Key: "debug_level", Value: "0"},
   121  					{Key: "diagnostic_definitions", Value: "False"},
   122  					{Key: "error_code_header_only", Value: "False"},
   123  					{Key: "extra_b2_flags", Value: "None"},
   124  					{Key: "fPIC", Value: "True"},
   125  					{Key: "filesystem_no_deprecated", Value: "False"},
   126  					{Key: "header_only", Value: "False"},
   127  					{Key: "i18n_backend", Value: "deprecated"},
   128  					{Key: "i18n_backend_iconv", Value: "libc"},
   129  					{Key: "i18n_backend_icu", Value: "False"},
   130  					{Key: "layout", Value: "system"},
   131  					{Key: "lzma", Value: "False"},
   132  					{Key: "magic_autolink", Value: "False"},
   133  					{Key: "multithreading", Value: "True"},
   134  					{Key: "namespace", Value: "boost"},
   135  					{Key: "namespace_alias", Value: "False"},
   136  					{Key: "numa", Value: "True"},
   137  					{Key: "pch", Value: "True"},
   138  					{Key: "python_executable", Value: "None"},
   139  					{Key: "python_version", Value: "None"},
   140  					{Key: "segmented_stacks", Value: "False"},
   141  					{Key: "shared", Value: "False"},
   142  					{Key: "system_no_deprecated", Value: "False"},
   143  					{Key: "system_use_utf8", Value: "False"},
   144  					{Key: "visibility", Value: "hidden"},
   145  					{Key: "with_stacktrace_backtrace", Value: "True"},
   146  					{Key: "without_atomic", Value: "False"},
   147  					{Key: "without_chrono", Value: "False"},
   148  					{Key: "without_container", Value: "False"},
   149  					{Key: "without_context", Value: "False"},
   150  					{Key: "without_contract", Value: "False"},
   151  					{Key: "without_coroutine", Value: "False"},
   152  					{Key: "without_date_time", Value: "False"},
   153  					{Key: "without_exception", Value: "False"},
   154  					{Key: "without_fiber", Value: "False"},
   155  					{Key: "without_filesystem", Value: "False"},
   156  					{Key: "without_graph", Value: "False"},
   157  					{Key: "without_graph_parallel", Value: "True"},
   158  					{Key: "without_iostreams", Value: "False"},
   159  					{Key: "without_json", Value: "False"},
   160  					{Key: "without_locale", Value: "False"},
   161  					{Key: "without_log", Value: "False"},
   162  					{Key: "without_math", Value: "False"},
   163  					{Key: "without_mpi", Value: "True"},
   164  					{Key: "without_nowide", Value: "False"},
   165  					{Key: "without_program_options", Value: "False"},
   166  					{Key: "without_python", Value: "True"},
   167  					{Key: "without_random", Value: "False"},
   168  					{Key: "without_regex", Value: "False"},
   169  					{Key: "without_serialization", Value: "False"},
   170  					{Key: "without_stacktrace", Value: "False"},
   171  					{Key: "without_system", Value: "False"},
   172  					{Key: "without_test", Value: "False"},
   173  					{Key: "without_thread", Value: "False"},
   174  					{Key: "without_timer", Value: "False"},
   175  					{Key: "without_type_erasure", Value: "False"},
   176  					{Key: "without_wave", Value: "False"},
   177  					{Key: "zlib", Value: "True"},
   178  					{Key: "zstd", Value: "False"},
   179  					{Key: "bzip2:build_executable", Value: "True"},
   180  					{Key: "bzip2:fPIC", Value: "True"},
   181  					{Key: "bzip2:shared", Value: "False"},
   182  					{Key: "libbacktrace:fPIC", Value: "True"},
   183  					{Key: "libbacktrace:shared", Value: "False"},
   184  					{Key: "zlib:fPIC", Value: "True"},
   185  					{Key: "zlib:shared", Value: "False"},
   186  				},
   187  				Context:   "host",
   188  				PackageID: "dc8aedd23a0f0a773a5fcdcfe1ae3e89c4205978",
   189  				Prev:      "b9d7912e6131dfa453c725593b36c808",
   190  			},
   191  		},
   192  		{
   193  			Name:      "zlib",
   194  			Version:   "1.2.12",
   195  			PURL:      "pkg:conan/zlib@1.2.12",
   196  			Locations: file.NewLocationSet(file.NewLocation(fixture)),
   197  			Language:  pkg.CPP,
   198  			Type:      pkg.ConanPkg,
   199  			Metadata: pkg.ConanV1LockEntry{
   200  				Ref: "zlib/1.2.12#c67ce17f2e96b972d42393ce50a76a1a",
   201  				Options: pkg.KeyValues{
   202  					{
   203  						Key:   "fPIC",
   204  						Value: "True",
   205  					},
   206  					{
   207  						Key:   "shared",
   208  						Value: "False",
   209  					},
   210  				},
   211  				Context:   "host",
   212  				PackageID: "dfbe50feef7f3c6223a476cd5aeadb687084a646",
   213  				Prev:      "7cd359d44f89ab08e33b5db75605002c",
   214  			},
   215  		},
   216  		{
   217  			Name:      "bzip2",
   218  			Version:   "1.0.8",
   219  			PURL:      "pkg:conan/bzip2@1.0.8",
   220  			Locations: file.NewLocationSet(file.NewLocation(fixture)),
   221  			Language:  pkg.CPP,
   222  			Type:      pkg.ConanPkg,
   223  			Metadata: pkg.ConanV1LockEntry{
   224  				Ref: "bzip2/1.0.8#62a8031289639043797cf53fa876d0ef",
   225  				Options: []pkg.KeyValue{
   226  					{
   227  						Key:   "build_executable",
   228  						Value: "True",
   229  					},
   230  					{
   231  						Key:   "fPIC",
   232  						Value: "True",
   233  					},
   234  					{
   235  						Key:   "shared",
   236  						Value: "False",
   237  					},
   238  				},
   239  				Context:   "host",
   240  				PackageID: "c32092bf4d4bb47cf962af898e02823f499b017e",
   241  				Prev:      "b746948bc999d6f17f52a1f76e729e80",
   242  			},
   243  		},
   244  		{
   245  			Name:      "libbacktrace",
   246  			Version:   "cci.20210118",
   247  			PURL:      "pkg:conan/libbacktrace@cci.20210118",
   248  			Locations: file.NewLocationSet(file.NewLocation(fixture)),
   249  			Language:  pkg.CPP,
   250  			Type:      pkg.ConanPkg,
   251  			Metadata: pkg.ConanV1LockEntry{
   252  				Ref: "libbacktrace/cci.20210118#76e40b760e0bcd602d46db56b22820ab",
   253  				Options: []pkg.KeyValue{
   254  					{
   255  						Key:   "fPIC",
   256  						Value: "True",
   257  					},
   258  					{
   259  						Key:   "shared",
   260  						Value: "False",
   261  					},
   262  				},
   263  				Context:   "host",
   264  				PackageID: "dfbe50feef7f3c6223a476cd5aeadb687084a646",
   265  				Prev:      "98a976f017e894c27e9a158b807ec0c7",
   266  			},
   267  		},
   268  		{
   269  			Name:      "tinyxml2",
   270  			Version:   "9.0.0",
   271  			PURL:      "pkg:conan/tinyxml2@9.0.0",
   272  			Locations: file.NewLocationSet(file.NewLocation(fixture)),
   273  			Language:  pkg.CPP,
   274  			Type:      pkg.ConanPkg,
   275  			Metadata: pkg.ConanV1LockEntry{
   276  				Ref: "tinyxml2/9.0.0#9f13a36ebfc222cd55fe531a0a8d94d1",
   277  				Options: []pkg.KeyValue{
   278  					{
   279  						Key:   "fPIC",
   280  						Value: "True",
   281  					},
   282  					{
   283  						Key:   "shared",
   284  						Value: "False",
   285  					},
   286  				},
   287  				Context: "host",
   288  				// intentionally remove to test missing PackageID and Prev
   289  				// PackageID: "6557f18ca99c0b6a233f43db00e30efaa525e27e",
   290  				// Prev:      "548bb273d2980991baa519453d68e5cd",
   291  			},
   292  		},
   293  	}
   294  
   295  	// relationships require IDs to be set to be sorted similarly
   296  	for i := range expected {
   297  		expected[i].SetID()
   298  	}
   299  
   300  	var expectedRelationships = []artifact.Relationship{
   301  		{
   302  			From: expected[1], // boost
   303  			To:   expected[0], // mfast
   304  			Type: artifact.DependencyOfRelationship,
   305  			Data: nil,
   306  		},
   307  		{
   308  			From: expected[5], // tinyxml2
   309  			To:   expected[0], // mfast
   310  			Type: artifact.DependencyOfRelationship,
   311  			Data: nil,
   312  		},
   313  		{
   314  			From: expected[2], // zlib
   315  			To:   expected[1], // boost
   316  			Type: artifact.DependencyOfRelationship,
   317  			Data: nil,
   318  		},
   319  		{
   320  			From: expected[3], // bzip2
   321  			To:   expected[1], // boost
   322  			Type: artifact.DependencyOfRelationship,
   323  			Data: nil,
   324  		},
   325  		{
   326  			From: expected[4], // libbacktrace
   327  			To:   expected[1], // boost
   328  			Type: artifact.DependencyOfRelationship,
   329  			Data: nil,
   330  		},
   331  	}
   332  
   333  	pkgtest.TestFileParser(t, fixture, parseConanLock, expected, expectedRelationships)
   334  }
   335  
   336  func TestParseConanLockV2(t *testing.T) {
   337  	fixture := "test-fixtures/conanlock-v2/conan.lock"
   338  	expected := []pkg.Package{
   339  		{
   340  			Name:      "matrix",
   341  			Version:   "1.1",
   342  			PURL:      "pkg:conan/matrix@1.1",
   343  			Locations: file.NewLocationSet(file.NewLocation(fixture)),
   344  			Language:  pkg.CPP,
   345  			Type:      pkg.ConanPkg,
   346  			Metadata: pkg.ConanV2LockEntry{
   347  				Ref:            "matrix/1.1#905c3f0babc520684c84127378fefdd0%1675278901.7527816",
   348  				RecipeRevision: "905c3f0babc520684c84127378fefdd0",
   349  				TimeStamp:      "1675278901.7527816",
   350  			},
   351  		},
   352  		{
   353  			Name:      "sound32",
   354  			Version:   "1.0",
   355  			PURL:      "pkg:conan/sound32@1.0",
   356  			Locations: file.NewLocationSet(file.NewLocation(fixture)),
   357  			Language:  pkg.CPP,
   358  			Type:      pkg.ConanPkg,
   359  			Metadata: pkg.ConanV2LockEntry{
   360  				Ref:            "sound32/1.0#83d4b7bf607b3b60a6546f8b58b5cdd7%1675278904.0791488",
   361  				RecipeRevision: "83d4b7bf607b3b60a6546f8b58b5cdd7",
   362  				TimeStamp:      "1675278904.0791488",
   363  			},
   364  		},
   365  	}
   366  
   367  	// relationships require IDs to be set to be sorted similarly
   368  	for i := range expected {
   369  		expected[i].SetID()
   370  	}
   371  
   372  	var expectedRelationships []artifact.Relationship
   373  
   374  	pkgtest.TestFileParser(t, fixture, parseConanLock, expected, expectedRelationships)
   375  }
   376  
   377  func Test_corruptConanlock(t *testing.T) {
   378  	pkgtest.NewCatalogTester().
   379  		FromFile(t, "test-fixtures/corrupt/conan.lock").
   380  		WithError().
   381  		TestParser(t, parseConanLock)
   382  }