Skip to content

Commit

Permalink
tests: add no resolver match test case
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Phillips <[email protected]>
  • Loading branch information
spiffcs committed Apr 26, 2024
1 parent e79eea8 commit bb8d07b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion internal/relationship/binary/binary_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ func populateRelationships(exec file.Executable, parentPkg pkg.Package, resolver
// are you in our index?
realBaseName := path.Base(loc.RealPath)
pkgCollection := index.owningLibraryPackage(realBaseName)

if pkgCollection.PackageCount() < 1 {
relIndex.add(
artifact.Relationship{
From: loc.Coordinates,
To: parentPkg,
Type: artifact.DependencyOfRelationship,
},
)
}
for _, p := range pkgCollection.Sorted() {
relIndex.add(
artifact.Relationship{
Expand Down
11 changes: 9 additions & 2 deletions internal/relationship/binary/binary_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
// sytftestfixture (lib executable)... that imports GLIBC

// 1. ELF P (a) --> exec (a) ---> imports of (a) --> (b) executable (imported executable) (ELF P --> file)
// 1. ... if the file resolver returns no answers given an owned claim we survive

// Case 3 needs to be covered somewhere else given that NewDependency relationships should already have accessor with deduped packages
// 3. ELF P (a) is a part of RPM P (b), thus ELF P (a) is deleted from the SBOM... this means that (b) gets all relationships of (a)
Expand Down Expand Up @@ -217,7 +216,15 @@ func TestNewDependencyRelationships(t *testing.T) {
want: []artifact.Relationship{},
},
{
name: "given multiple owned paths for RPM package, expect only one relationship to be created",
name: "given a package that imports a library that is not tracked by the resolver, expect no relationships to be created",
resolver: file.NewMockResolverForPaths(),
coordinateIndex: map[file.Coordinates]file.Executable{
glibcCoordinate: glibcExecutable,
nestedLibCoordinate: syftTestFixtureExecutable,
parrallelLibCoordinate: syftTestFixtureExecutable2,
},
packages: []pkg.Package{glibCPackage, syftTestFixturePackage},
want: []artifact.Relationship{},
},
}
for _, tt := range tests {
Expand Down

0 comments on commit bb8d07b

Please sign in to comment.