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