Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion syft/file/cataloger/filedigest/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func (i *Cataloger) Catalog(resolver file.Resolver, coordinates ...file.Coordina
locations = intCataloger.AllRegularFiles(resolver)
} else {
for _, c := range coordinates {
locations = append(locations, file.NewLocationFromCoordinates(c))
locs, err := resolver.FilesByPath(c.RealPath)
if err != nil {
return nil, fmt.Errorf("unable to get file locations for path %q: %w", c.RealPath, err)
}
locations = append(locations, locs...)
}
}

Expand Down
44 changes: 44 additions & 0 deletions syft/file/cataloger/filedigest/cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,47 @@ func TestDigestsCataloger_MixFileTypes(t *testing.T) {
})
}
}

func TestFileDigestCataloger_GivenCoordinates(t *testing.T) {
testImage := "image-file-type-mix"

img := imagetest.GetFixtureImage(t, "docker-archive", testImage)

c := NewCataloger([]crypto.Hash{crypto.SHA256})

src, err := source.NewFromStereoscopeImageObject(img, testImage, nil)
require.NoError(t, err)

resolver, err := src.FileResolver(source.SquashedScope)
require.NoError(t, err)

tests := []struct {
path string
exists bool
expected string
}{
{
path: "/file-1.txt",
exists: true,
expected: "b089629781f05ef805b4511e93717f2ffa4c9d991771d5cbfa4b7242b4ef5fff",
},
}

for _, test := range tests {
t.Run(test.path, func(t *testing.T) {
_, ref, err := img.SquashedTree().File(stereoscopeFile.Path(test.path))
require.NoError(t, err)

l := file.NewLocationFromImage(test.path, *ref.Reference, img)

// note: an important difference between this test and the previous is that this test is using a list
// of specific coordinates to catalog
actual, err := c.Catalog(resolver, l.Coordinates)
require.NoError(t, err)
require.Len(t, actual, 1)

assert.Equal(t, test.expected, actual[l.Coordinates][0].Value, "mismatched digests")
})
}

}
1 change: 0 additions & 1 deletion syft/file/cataloger/filemetadata/cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func TestFileMetadataCataloger_GivenCoordinates(t *testing.T) {
path string
exists bool
expected file.Metadata
err bool
}{
{
path: "/file-1.txt",
Expand Down