mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
Fix algo lookup by converting key to lower case (#2207)
Signed-off-by: Mohammad Sharief Baig <shariefmohammad007@gmail.com>
This commit is contained in:
parent
68cf57ed03
commit
d16ecdf715
@ -97,7 +97,7 @@ func toCycloneDXAlgorithm(algorithm string) cyclonedx.HashAlgorithm {
|
||||
"sha256": cyclonedx.HashAlgorithm("SHA-256"),
|
||||
}
|
||||
|
||||
return validMap[algorithm]
|
||||
return validMap[strings.ToLower(algorithm)]
|
||||
}
|
||||
|
||||
func decodeExternalReferences(c *cyclonedx.Component, metadata interface{}) {
|
||||
|
||||
@ -173,3 +173,27 @@ func Test_isValidExternalRef(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_toCycloneDXAlgorithm(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected cyclonedx.HashAlgorithm
|
||||
}{
|
||||
{
|
||||
name: "valid algorithm name in upper case",
|
||||
input: "SHA1",
|
||||
expected: cyclonedx.HashAlgorithm("SHA-1"),
|
||||
},
|
||||
{
|
||||
name: "valid algorithm name in lower case",
|
||||
input: "sha1",
|
||||
expected: cyclonedx.HashAlgorithm("SHA-1"),
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
assert.Equal(t, test.expected, toCycloneDXAlgorithm(test.input))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user