mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
fix(protecode): handle sha256 in upload artifacts (#2532)
* add sha256 check to protecodeExecuteScan * remove trailing spaces * add Unit-Test for getTarName * Apply suggestions from code review Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
This commit is contained in:
parent
efe3ab36f8
commit
ea203a2c69
@ -330,11 +330,15 @@ func correctDockerConfigEnvVar(config *protecodeExecuteScanOptions) {
|
|||||||
func getTarName(config *protecodeExecuteScanOptions) string {
|
func getTarName(config *protecodeExecuteScanOptions) string {
|
||||||
// remove original version
|
// remove original version
|
||||||
fileName := strings.TrimSuffix(config.ScanImage, ":"+config.ArtifactVersion)
|
fileName := strings.TrimSuffix(config.ScanImage, ":"+config.ArtifactVersion)
|
||||||
|
// remove sha digest if exists
|
||||||
|
sha256 := "@sha256"
|
||||||
|
if index := strings.Index(fileName, sha256); index > -1 {
|
||||||
|
fileName = fileName[:index]
|
||||||
|
}
|
||||||
// append trimmed version
|
// append trimmed version
|
||||||
if version := handleArtifactVersion(config.ArtifactVersion); len(version) > 0 {
|
if version := handleArtifactVersion(config.ArtifactVersion); len(version) > 0 {
|
||||||
fileName = fileName + "_" + version
|
fileName = fileName + "_" + version
|
||||||
}
|
}
|
||||||
// replace unwanted chars
|
|
||||||
fileName = strings.ReplaceAll(fileName, "/", "_")
|
fileName = strings.ReplaceAll(fileName, "/", "_")
|
||||||
return fileName + ".tar"
|
return fileName + ".tar"
|
||||||
}
|
}
|
||||||
|
@ -399,13 +399,22 @@ func TestGetTarName(t *testing.T) {
|
|||||||
"3.20.20-20200131085038+eeb7c1033339bfd404d21ec5e7dc05c80e9e985e",
|
"3.20.20-20200131085038+eeb7c1033339bfd404d21ec5e7dc05c80e9e985e",
|
||||||
"abc_3.tar",
|
"abc_3.tar",
|
||||||
},
|
},
|
||||||
"without version ": {
|
"without version": {
|
||||||
"abc",
|
"abc",
|
||||||
"",
|
"",
|
||||||
"abc.tar",
|
"abc.tar",
|
||||||
},
|
},
|
||||||
|
"ScanImage without sha as artifactVersion": {
|
||||||
|
"abc@sha256:12345",
|
||||||
|
"",
|
||||||
|
"abc.tar",
|
||||||
|
},
|
||||||
|
"ScanImage with sha as artifactVersion": {
|
||||||
|
"ppiper/cf-cli@sha256:c25dbacb9ab6e912afe0fe926d8f9d949c60adfe55d16778bde5941e6c37be11",
|
||||||
|
"c25dbacb9ab6e912afe0fe926d8f9d949c60adfe55d16778bde5941e6c37be11",
|
||||||
|
"ppiper_cf-cli_c25dbacb9ab6e912afe0fe926d8f9d949c60adfe55d16778bde5941e6c37be11.tar",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, c := range cases {
|
for name, c := range cases {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
assert.Equal(t, c.expect, getTarName(&protecodeExecuteScanOptions{ScanImage: c.image, ArtifactVersion: c.version}))
|
assert.Equal(t, c.expect, getTarName(&protecodeExecuteScanOptions{ScanImage: c.image, ArtifactVersion: c.version}))
|
||||||
|
Loading…
Reference in New Issue
Block a user