github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/alpm/cataloger_test.go (about)

     1  package alpm
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/google/go-cmp/cmp/cmpopts"
     7  
     8  	"github.com/anchore/syft/syft/artifact"
     9  	"github.com/anchore/syft/syft/file"
    10  	"github.com/anchore/syft/syft/pkg"
    11  	"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
    12  )
    13  
    14  func TestAlpmCataloger(t *testing.T) {
    15  	dbLocation := file.NewLocation("var/lib/pacman/local/gmp-6.2.1-2/desc")
    16  	expectedPkgs := []pkg.Package{
    17  		{
    18  			Name:    "gmp",
    19  			Version: "6.2.1-2",
    20  			Type:    pkg.AlpmPkg,
    21  			FoundBy: "alpmdb-cataloger",
    22  			Licenses: pkg.NewLicenseSet(
    23  				pkg.NewLicenseFromLocations("LGPL3", dbLocation),
    24  				pkg.NewLicenseFromLocations("GPL", dbLocation),
    25  			),
    26  			Locations:    file.NewLocationSet(dbLocation),
    27  			CPEs:         nil,
    28  			PURL:         "",
    29  			MetadataType: "AlpmMetadata",
    30  			Metadata: pkg.AlpmMetadata{
    31  				BasePackage:  "gmp",
    32  				Package:      "gmp",
    33  				Version:      "6.2.1-2",
    34  				Description:  "A free library for arbitrary precision arithmetic",
    35  				Architecture: "x86_64",
    36  				Size:         1044438,
    37  				Packager:     "Antonio Rojas <arojas@archlinux.org>",
    38  				URL:          "https://gmplib.org/",
    39  				Validation:   "pgp",
    40  				Reason:       1,
    41  				Files: []pkg.AlpmFileRecord{
    42  					{
    43  						Path:    "/usr",
    44  						Type:    "dir",
    45  						Digests: []file.Digest{},
    46  					},
    47  					{
    48  						Path:    "/usr/include",
    49  						Type:    "dir",
    50  						Digests: []file.Digest{},
    51  					},
    52  					{
    53  						Path: "/usr/include/gmp.h",
    54  						Size: "84140",
    55  						Digests: []file.Digest{
    56  							{Algorithm: "md5", Value: "76595f70565c72550eb520809bf86856"},
    57  							{Algorithm: "sha256", Value: "91a614b9202453153fe3b7512d15e89659108b93ce8841c8e13789eb85da9e3a"},
    58  						},
    59  					},
    60  					{
    61  						Path: "/usr/include/gmpxx.h",
    62  						Size: "129113",
    63  						Digests: []file.Digest{
    64  							{Algorithm: "md5", Value: "ea3d21de4bcf7c696799c5c55dd3655b"},
    65  							{Algorithm: "sha256", Value: "0011ae411a0bc1030e07d968b32fdc1343f5ac2a17b7d28f493e7976dde2ac82"},
    66  						},
    67  					},
    68  					{
    69  						Path:    "/usr/lib",
    70  						Type:    "dir",
    71  						Digests: []file.Digest{},
    72  					},
    73  					{
    74  						Path:    "/usr/lib/libgmp.so",
    75  						Type:    "link",
    76  						Link:    "libgmp.so.10.4.1",
    77  						Digests: []file.Digest{},
    78  					},
    79  					{
    80  						Path:    "/usr/lib/libgmp.so.10",
    81  						Type:    "link",
    82  						Link:    "libgmp.so.10.4.1",
    83  						Digests: []file.Digest{},
    84  					},
    85  					{
    86  						Path: "/usr/lib/libgmp.so.10.4.1",
    87  						Size: "663224",
    88  						Digests: []file.Digest{
    89  							{Algorithm: "md5", Value: "d6d03eadacdd9048d5b2adf577e9d722"},
    90  							{Algorithm: "sha256", Value: "39898bd3d8d6785222432fa8b8aef7ce3b7e5bbfc66a52b7c0da09bed4adbe6a"},
    91  						},
    92  					},
    93  					{
    94  						Path:    "/usr/lib/libgmpxx.so",
    95  						Type:    "link",
    96  						Link:    "libgmpxx.so.4.6.1",
    97  						Digests: []file.Digest{},
    98  					},
    99  					{
   100  						Path:    "/usr/lib/libgmpxx.so.4",
   101  						Type:    "link",
   102  						Link:    "libgmpxx.so.4.6.1",
   103  						Digests: []file.Digest{},
   104  					},
   105  					{
   106  						Path: "/usr/lib/libgmpxx.so.4.6.1",
   107  						Size: "30680",
   108  						Digests: []file.Digest{
   109  							{Algorithm: "md5", Value: "dd5f0c4d635fa599fa7f4339c0e8814d"},
   110  							{Algorithm: "sha256", Value: "0ef67cbde4841f58d2e4b41f59425eb87c9eeaf4e649c060b326342c53bedbec"},
   111  						},
   112  					},
   113  					{
   114  						Path:    "/usr/lib/pkgconfig",
   115  						Type:    "dir",
   116  						Digests: []file.Digest{},
   117  					},
   118  					{
   119  						Path: "/usr/lib/pkgconfig/gmp.pc",
   120  						Size: "245",
   121  						Digests: []file.Digest{
   122  							{Algorithm: "md5", Value: "a91a9f1b66218cb77b9cd2cdf341756d"},
   123  							{Algorithm: "sha256", Value: "4e9de547a48c4e443781e9fa702a1ec5a23ee28b4bc520306cff2541a855be37"},
   124  						},
   125  					},
   126  					{
   127  						Path: "/usr/lib/pkgconfig/gmpxx.pc",
   128  						Size: "280",
   129  						Digests: []file.Digest{
   130  							{Algorithm: "md5", Value: "8c0f54e987934352177a6a30a811b001"},
   131  							{Algorithm: "sha256", Value: "fc5dbfbe75977057ba50953d94b9daecf696c9fdfe5b94692b832b44ecca871b"},
   132  						},
   133  					},
   134  					{
   135  						Path:    "/usr/share",
   136  						Type:    "dir",
   137  						Digests: []file.Digest{},
   138  					},
   139  					{
   140  						Path:    "/usr/share/info",
   141  						Type:    "dir",
   142  						Digests: []file.Digest{},
   143  					},
   144  					{
   145  						Path: "/usr/share/info/gmp.info-1.gz",
   146  						Size: "85892",
   147  						Digests: []file.Digest{
   148  							{Algorithm: "md5", Value: "63304d4d2f0247fb8a999fae66a81c19"},
   149  							{Algorithm: "sha256", Value: "86288c1531a2789db5da8b9838b5cde4db07bda230ae11eba23a1f33698bd14e"},
   150  						},
   151  					},
   152  					{
   153  						Path: "/usr/share/info/gmp.info-2.gz",
   154  						Size: "48484",
   155  						Digests: []file.Digest{
   156  							{Algorithm: "md5", Value: "4bb0dadec416d305232cac6eae712ff7"},
   157  							{Algorithm: "sha256", Value: "b7443c1b529588d98a074266087f79b595657ac7274191c34b10a9ceedfa950e"},
   158  						},
   159  					},
   160  					{
   161  						Path: "/usr/share/info/gmp.info.gz",
   162  						Size: "2380",
   163  						Digests: []file.Digest{
   164  							{Algorithm: "md5", Value: "cf6880fb0d862ee1da0d13c3831b5720"},
   165  							{Algorithm: "sha256", Value: "a13c8eecda3f3e5ad1e09773e47a9686f07d9d494eaddf326f3696bbef1548fd"},
   166  						},
   167  					},
   168  				},
   169  				Backup: []pkg.AlpmFileRecord{},
   170  			},
   171  		},
   172  	}
   173  
   174  	// TODO: relationships are not under test yet
   175  	var expectedRelationships []artifact.Relationship
   176  
   177  	pkgtest.NewCatalogTester().
   178  		FromDirectory(t, "test-fixtures/gmp-fixture").
   179  		WithCompareOptions(cmpopts.IgnoreFields(pkg.AlpmFileRecord{}, "Time")).
   180  		Expects(expectedPkgs, expectedRelationships).
   181  		TestCataloger(t, NewAlpmdbCataloger())
   182  
   183  }
   184  
   185  func TestCataloger_Globs(t *testing.T) {
   186  	tests := []struct {
   187  		name     string
   188  		fixture  string
   189  		expected []string
   190  	}{
   191  		{
   192  			name:    "obtain description files",
   193  			fixture: "test-fixtures/glob-paths",
   194  			expected: []string{
   195  				"var/lib/pacman/local/base-1.0/desc",
   196  				"var/lib/pacman/local/dive-0.10.0/desc",
   197  			},
   198  		},
   199  	}
   200  
   201  	for _, test := range tests {
   202  		t.Run(test.name, func(t *testing.T) {
   203  			pkgtest.NewCatalogTester().
   204  				FromDirectory(t, test.fixture).
   205  				ExpectsResolverContentQueries(test.expected).
   206  				IgnoreUnfulfilledPathResponses("var/lib/pacman/local/base-1.0/mtree", "var/lib/pacman/local/dive-0.10.0/mtree").
   207  				TestCataloger(t, NewAlpmdbCataloger())
   208  		})
   209  	}
   210  }