Skip to content

Commit

Permalink
SPDX file has duplicate sha256 tag in versionInfo (anchore#2300)
Browse files Browse the repository at this point in the history
* SPDX file has duplicate sha256 tag in versionInfo

Signed-off-by: Colm O hEigeartaigh <[email protected]>

* add tests

Signed-off-by: Alex Goodman <[email protected]>

---------

Signed-off-by: Colm O hEigeartaigh <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Co-authored-by: Alex Goodman <[email protected]>
  • Loading branch information
coheigea and wagoodman authored Nov 8, 2023
1 parent 9b74405 commit ea2c840
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
4 changes: 0 additions & 4 deletions syft/source/file_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ func deriveIDFromFile(cfg FileConfig) (artifact.ID, string) {
info += fmt.Sprintf(":%s@%s", cfg.Alias.Name, cfg.Alias.Version)
}

if d != "" {
d = fmt.Sprintf("sha256:%s", d)
}

return artifactIDFromDigest(digest.SHA256.FromString(info).String()), d
}

Expand Down
25 changes: 15 additions & 10 deletions syft/source/file_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ func createArchive(t testing.TB, sourceDirPath, destinationArchivePath string, l

func Test_FileSource_ID(t *testing.T) {
tests := []struct {
name string
cfg FileConfig
want artifact.ID
wantErr require.ErrorAssertionFunc
name string
cfg FileConfig
want artifact.ID
wantDigest string
wantErr require.ErrorAssertionFunc
}{
{
name: "empty",
Expand All @@ -236,9 +237,10 @@ func Test_FileSource_ID(t *testing.T) {
wantErr: require.Error,
},
{
name: "with path",
cfg: FileConfig{Path: "./test-fixtures/image-simple/Dockerfile"},
want: artifact.ID("db7146472cf6d49b3ac01b42812fb60020b0b4898b97491b21bb690c808d5159"),
name: "with path",
cfg: FileConfig{Path: "./test-fixtures/image-simple/Dockerfile"},
want: artifact.ID("db7146472cf6d49b3ac01b42812fb60020b0b4898b97491b21bb690c808d5159"),
wantDigest: "sha256:38601c0bb4269a10ce1d00590ea7689c1117dd9274c758653934ab4f2016f80f",
},
{
name: "with path and alias",
Expand All @@ -249,7 +251,8 @@ func Test_FileSource_ID(t *testing.T) {
Version: "version-me-this!",
},
},
want: artifact.ID("3c713003305ac6605255cec8bf4ea649aa44b2b9a9f3a07bd683869d1363438a"),
want: artifact.ID("3c713003305ac6605255cec8bf4ea649aa44b2b9a9f3a07bd683869d1363438a"),
wantDigest: "sha256:38601c0bb4269a10ce1d00590ea7689c1117dd9274c758653934ab4f2016f80f",
},
{
name: "other fields do not affect ID",
Expand All @@ -259,7 +262,8 @@ func Test_FileSource_ID(t *testing.T) {
Paths: []string{"a", "b"},
},
},
want: artifact.ID("db7146472cf6d49b3ac01b42812fb60020b0b4898b97491b21bb690c808d5159"),
want: artifact.ID("db7146472cf6d49b3ac01b42812fb60020b0b4898b97491b21bb690c808d5159"),
wantDigest: "sha256:38601c0bb4269a10ce1d00590ea7689c1117dd9274c758653934ab4f2016f80f",
},
}
for _, tt := range tests {
Expand All @@ -272,7 +276,8 @@ func Test_FileSource_ID(t *testing.T) {
if err != nil {
return
}
assert.Equalf(t, tt.want, s.ID(), "ID()")
assert.Equalf(t, tt.want, s.ID(), "ID() mismatch")
assert.Equalf(t, tt.wantDigest, s.digestForVersion, "digestForVersion mismatch")
})
}
}

0 comments on commit ea2c840

Please sign in to comment.