Skip to content

Commit f044ef1

Browse files
authored
fix(curl): Remove --insecure flag from curl when downlaoding Piper binary (#5179)
* remove --insecure flag from binary download * remove --insecure flag from binary download * adjust unit tests
1 parent 10f535c commit f044ef1

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/com/sap/piper/PiperGoUtils.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class PiperGoUtils implements Serializable {
8383
private boolean downloadGoBinary(url) {
8484

8585
try {
86-
def httpStatus = steps.sh(returnStdout: true, script: "curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out '%{http_code}' --output ${piperExecutable} '${url}'")
86+
def httpStatus = steps.sh(returnStdout: true, script: "curl --silent --retry 5 --retry-max-time 240 --location --write-out '%{http_code}' --output ${piperExecutable} '${url}'")
8787

8888
if (httpStatus == '200') {
8989
steps.sh(script: "chmod +x ${piperExecutable}")

test/groovy/com/sap/piper/PiperGoUtilsTest.groovy

+12-12
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ class PiperGoUtilsTest extends BasePiperTest {
6363
})
6464

6565
shellCallRule.setReturnValue('[ -x ./piper ]', 1)
66-
shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '200')
66+
shellCallRule.setReturnValue('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '200')
6767

6868
piperGoUtils.unstashPiperBin()
6969
assertThat(shellCallRule.shell.size(), is(4))
70-
assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\''))
70+
assertThat(shellCallRule.shell[1].toString(), is('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\''))
7171
assertThat(shellCallRule.shell[2].toString(), is('chmod +x piper'))
7272
assertThat(shellCallRule.shell[3].toString(), is('./piper version'))
7373
}
@@ -84,11 +84,11 @@ class PiperGoUtilsTest extends BasePiperTest {
8484
})
8585

8686
shellCallRule.setReturnValue('[ -x ./piper ]', 1)
87-
shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/testTag/piper\'', '200')
87+
shellCallRule.setReturnValue('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/testTag/piper\'', '200')
8888

8989
piperGoUtils.unstashPiperBin()
9090
assertThat(shellCallRule.shell.size(), is(4))
91-
assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/testTag/piper\''))
91+
assertThat(shellCallRule.shell[1].toString(), is('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/testTag/piper\''))
9292
assertThat(shellCallRule.shell[2].toString(), is('chmod +x piper'))
9393
assertThat(shellCallRule.shell[3].toString(), is('./piper version'))
9494
}
@@ -101,8 +101,8 @@ class PiperGoUtilsTest extends BasePiperTest {
101101

102102
shellCallRule.setReturnValue('[ -x ./piper ]', 1)
103103
shellCallRule.setReturnValue('./piper version', "1.2.3")
104-
shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
105-
shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '200')
104+
shellCallRule.setReturnValue('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
105+
shellCallRule.setReturnValue('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '200')
106106

107107
// this mocks utils.unstash - mimic stash not existing
108108
helper.registerAllowedMethod("unstash", [String.class], { stashFileName ->
@@ -112,8 +112,8 @@ class PiperGoUtilsTest extends BasePiperTest {
112112
piperGoUtils.unstashPiperBin()
113113
assertThat(shellCallRule.shell.size(), is(5))
114114
assertThat(shellCallRule.shell[0].toString(), is('[ -x ./piper ]'))
115-
assertThat(shellCallRule.shell[1].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\''))
116-
assertThat(shellCallRule.shell[2].toString(), is('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\''))
115+
assertThat(shellCallRule.shell[1].toString(), is('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\''))
116+
assertThat(shellCallRule.shell[2].toString(), is('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\''))
117117
assertThat(shellCallRule.shell[3].toString(), is('chmod +x piper'))
118118
assertThat(shellCallRule.shell[4].toString(), is ('./piper version'))
119119
}
@@ -124,8 +124,8 @@ class PiperGoUtilsTest extends BasePiperTest {
124124
piperGoUtils.metaClass.getLibrariesInfo = {-> return [[name: 'piper-lib-os', version: 'notAvailable']]}
125125

126126
shellCallRule.setReturnValue('[ -x ./piper ]', 1)
127-
shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
128-
shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '500')
127+
shellCallRule.setReturnValue('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
128+
shellCallRule.setReturnValue('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '500')
129129

130130
helper.registerAllowedMethod("unstash", [String.class], { stashFileName ->
131131
return []
@@ -141,8 +141,8 @@ class PiperGoUtilsTest extends BasePiperTest {
141141
piperGoUtils.metaClass.getLibrariesInfo = {-> return [[name: 'piper-lib-os', version: 'notAvailable']]}
142142

143143
shellCallRule.setReturnValue('[ -x ./piper ]', 1)
144-
shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
145-
shellCallRule.setReturnValue('curl --insecure --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '500')
144+
shellCallRule.setReturnValue('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/download/notAvailable/piper\'', '404')
145+
shellCallRule.setReturnValue('curl --silent --retry 5 --retry-max-time 240 --location --write-out \'%{http_code}\' --output piper \'https://github.com/SAP/jenkins-library/releases/latest/download/piper\'', '500')
146146

147147
helper.registerAllowedMethod("unstash", [String.class], { stashFileName ->
148148
return []

0 commit comments

Comments
 (0)