-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added keycloak integration test #342
Draft
ricklambrechts
wants to merge
9
commits into
jumbojett:master
Choose a base branch
from
ricklambrechts:keycloak-integration-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
afd5af2
Added keycloak service
ricklambrechts ea131d2
Added create realm and user
ricklambrechts 65f89b7
Added create client
ricklambrechts 73393ed
Added makefile
ricklambrechts 4f9cca6
Use make file and added simple client secret test application
ricklambrechts b9d9a87
Added cypress
ricklambrechts d91acd7
Added cypress to github action
ricklambrechts 7250b9f
Upload cypress artifacts
ricklambrechts 34d251a
Added cypress commands in packages json
ricklambrechts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
name: Keycloak Integration Tests | ||
|
||
on: [ push, pull_request ] | ||
|
||
env: | ||
DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi" | ||
|
||
jobs: | ||
integration-tests: | ||
name: PHP ${{ matrix.php }} on ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
php: [ '8.0' ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
- name: Get composer cache directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
- name: Cache composer dependencies | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: Install dependencies | ||
run: composer update $DEFAULT_COMPOSER_FLAGS | ||
- name: Start keycloak | ||
run: | | ||
cd .github/workflows/keycloak | ||
make docker-up | ||
echo "Waiting for Keycloak to start..." | ||
sleep 10 # Wait for keycloak to start because of please wait in logs | ||
./wait-for-keycloak.sh http://localhost:8080/realms/master | ||
- name: Echo logs of keycloak | ||
run: | | ||
cd .github/workflows/keycloak | ||
docker-compose logs --tail all keycloak | ||
- name: Create custom realm, user and client | ||
run: | | ||
cd .github/workflows/keycloak | ||
make keycloak-create-test-realm | ||
- name: Run simple test application | ||
run: | | ||
cd .github/workflows/keycloak | ||
make serve-test-application > /dev/null 2>&1 & | ||
- name: Run integration tests | ||
uses: cypress-io/github-action@v4 | ||
with: | ||
working-directory: .github/workflows/keycloak | ||
browser: chrome | ||
- uses: actions/upload-artifact@v2 | ||
if: failure() | ||
with: | ||
name: cypress-screenshots | ||
path: .github/workflows/keycloak/cypress/screenshots | ||
- uses: actions/upload-artifact@v2 | ||
if: always() | ||
with: | ||
name: cypress-videos | ||
path: .github/workflows/keycloak/cypress/videos |
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,30 @@ | ||
# Suppresses Make-specific output. Remove for more debugging info. | ||
.SILENT: | ||
|
||
# Variables | ||
KCADM = /opt/keycloak/bin/kcadm.sh | ||
DOCKER_EXEC = docker-compose exec -T keycloak | ||
|
||
# Commands | ||
all: help | ||
|
||
help: ## Display available commands | ||
echo "Available make commands:" | ||
echo | ||
grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
docker-up: ## Start Keycloak | ||
docker-compose up -d | ||
|
||
docker-down: ## Stop Keycloak | ||
docker-compose down | ||
|
||
keycloak-create-test-realm: ## Create test realm | ||
$(DOCKER_EXEC) $(KCADM) config credentials --server http://localhost:8080 --realm master --user admin --password admin --client admin-cli | ||
$(DOCKER_EXEC) $(KCADM) create realms -s realm="testrealm" -s id="testrealm" -s enabled=true | ||
$(DOCKER_EXEC) $(KCADM) create users -r testrealm -s username=testuser -s enabled=true -s firstName=John -s lastName=Doe | ||
$(DOCKER_EXEC) $(KCADM) set-password -r testrealm --username testuser --new-password testpassword | ||
$(DOCKER_EXEC) $(KCADM) create clients -r testrealm -s clientId=testclient -s enabled=true -s clientAuthenticatorType=client-secret -s secret=testsecret -s 'redirectUris=["http://localhost:8000/*"]' -i | ||
|
||
serve-test-application: ## Serve test application | ||
php -S localhost:8000 tests/client-secret-test.php |
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,11 @@ | ||
const { defineConfig } = require("cypress"); | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
experimentalStudio: true, | ||
experimentalSessionAndOrigin: true, | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}); |
29 changes: 29 additions & 0 deletions
29
.github/workflows/keycloak/cypress/e2e/client-secret-test.cy.js
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 @@ | ||
describe('client secret test', () => { | ||
it( | ||
'can visit the application and can sign in', | ||
{ | ||
env: { | ||
app_url: 'http://localhost:8000', | ||
} | ||
}, | ||
() => { | ||
// Visit the test application, the application should redirect to the login page | ||
cy.visit(Cypress.env('app_url')) | ||
|
||
// Now we should be on the login page, we can check the url if it includes realms | ||
cy.url().should('include', '/realms/') | ||
|
||
// Set username and password and login | ||
cy.get('#username').clear('testuser'); | ||
cy.get('#username').type('testuser'); | ||
cy.get('#password').clear(); | ||
cy.get('#password').type('testpassword'); | ||
cy.get('#kc-login').click(); | ||
|
||
// After login, we are redirected back to the application | ||
cy.url().should('contain', Cypress.env('app_url')) | ||
|
||
// We should see the username. | ||
cy.contains('Hi John Doe') | ||
}) | ||
}) |
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,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "[email protected]", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
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,25 @@ | ||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) |
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/e2e.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3' | ||
|
||
services: | ||
keycloak: | ||
image: quay.io/keycloak/keycloak:latest | ||
environment: | ||
KEYCLOAK_ADMIN: admin | ||
KEYCLOAK_ADMIN_PASSWORD: admin | ||
ports: | ||
- 8080:8080 | ||
command: start-dev |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why redirecting the outputs to /dev/null? When everything is fine you surely don't need it, but this might be useful to debug when things are broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could indeed save the output as a kind of debug log., thanks.