1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-11-28 08:49:44 +02:00

Enable wdi5 autologin (#4522)

* Enable wdi5 autologin

By also providing the basic auth credential on the env vars wdi5_username and wdi5_password we enable the wdi5 autologin feature, where the user does not have to remap the credentials in their wdi5 configuration. See https://ui5-community.github.io/wdi5/#/authentication?id=credentials

* Add documentation

* Add wdi5 parameter

* Add tests
This commit is contained in:
Oliver Feldmann 2023-09-12 10:11:28 +02:00 committed by GitHub
parent 3eb4f165b2
commit 1aac091497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 126 additions and 1 deletions

View File

@ -5,3 +5,9 @@
## ${docGenParameters}
## ${docGenConfiguration}
## Examples
### Passing credentials
When running acceptance tests in a real environment, authentication will be enabled in most cases. WDI5 includes [features to automatically perform the login](https://ui5-community.github.io/wdi5/#/authentication). For this, if the step parameter `wdi5` is set to `true`, the provided basic auth credential (`credentialsId`) are mapped to the environment variables `wdi5_username` and `wdi5_password`.

View File

@ -166,6 +166,114 @@ class NpmExecuteEndToEndTestsTest extends BasePiperTest {
assert npmExecuteScriptsRule.hasParameter('scriptOptions', ["--baseUrl=http://my-url.com"])
}
@Test
void oneAppUrl__whenWdi5IsTrue__wdi5CredentialIsProvided() {
def appUrl = [url: "http://my-url.com", credentialId: "testCred"]
nullScript.commonPipelineEnvironment.configuration = [stages: [myStage:[
appUrls: [appUrl],
wdi5: true
]]]
stepRule.step.npmExecuteEndToEndTests(
script: nullScript,
stageName: "myStage"
)
assertFalse(executedInParallel)
assert npmExecuteScriptsRule.hasParameter('script', nullScript)
assert npmExecuteScriptsRule.hasParameter('parameters', [dockerOptions: ['--shm-size 512MB']])
assert npmExecuteScriptsRule.hasParameter('virtualFrameBuffer', true)
assert npmExecuteScriptsRule.hasParameter('runScripts', ["ci-e2e"])
assert npmExecuteScriptsRule.hasParameter('scriptOptions', ["--launchUrl=${appUrl.url}"])
assert binding.hasVariable('e2e_username')
assert binding.hasVariable('e2e_password')
assert binding.hasVariable('wdi5_username')
assert binding.hasVariable('wdi5_password')
}
@Test
void oneAppUrl__whenWdi5IsNotSet__noWdi5CredentialIsProvided() {
def appUrl = [url: "http://my-url.com", credentialId: "testCred"]
nullScript.commonPipelineEnvironment.configuration = [stages: [myStage:[
appUrls: [appUrl]
]]]
stepRule.step.npmExecuteEndToEndTests(
script: nullScript,
stageName: "myStage"
)
assertFalse(executedInParallel)
assert npmExecuteScriptsRule.hasParameter('script', nullScript)
assert npmExecuteScriptsRule.hasParameter('parameters', [dockerOptions: ['--shm-size 512MB']])
assert npmExecuteScriptsRule.hasParameter('virtualFrameBuffer', true)
assert npmExecuteScriptsRule.hasParameter('runScripts', ["ci-e2e"])
assert npmExecuteScriptsRule.hasParameter('scriptOptions', ["--launchUrl=${appUrl.url}"])
assert binding.hasVariable('e2e_username')
assert binding.hasVariable('e2e_password')
assertFalse binding.hasVariable('wdi5_username')
assertFalse binding.hasVariable('wdi5_password')
}
@Test
void whenWdi5IsTrue__wdi5CredentialIsProvided() {
nullScript.commonPipelineEnvironment.configuration = [
stages: [
myStage: [
wdi5: true,
credentialsId: "testCred"
]
]
]
stepRule.step.npmExecuteEndToEndTests(
script: nullScript,
stageName: "myStage"
)
assertFalse(executedInParallel)
assert npmExecuteScriptsRule.hasParameter('script', nullScript)
assert npmExecuteScriptsRule.hasParameter('parameters', [dockerOptions: ['--shm-size 512MB']])
assert npmExecuteScriptsRule.hasParameter('virtualFrameBuffer', true)
assert npmExecuteScriptsRule.hasParameter('runScripts', ["ci-e2e"])
assert binding.hasVariable('e2e_username')
assert binding.hasVariable('e2e_password')
assert binding.hasVariable('wdi5_username')
assert binding.hasVariable('wdi5_password')
}
@Test
void whenWdi5IsNotSet__noWdi5CredentialIsProvided() {
nullScript.commonPipelineEnvironment.configuration = [
stages: [
myStage: [
credentialsId: "testCred"
]
]
]
stepRule.step.npmExecuteEndToEndTests(
script: nullScript,
stageName: "myStage"
)
assertFalse(executedInParallel)
assert npmExecuteScriptsRule.hasParameter('script', nullScript)
assert npmExecuteScriptsRule.hasParameter('parameters', [dockerOptions: ['--shm-size 512MB']])
assert npmExecuteScriptsRule.hasParameter('virtualFrameBuffer', true)
assert npmExecuteScriptsRule.hasParameter('runScripts', ["ci-e2e"])
assert binding.hasVariable('e2e_username')
assert binding.hasVariable('e2e_password')
assertFalse binding.hasVariable('wdi5_username')
assertFalse binding.hasVariable('wdi5_password')
}
@Test
void chooseScript() {

View File

@ -52,7 +52,12 @@ import static com.sap.piper.Prerequisites.checkScript
/**
* Credentials to access the application to be tested
*/
'credentialsId'
'credentialsId',
/**
* Distinguish if these are wdi5 tests. If set to `true` `wdi5_username` and `wdi5_password` environment variables are used to enable [autologin](https://ui5-community.github.io/wdi5/#/authentication?id=credentials).
* @possibleValues `true`, `false`
*/
'wdi5'
])
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
@ -112,6 +117,9 @@ void call(Map parameters = [:]) {
}
if (appUrl.credentialId) {
credentials.add(usernamePassword(credentialsId: appUrl.credentialId, passwordVariable: 'e2e_password', usernameVariable: 'e2e_username'))
if (config.wdi5) {
credentials.add(usernamePassword(credentialsId: appUrl.credentialId, passwordVariable: 'wdi5_password', usernameVariable: 'wdi5_username'))
}
}
List scriptOptions = ["--launchUrl=${appUrl.url}"]
if (appUrl.parameters) {
@ -127,6 +135,9 @@ void call(Map parameters = [:]) {
}else{
if (config.credentialsId) {
credentials.add(usernamePassword(credentialsId: config.credentialsId, passwordVariable: 'e2e_password', usernameVariable: 'e2e_username'))
if (config.wdi5) {
credentials.add(usernamePassword(credentialsId: config.credentialsId, passwordVariable: 'wdi5_password', usernameVariable: 'wdi5_username'))
}
}
List scriptOptions = []
if (config.baseUrl){