github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/gentoo/cataloger_test.go (about)

     1  package gentoo
     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 TestPortageCataloger(t *testing.T) {
    13  	tests := []struct {
    14  		name                  string
    15  		fixture               string
    16  		expectedPackages      []pkg.Package
    17  		expectedRelationships []artifact.Relationship
    18  	}{
    19  		{
    20  			name:    "standard skopeo package",
    21  			fixture: "test-fixtures/layout",
    22  			expectedPackages: []pkg.Package{
    23  				{
    24  					Name:    "app-containers/skopeo",
    25  					Version: "1.5.1",
    26  					FoundBy: "portage-cataloger",
    27  					PURL:    "pkg:ebuild/app-containers%2Fskopeo@1.5.1",
    28  					Locations: file.NewLocationSet(
    29  						file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/CONTENTS"),
    30  						file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/SIZE"),
    31  						file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/LICENSE"),
    32  					),
    33  					Licenses: pkg.NewLicenseSet(
    34  						pkg.NewLicensesFromLocation(
    35  							file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/LICENSE"),
    36  							"Apache-2.0 AND BSD AND BSD-2 AND CC-BY-SA-4.0 AND ISC AND MIT")...,
    37  					),
    38  					Type: pkg.PortagePkg,
    39  					Metadata: pkg.PortageEntry{
    40  						InstalledSize: 27937835,
    41  						Licenses:      "Apache-2.0 BSD BSD-2 CC-BY-SA-4.0 ISC MIT",
    42  						Files: []pkg.PortageFileRecord{
    43  							{
    44  								Path: "/usr/bin/skopeo",
    45  								Digest: &file.Digest{
    46  									Algorithm: "md5",
    47  									Value:     "376c02bd3b22804df8fdfdc895e7dbfb",
    48  								},
    49  							},
    50  							{
    51  								Path: "/etc/containers/policy.json",
    52  								Digest: &file.Digest{
    53  									Algorithm: "md5",
    54  									Value:     "c01eb6950f03419e09d4fc88cb42ff6f",
    55  								},
    56  							},
    57  							{
    58  								Path: "/etc/containers/registries.d/default.yaml",
    59  								Digest: &file.Digest{
    60  									Algorithm: "md5",
    61  									Value:     "e6e66cd3c24623e0667f26542e0e08f6",
    62  								},
    63  							},
    64  							{
    65  								Path: "/var/lib/atomic/sigstore/.keep_app-containers_skopeo-0",
    66  								Digest: &file.Digest{
    67  									Algorithm: "md5",
    68  									Value:     "d41d8cd98f00b204e9800998ecf8427e",
    69  								},
    70  							},
    71  						},
    72  					},
    73  				},
    74  			},
    75  			// not supported at this time
    76  			expectedRelationships: nil,
    77  		},
    78  		{
    79  			name:    "standard skopeo package with license groups",
    80  			fixture: "test-fixtures/layout-license-groups",
    81  			expectedPackages: []pkg.Package{
    82  				{
    83  					Name:    "app-containers/skopeo",
    84  					Version: "1.5.1",
    85  					FoundBy: "portage-cataloger",
    86  					PURL:    "pkg:ebuild/app-containers%2Fskopeo@1.5.1",
    87  					Locations: file.NewLocationSet(
    88  						file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/CONTENTS"),
    89  						file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/SIZE"),
    90  						file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/LICENSE"),
    91  					),
    92  					Licenses: pkg.NewLicenseSet(
    93  						pkg.NewLicensesFromLocation(
    94  							file.NewLocation("var/db/pkg/app-containers/skopeo-1.5.1/LICENSE"),
    95  							"Apache-2.0 AND BSD AND BSD-2 AND CC-BY-SA-4.0 AND ISC AND MIT")...,
    96  					),
    97  					Type: pkg.PortagePkg,
    98  					Metadata: pkg.PortageEntry{
    99  						InstalledSize: 27937835,
   100  						Licenses:      "@GROUP1 @MIT-LIKE",
   101  						Files: []pkg.PortageFileRecord{
   102  							{
   103  								Path: "/usr/bin/skopeo",
   104  								Digest: &file.Digest{
   105  									Algorithm: "md5",
   106  									Value:     "376c02bd3b22804df8fdfdc895e7dbfb",
   107  								},
   108  							},
   109  							{
   110  								Path: "/etc/containers/policy.json",
   111  								Digest: &file.Digest{
   112  									Algorithm: "md5",
   113  									Value:     "c01eb6950f03419e09d4fc88cb42ff6f",
   114  								},
   115  							},
   116  							{
   117  								Path: "/etc/containers/registries.d/default.yaml",
   118  								Digest: &file.Digest{
   119  									Algorithm: "md5",
   120  									Value:     "e6e66cd3c24623e0667f26542e0e08f6",
   121  								},
   122  							},
   123  							{
   124  								Path: "/var/lib/atomic/sigstore/.keep_app-containers_skopeo-0",
   125  								Digest: &file.Digest{
   126  									Algorithm: "md5",
   127  									Value:     "d41d8cd98f00b204e9800998ecf8427e",
   128  								},
   129  							},
   130  						},
   131  					},
   132  				},
   133  			},
   134  			// not supported at this time
   135  			expectedRelationships: nil,
   136  		},
   137  	}
   138  
   139  	for _, test := range tests {
   140  		t.Run(test.name, func(t *testing.T) {
   141  			pkgtest.NewCatalogTester().
   142  				FromDirectory(t, test.fixture).
   143  				Expects(test.expectedPackages, test.expectedRelationships).
   144  				TestCataloger(t, NewPortageCataloger())
   145  		})
   146  	}
   147  }
   148  
   149  func TestCataloger_Globs(t *testing.T) {
   150  	tests := []struct {
   151  		name     string
   152  		fixture  string
   153  		expected []string
   154  	}{
   155  		{
   156  			name:    "obtain portage contents file",
   157  			fixture: "test-fixtures/glob-paths",
   158  			expected: []string{
   159  				"var/db/pkg/x/y/CONTENTS",
   160  			},
   161  		},
   162  	}
   163  
   164  	for _, test := range tests {
   165  		t.Run(test.name, func(t *testing.T) {
   166  			pkgtest.NewCatalogTester().
   167  				FromDirectory(t, test.fixture).
   168  				ExpectsResolverContentQueries(test.expected).
   169  				TestCataloger(t, NewPortageCataloger())
   170  		})
   171  	}
   172  }