-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZENKO-2659 E2E test user authentication
- Loading branch information
1 parent
ebbb826
commit c091051
Showing
18 changed files
with
1,039 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"baseUrl": "http://127.0.0.1:8383", | ||
"video": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint jest/expect-expect: 0 */ | ||
|
||
describe('Authentication with keycloak', () => { | ||
describe('User authenticated', () => { | ||
beforeEach(cy.kcLogin); | ||
|
||
it(`should render user full name: ${Cypress.env('KEYCLOAK_USER_FULLNAME')}`, () => { | ||
const kcUserFullname = Cypress.env('KEYCLOAK_USER_FULLNAME'); | ||
if (!kcUserFullname) { | ||
throw new Error('missing CYPRESS_KEYCLOAK_USER_FULLNAME environment variable'); | ||
} | ||
|
||
cy.visit('/'); | ||
cy.get('.sc-navbar').should('exist'); | ||
// NOTE: this value is based on "eve/workers/keycloakconfig/keycloak-realm.json" | ||
cy.get('.sc-navbar').should('contain', kcUserFullname); | ||
}); | ||
|
||
afterEach(cy.kcLogout); | ||
}); | ||
|
||
describe('User not authenticated', () => { | ||
it('should not render user name', () => { | ||
cy.visit('/'); | ||
cy.get('.sc-navbar').should('not.exist'); | ||
cy.url(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************************** | ||
// This example plugins/index.js can be used to load plugins | ||
// | ||
// You can change the location of this file or turn off loading | ||
// the plugins file with the 'pluginsFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/plugins-guide | ||
// *********************************************************** | ||
|
||
// This function is called when a project is opened or re-opened (e.g. due to | ||
// the project's config changing) | ||
|
||
/** | ||
* @type {Cypress.PluginConfig} | ||
*/ | ||
module.exports = (on, config) => { | ||
// `on` is used to hook into various events Cypress emits | ||
// `config` is the resolved Cypress config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Cypress.Commands.add('kcLogin', (username, password) => { | ||
Cypress.log({ name: 'keycloak login' }); | ||
|
||
const kcUsername = username || Cypress.env('KEYCLOAK_USERNAME'); | ||
const kcPassword = password || Cypress.env('KEYCLOAK_PASSWORD'); | ||
const kcRoot = Cypress.env('KEYCLOAK_ROOT'); | ||
const kcRealm = Cypress.env('KEYCLOAK_REALM'); | ||
const kcClientID = Cypress.env('KEYCLOAK_CLIENT_ID'); | ||
|
||
if (!kcUsername || !kcPassword || !kcRoot || !kcRealm || !kcClientID) { | ||
throw new Error('missing CYPRESS_KEYCLOAK_USERNAME, CYPRESS_KEYCLOAK_PASSWORD, CYPRESS_KEYCLOAK_ROOT, CYPRESS_KEYCLOAK_REALM or CYPRESS_KEYCLOAK_CLIENT_ID environment variable'); | ||
} | ||
|
||
const getStartBody = { | ||
url: `${kcRoot}/auth/realms/${kcRealm}/protocol/openid-connect/auth`, | ||
followRedirect: false, | ||
qs: { | ||
scope: 'openid', | ||
response_type: 'code', | ||
approval_prompt: 'auto', | ||
redirect_uri: `${Cypress.config('baseUrl')}/login/callback`, | ||
client_id: kcClientID, | ||
}, | ||
}; | ||
return cy.request(getStartBody).then(response => { | ||
const html = document.createElement('html'); | ||
html.innerHTML = response.body; | ||
|
||
const form = html.getElementsByTagName('form')[0]; | ||
const url = form.action; | ||
const postLoginBody = { | ||
method: 'POST', | ||
url, | ||
followRedirect: false, | ||
form: true, | ||
body: { | ||
username: kcUsername, | ||
password: kcPassword, | ||
}, | ||
}; | ||
return cy.request(postLoginBody); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('kcLogout', () => { | ||
Cypress.log({ name: 'keycloak logout' }); | ||
|
||
const kcRoot = Cypress.env('KEYCLOAK_ROOT'); | ||
const kcRealm = Cypress.env('KEYCLOAK_REALM'); | ||
|
||
if (!kcRoot || !kcRealm) { | ||
throw new Error('missing CYPRESS_KEYCLOAK_ROOT and/or CYPRESS_KEYCLOAK_REALM environment variable'); | ||
} | ||
|
||
cy.clearSession(); | ||
return cy.request({ | ||
url: `${kcRoot}/auth/realms/${kcRealm}/protocol/openid-connect/logout`, | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('clearSession', () => { | ||
Cypress.log({ name: 'Clear Session' }); | ||
cy.window().then(window => window.sessionStorage.clear()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands'; | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
libgtk2.0-0 | ||
libgtk-3-0 | ||
libnotify-dev | ||
libgconf-2-4 | ||
libnss3 | ||
libxss1 | ||
libasound2 | ||
libxtst6 | ||
xauth | ||
xvfb |
1 change: 1 addition & 0 deletions
1
eve/workers/build/pensieve_packages.list → eve/workers/build/zenko_packages.list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
nodejs | ||
yarn=1.9.4-1 | ||
netcat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM jboss/keycloak:10.0.2 | ||
|
||
USER root | ||
|
||
# install jq | ||
RUN microdnf install wget | ||
RUN wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 | ||
RUN chmod +x ./jq | ||
RUN cp jq /usr/bin | ||
|
||
COPY keycloak-realm.json /config/keycloak-realm.json | ||
COPY entrypoint.sh / | ||
|
||
WORKDIR /config | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
CMD ["-b 0.0.0.0 -Dkeycloak.migration.action=import -Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=/config/keycloak-realm.json"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
# set -e stops the execution of a script if a command or pipeline has an error | ||
set -e | ||
|
||
# modifying keycloak-realm.json | ||
JQ_FILTERS_REALM="." | ||
|
||
if [[ "$KEYCLOAK_REALM" ]] ; then | ||
JQ_FILTERS_REALM="$JQ_FILTERS_REALM | .realm=\"$KEYCLOAK_REALM\"" | ||
fi | ||
|
||
if [[ "$KEYCLOAK_CLIENT_ID" ]] ; then | ||
JQ_FILTERS_REALM="$JQ_FILTERS_REALM | .clients[0].clientId=\"$KEYCLOAK_CLIENT_ID\"" | ||
fi | ||
|
||
if [[ "$KEYCLOAK_USERNAME" ]] ; then | ||
JQ_FILTERS_REALM="$JQ_FILTERS_REALM | .users[0].username=\"$KEYCLOAK_USERNAME\"" | ||
fi | ||
|
||
if [[ "$KEYCLOAK_USER_FIRSTNAME" ]] ; then | ||
JQ_FILTERS_REALM="$JQ_FILTERS_REALM | .users[0].firstName=\"$KEYCLOAK_USER_FIRSTNAME\"" | ||
fi | ||
|
||
if [[ "$KEYCLOAK_USER_LASTNAME" ]] ; then | ||
JQ_FILTERS_REALM="$JQ_FILTERS_REALM | .users[0].lastName=\"$KEYCLOAK_USER_LASTNAME\"" | ||
fi | ||
|
||
if [[ $JQ_FILTERS_REALM != "." ]]; then | ||
jq "$JQ_FILTERS_REALM" keycloak-realm.json > keycloak-realm.json.tmp | ||
mv keycloak-realm.json.tmp keycloak-realm.json | ||
fi | ||
|
||
# LAUNCH keycloak entrypoint | ||
/opt/jboss/tools/docker-entrypoint.sh $@ |
Oops, something went wrong.