github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/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/lineaje-labs/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.ConanLockEntry{ 23 Ref: "mfast/1.2.2@my_user/my_channel#c6f6387c9b99780f0ee05e25f99d0f39", 24 Options: map[string]string{ 25 "fPIC": "True", 26 "shared": "False", 27 "with_sqlite3": "False", 28 "boost:addr2line_location": "/usr/bin/addr2line", 29 "boost:asio_no_deprecated": "False", 30 "boost:buildid": "None", 31 "boost:bzip2": "True", 32 "boost:debug_level": "0", 33 "boost:diagnostic_definitions": "False", 34 "boost:error_code_header_only": "False", 35 "boost:extra_b2_flags": "None", 36 "boost:fPIC": "True", 37 "boost:filesystem_no_deprecated": "False", 38 "boost:header_only": "False", 39 "boost:i18n_backend": "deprecated", 40 "boost:i18n_backend_iconv": "libc", 41 "boost:i18n_backend_icu": "False", 42 "boost:layout": "system", 43 "boost:lzma": "False", 44 "boost:magic_autolink": "False", 45 "boost:multithreading": "True", 46 "boost:namespace": "boost", 47 "boost:namespace_alias": "False", 48 "boost:numa": "True", 49 "boost:pch": "True", 50 "boost:python_executable": "None", 51 "boost:python_version": "None", 52 "boost:segmented_stacks": "False", 53 "boost:shared": "False", 54 "boost:system_no_deprecated": "False", 55 "boost:system_use_utf8": "False", 56 "boost:visibility": "hidden", 57 "boost:with_stacktrace_backtrace": "True", 58 "boost:without_atomic": "False", 59 "boost:without_chrono": "False", 60 "boost:without_container": "False", 61 "boost:without_context": "False", 62 "boost:without_contract": "False", 63 "boost:without_coroutine": "False", 64 "boost:without_date_time": "False", 65 "boost:without_exception": "False", 66 "boost:without_fiber": "False", 67 "boost:without_filesystem": "False", 68 "boost:without_graph": "False", 69 "boost:without_graph_parallel": "True", 70 "boost:without_iostreams": "False", 71 "boost:without_json": "False", 72 "boost:without_locale": "False", 73 "boost:without_log": "False", 74 "boost:without_math": "False", 75 "boost:without_mpi": "True", 76 "boost:without_nowide": "False", 77 "boost:without_program_options": "False", 78 "boost:without_python": "True", 79 "boost:without_random": "False", 80 "boost:without_regex": "False", 81 "boost:without_serialization": "False", 82 "boost:without_stacktrace": "False", 83 "boost:without_system": "False", 84 "boost:without_test": "False", 85 "boost:without_thread": "False", 86 "boost:without_timer": "False", 87 "boost:without_type_erasure": "False", 88 "boost:without_wave": "False", 89 "boost:zlib": "True", 90 "boost:zstd": "False", 91 "bzip2:build_executable": "True", 92 "bzip2:fPIC": "True", 93 "bzip2:shared": "False", 94 "libbacktrace:fPIC": "True", 95 "libbacktrace:shared": "False", 96 "tinyxml2:fPIC": "True", 97 "tinyxml2:shared": "False", 98 "zlib:fPIC": "True", 99 "zlib:shared": "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.ConanLockEntry{ 114 Ref: "boost/1.75.0#a9c318f067216f900900e044e7af4ab1", 115 Options: map[string]string{ 116 "addr2line_location": "/usr/bin/addr2line", 117 "asio_no_deprecated": "False", 118 "buildid": "None", 119 "bzip2": "True", 120 "debug_level": "0", 121 "diagnostic_definitions": "False", 122 "error_code_header_only": "False", 123 "extra_b2_flags": "None", 124 "fPIC": "True", 125 "filesystem_no_deprecated": "False", 126 "header_only": "False", 127 "i18n_backend": "deprecated", 128 "i18n_backend_iconv": "libc", 129 "i18n_backend_icu": "False", 130 "layout": "system", 131 "lzma": "False", 132 "magic_autolink": "False", 133 "multithreading": "True", 134 "namespace": "boost", 135 "namespace_alias": "False", 136 "numa": "True", 137 "pch": "True", 138 "python_executable": "None", 139 "python_version": "None", 140 "segmented_stacks": "False", 141 "shared": "False", 142 "system_no_deprecated": "False", 143 "system_use_utf8": "False", 144 "visibility": "hidden", 145 "with_stacktrace_backtrace": "True", 146 "without_atomic": "False", 147 "without_chrono": "False", 148 "without_container": "False", 149 "without_context": "False", 150 "without_contract": "False", 151 "without_coroutine": "False", 152 "without_date_time": "False", 153 "without_exception": "False", 154 "without_fiber": "False", 155 "without_filesystem": "False", 156 "without_graph": "False", 157 "without_graph_parallel": "True", 158 "without_iostreams": "False", 159 "without_json": "False", 160 "without_locale": "False", 161 "without_log": "False", 162 "without_math": "False", 163 "without_mpi": "True", 164 "without_nowide": "False", 165 "without_program_options": "False", 166 "without_python": "True", 167 "without_random": "False", 168 "without_regex": "False", 169 "without_serialization": "False", 170 "without_stacktrace": "False", 171 "without_system": "False", 172 "without_test": "False", 173 "without_thread": "False", 174 "without_timer": "False", 175 "without_type_erasure": "False", 176 "without_wave": "False", 177 "zlib": "True", 178 "zstd": "False", 179 "bzip2:build_executable": "True", 180 "bzip2:fPIC": "True", 181 "bzip2:shared": "False", 182 "libbacktrace:fPIC": "True", 183 "libbacktrace:shared": "False", 184 "zlib:fPIC": "True", 185 "zlib:shared": "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.ConanLockEntry{ 200 Ref: "zlib/1.2.12#c67ce17f2e96b972d42393ce50a76a1a", 201 Options: map[string]string{ 202 "fPIC": "True", 203 "shared": "False", 204 }, 205 Context: "host", 206 PackageID: "dfbe50feef7f3c6223a476cd5aeadb687084a646", 207 Prev: "7cd359d44f89ab08e33b5db75605002c", 208 }, 209 }, 210 { 211 Name: "bzip2", 212 Version: "1.0.8", 213 PURL: "pkg:conan/bzip2@1.0.8", 214 Locations: file.NewLocationSet(file.NewLocation(fixture)), 215 Language: pkg.CPP, 216 Type: pkg.ConanPkg, 217 Metadata: pkg.ConanLockEntry{ 218 Ref: "bzip2/1.0.8#62a8031289639043797cf53fa876d0ef", 219 Options: map[string]string{ 220 "build_executable": "True", 221 "fPIC": "True", 222 "shared": "False", 223 }, 224 Context: "host", 225 PackageID: "c32092bf4d4bb47cf962af898e02823f499b017e", 226 Prev: "b746948bc999d6f17f52a1f76e729e80", 227 }, 228 }, 229 { 230 Name: "libbacktrace", 231 Version: "cci.20210118", 232 PURL: "pkg:conan/libbacktrace@cci.20210118", 233 Locations: file.NewLocationSet(file.NewLocation(fixture)), 234 Language: pkg.CPP, 235 Type: pkg.ConanPkg, 236 Metadata: pkg.ConanLockEntry{ 237 Ref: "libbacktrace/cci.20210118#76e40b760e0bcd602d46db56b22820ab", 238 Options: map[string]string{ 239 "fPIC": "True", 240 "shared": "False", 241 }, 242 Context: "host", 243 PackageID: "dfbe50feef7f3c6223a476cd5aeadb687084a646", 244 Prev: "98a976f017e894c27e9a158b807ec0c7", 245 }, 246 }, 247 { 248 Name: "tinyxml2", 249 Version: "9.0.0", 250 PURL: "pkg:conan/tinyxml2@9.0.0", 251 Locations: file.NewLocationSet(file.NewLocation(fixture)), 252 Language: pkg.CPP, 253 Type: pkg.ConanPkg, 254 Metadata: pkg.ConanLockEntry{ 255 Ref: "tinyxml2/9.0.0#9f13a36ebfc222cd55fe531a0a8d94d1", 256 Options: map[string]string{ 257 "fPIC": "True", 258 "shared": "False", 259 }, 260 Context: "host", 261 // intentionally remove to test missing PackageID and Prev 262 // PackageID: "6557f18ca99c0b6a233f43db00e30efaa525e27e", 263 // Prev: "548bb273d2980991baa519453d68e5cd", 264 }, 265 }, 266 } 267 268 // relationships require IDs to be set to be sorted similarly 269 for i := range expected { 270 expected[i].SetID() 271 } 272 273 var expectedRelationships = []artifact.Relationship{ 274 { 275 From: expected[1], // boost 276 To: expected[0], // mfast 277 Type: artifact.DependencyOfRelationship, 278 Data: nil, 279 }, 280 { 281 From: expected[5], // tinyxml2 282 To: expected[0], // mfast 283 Type: artifact.DependencyOfRelationship, 284 Data: nil, 285 }, 286 { 287 From: expected[2], // zlib 288 To: expected[1], // boost 289 Type: artifact.DependencyOfRelationship, 290 Data: nil, 291 }, 292 { 293 From: expected[3], // bzip2 294 To: expected[1], // boost 295 Type: artifact.DependencyOfRelationship, 296 Data: nil, 297 }, 298 { 299 From: expected[4], // libbacktrace 300 To: expected[1], // boost 301 Type: artifact.DependencyOfRelationship, 302 Data: nil, 303 }, 304 } 305 306 pkgtest.TestFileParser(t, fixture, parseConanlock, expected, expectedRelationships) 307 }