Commit d58dabab authored by Emanuele Aina's avatar Emanuele Aina

test: Handle usernamePassword within withCredentials

This is useful for internal images which need to retrieve resources protected
by HTTP Basic Auth.
Signed-off-by: Emanuele Aina's avatarEmanuele Aina <emanuele.aina@collabora.com>
parent d4dddd1c
Pipeline #4119 passed with stage
in 1 minute and 52 seconds
...@@ -62,6 +62,23 @@ class CurrentBuildMock extends LinkedHashMap { ...@@ -62,6 +62,23 @@ class CurrentBuildMock extends LinkedHashMap {
} }
class JenkinsfileTest extends BasePipelineTest { class JenkinsfileTest extends BasePipelineTest {
static def withCredentialsInterceptor = { list, closure ->
list.forEach {
def vars = it instanceof List ? it : [ it ]
vars.forEach {
binding.setVariable(it, "$it")
}
}
def res = closure.call()
list.forEach {
def vars = it instanceof List ? it : [ it ]
vars.forEach {
binding.setVariable(it, null)
}
}
return res
}
@Override @Override
@Before @Before
void setUp() throws Exception { void setUp() throws Exception {
...@@ -70,9 +87,11 @@ class JenkinsfileTest extends BasePipelineTest { ...@@ -70,9 +87,11 @@ class JenkinsfileTest extends BasePipelineTest {
assert params.versionNumberString == '${BUILD_DATE_FORMATTED,"yyyyMMdd"}.${BUILDS_TODAY_Z}' assert params.versionNumberString == '${BUILD_DATE_FORMATTED,"yyyyMMdd"}.${BUILDS_TODAY_Z}'
return "20190401.0" return "20190401.0"
}) })
helper.registerAllowedMethod("withCredentials", [ List.class, Closure.class], withCredentialsInterceptor)
helper.registerAllowedMethod("parameters", [ArrayList.class], null) helper.registerAllowedMethod("parameters", [ArrayList.class], null)
helper.registerAllowedMethod("writeFile", [Map.class], null) helper.registerAllowedMethod("writeFile", [Map.class], null)
helper.registerAllowedMethod("file", [Map.class], {m -> m.variable}) helper.registerAllowedMethod("file", [Map.class], {m -> m.variable})
helper.registerAllowedMethod("usernamePassword", [Map.class], {m -> [m.usernameVariable, m.passwordVariable]})
helper.registerAllowedMethod("sshagent", [Map.class, Closure.class], null) helper.registerAllowedMethod("sshagent", [Map.class, Closure.class], null)
helper.registerAllowedMethod("deleteDir", [], null) helper.registerAllowedMethod("deleteDir", [], null)
helper.registerAllowedMethod("git", [Map.class], null) helper.registerAllowedMethod("git", [Map.class], null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment