mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
This PR adds DependencyOf relationships when ELF packages have been discovered by the binary cataloger. The discovered file.Executable type has a []ImportedLibraries that's read from the file when discovered by syft. By mapping these imported libraries back to the package collection, syft is able to create relationships showing which packages are dependencies of other packages by just reading metadata from the ELF executable. --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Signed-off-by: Brian Ebarb <ebarb.brian@sers.noreply.github.com> Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
package integration
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/anchore/clio"
|
|
"github.com/anchore/stereoscope/pkg/imagetest"
|
|
"github.com/anchore/syft/cmd/syft/internal/options"
|
|
"github.com/anchore/syft/syft"
|
|
"github.com/anchore/syft/syft/cataloging/pkgcataloging"
|
|
"github.com/anchore/syft/syft/sbom"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
func catalogFixtureImage(t *testing.T, fixtureImageName string, scope source.Scope, catalogerSelection ...string) (sbom.SBOM, source.Source) {
|
|
cfg := options.DefaultCatalog().ToSBOMConfig(clio.Identification{
|
|
Name: "syft-tester",
|
|
Version: "v0.99.0",
|
|
}).WithCatalogerSelection(
|
|
pkgcataloging.NewSelectionRequest().
|
|
WithExpression(catalogerSelection...),
|
|
)
|
|
cfg.Search.Scope = scope
|
|
|
|
return catalogFixtureImageWithConfig(t, fixtureImageName, cfg)
|
|
}
|
|
|
|
func catalogFixtureImageWithConfig(t *testing.T, fixtureImageName string, cfg *syft.CreateSBOMConfig) (sbom.SBOM, source.Source) {
|
|
cfg.CatalogerSelection = cfg.CatalogerSelection.WithDefaults(pkgcataloging.ImageTag)
|
|
|
|
// get the fixture image tar file
|
|
tarPath := imagetest.GetFixtureImageTarPath(t, fixtureImageName)
|
|
|
|
// get the source to build an SBOM against
|
|
theSource, err := syft.GetSource(context.Background(), tarPath, syft.DefaultGetSourceConfig().WithSources("docker-archive"))
|
|
require.NoError(t, err)
|
|
|
|
t.Cleanup(func() {
|
|
require.NoError(t, theSource.Close())
|
|
})
|
|
|
|
s, err := syft.CreateSBOM(context.Background(), theSource, cfg)
|
|
|
|
require.NoError(t, err)
|
|
require.NotNil(t, s)
|
|
|
|
return *s, theSource
|
|
}
|
|
|
|
func catalogDirectory(t *testing.T, dir string, catalogerSelection ...string) (sbom.SBOM, source.Source) {
|
|
cfg := options.DefaultCatalog().ToSBOMConfig(clio.Identification{
|
|
Name: "syft-tester",
|
|
Version: "v0.99.0",
|
|
}).WithCatalogerSelection(
|
|
pkgcataloging.NewSelectionRequest().
|
|
WithExpression(catalogerSelection...),
|
|
)
|
|
|
|
return catalogDirectoryWithConfig(t, dir, cfg)
|
|
}
|
|
|
|
func catalogDirectoryWithConfig(t *testing.T, dir string, cfg *syft.CreateSBOMConfig) (sbom.SBOM, source.Source) {
|
|
cfg.CatalogerSelection = cfg.CatalogerSelection.WithDefaults(pkgcataloging.DirectoryTag)
|
|
|
|
// get the source to build an sbom against
|
|
theSource, err := syft.GetSource(context.Background(), dir, syft.DefaultGetSourceConfig().WithSources("dir"))
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
require.NoError(t, theSource.Close())
|
|
})
|
|
|
|
// build the SBOM
|
|
s, err := syft.CreateSBOM(context.Background(), theSource, cfg)
|
|
|
|
require.NoError(t, err)
|
|
require.NotNil(t, s)
|
|
|
|
return *s, theSource
|
|
}
|