Skip to content

Commit

Permalink
add keycloak test in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
sam committed Feb 23, 2024
1 parent 5dd364c commit 117db0b
Show file tree
Hide file tree
Showing 9 changed files with 2,670 additions and 242 deletions.
2,610 changes: 2,610 additions & 0 deletions .docker/keycloak/config/realm-export.localhost.json

Large diffs are not rendered by default.

227 changes: 0 additions & 227 deletions .env.oidc

This file was deleted.

10 changes: 5 additions & 5 deletions .env.oidc.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SYMFONY_ENV='test'
APP_SECRET='$ecretf0rt3st'
PHP_USER='www-data'
PHP_IDE_CONFIG='serverName=membres.yourcoop.local'
PHP_IDE_CONFIG='serverName=localhost'
PHP_MEMORY_LIMIT=512M
PHP_SERVICE_NAME='php7.4-fpm'
###> symfony/framework-bundle ###
Expand Down Expand Up @@ -59,8 +59,8 @@ EMAILS_NOREPLY_NAME='Ne pas répondre'
[email protected]

# Router Configuration
ROUTER_REQUEST_CONTEXT_HOST=membres.yourcoop.local
ROUTER_REQUEST_CONTEXT_SCHEME=https
ROUTER_REQUEST_CONTEXT_HOST=localhost
ROUTER_REQUEST_CONTEXT_SCHEME=http
ROUTER_REQUEST_CONTEXT_BASE_URL=

# Security: IP check
Expand Down Expand Up @@ -184,9 +184,9 @@ LOGGING_MATTERMOST_CHANNEL=elefan

# Open ID Client
OIDC_ENABLE=true
OIDC_PROFILE_CUSTOM_MESSAGE='vos informations personnelles sont éditables <a href="http://membres.yourcool.local:8080/"> ici </a>'
OIDC_PROFILE_CUSTOM_MESSAGE='vos informations personnelles sont éditables <a href="http://localhost:8080/"> ici </a>'
OIDC_NO_ACCOUNT_MESSAGE="Vous n\'avez pas de compte. Veuillez contacter le support."
OIDC_ISSUER=http://keycloak:8080/auth
OIDC_ISSUER=http://localhost:8080/auth
OIDC_REALM=elefan
OIDC_CLIENT_ID=elefan
OIDC_CLIENT_SECRET=secret
Expand Down
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ LOGGING_MATTERMOST_CHANNEL=elefan
OIDC_ENABLE=false
OIDC_PROFILE_CUSTOM_MESSAGE='vos informations personnelles sont éditables <a href="http://membres.yourcool.local:8080/"> ici </a>'
OIDC_NO_ACCOUNT_MESSAGE="Vous n\'avez pas de compte. Veuillez contacter le support."
OIDC_ISSUER=http://keycloak:8080/auth
OIDC_ISSUER=http://localhost:8080/auth
OIDC_REALM=elefan
OIDC_CLIENT_ID=elefan
OIDC_CLIENT_SECRET=secret
Expand Down
40 changes: 39 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,42 @@ jobs:

# RUN CYPRESS TESTS ----------------
- name: Run Cypress tests
run: npm run cy:test:main
run: CYPRESS_BASE_URL=http://localhost:8000 npm run cy:test:main


# CHANGE ENV VARIABLES ----------------
- name: Set up test environment variables
run: cp .env.oidc.test .env.test

# START KEYCLOAK ----------------
- name: Start Keycloak
run: |
docker run -d \
--name keycloak \
-e KEYCLOAK_USER=admin \
-e KEYCLOAK_PASSWORD=admin \
-e DB_VENDOR=h2 \
-e KEYCLOAK_IMPORT=/config/realm-export.json \
-v ${{ github.workspace }}/.docker/keycloak/config/realm-export.localhost.json:/config/realm-export.json \
-p 8080:8080 \
--user root \
jboss/keycloak:16.1.1
# Wait for Keycloak to start
- name: Wait for Keycloak to be ready
run: |
until $(curl --output /dev/null --silent --head --fail http://localhost:8080/auth); do
printf '.'
sleep 5
done
# RUN CYPRESS TESTS ----------------
- name: Run Cypress keycloak tests
uses: cypress-io/github-action@v6
with:
start: npm run cy:test:oidc
env:
CYPRESS_BASE_URL: http://localhost:8000
CYPRESS_KEYCLOAK_URL: http://localhost:8080


3 changes: 3 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ module.exports = defineConfig({
viewportWidth: 1920,
viewportHeight: 1080,
},
env: {
keycloakUrl: 'http://localhost:8080',
},
});
6 changes: 4 additions & 2 deletions cypress/e2e/keycloak/admin/admin1_can_login.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


// temporarily disable uncaught exception handling
import {login} from "../keycloak_reusables";
import {login} from "../keycloak_reusables.cytools";

const keycloakUrl = Cypress.env('keycloakUrl') || 'http://localhost:8080'

Cypress.on('uncaught:exception', (err, runnable) => {
return false
Expand All @@ -11,7 +13,7 @@ Cypress.on('uncaught:exception', (err, runnable) => {
describe('admin1 can login', function () {
it('admin story', function () {

login("admin1", "password")
login(keycloakUrl, "admin1", "password")

cy.log('home page banner contains "admin"')
cy.get('[data-cy=home_welcome_message]').contains('admin')
Expand Down
10 changes: 6 additions & 4 deletions cypress/e2e/keycloak/keycloak_reusables.cytools.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export function login(username, password) {

export function login(keycloakUrl, username, password) {

cy.visit("/")
cy.get('#login').click()

cy.origin('http://keycloak:8080', { args : { username, password }}, ({ username, password }) => {
console.log(Cypress.config());
console.log(Cypress.env());
cy.origin(keycloakUrl, { args : { username, password }}, ({ username, password }) => {
cy.log("fill in the login form")
cy.get('#username').type(username, {force: true})
cy.get('#password').type(password, {force: true})
Expand All @@ -12,7 +14,7 @@ export function login(username, password) {
cy.get('#kc-login').click()

cy.location().then((location) => {
if (location !== null && location.origin === 'http://keycloak:8080') {
if (location !== null && location.origin === keycloakUrl) {
cy.get('#kc-login').click()
} else {
cy.log("not asked for access to user data")
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"watch": "encore dev --watch",
"build": "npx encore production --progress",
"cy:open": "cypress open",
"cy:test:oidc": "CYPRESS_BASE_URL=http://127.0.0.1:8000 cypress run --spec 'cypress/e2e/oidc/*'",
"cy:test:main": "CYPRESS_BASE_URL=http://localhost:8000 cypress run --spec 'cypress/e2e/login/**/*'"
"cy:test:oidc": "cypress run --spec 'cypress/e2e/keycloak/**/*'",
"cy:test:main": "cypress run --spec 'cypress/e2e/login/**/*'"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 117db0b

Please sign in to comment.