Fix algo lookup by converting key to lower case (#2207)

Signed-off-by: Mohammad Sharief Baig <shariefmohammad007@gmail.com>
This commit is contained in:
Mohammad Sharief Baig 2023-10-09 22:37:18 +05:30 committed by GitHub
parent 68cf57ed03
commit d16ecdf715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -97,7 +97,7 @@ func toCycloneDXAlgorithm(algorithm string) cyclonedx.HashAlgorithm {
"sha256": cyclonedx.HashAlgorithm("SHA-256"), "sha256": cyclonedx.HashAlgorithm("SHA-256"),
} }
return validMap[algorithm] return validMap[strings.ToLower(algorithm)]
} }
func decodeExternalReferences(c *cyclonedx.Component, metadata interface{}) { func decodeExternalReferences(c *cyclonedx.Component, metadata interface{}) {

View File

@ -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))
})
}
}