Skip to content
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

Restore the Stepup E2E behat tests #9

Merged
merged 38 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ef0a3f1
Mariadb: Add the test databases and provide access to them
quartje Dec 20, 2023
d1d38bc
Add tests from Stepup-deploy
quartje Dec 20, 2023
af31ea7
Introduce STEPUP_VERSION and APP_ENV vars
quartje Dec 20, 2023
16ea1f7
Add github action to build a behat container
quartje Dec 21, 2023
a4d7983
Add env.test file for smoketesting
quartje Dec 21, 2023
95371d7
Add docker compose behat override
quartje Dec 21, 2023
32aded6
Add behat documentation
quartje Dec 21, 2023
15e324b
Create a simple behat test runner
MKodde Jan 16, 2024
5442cb3
Start work on running the behat tests
MKodde Jan 17, 2024
8d080a7
Make the start-dev-env aware of the test environment. If .env contain…
quartje Jan 17, 2024
bfd7c7d
Get the selfservice.feature back up and running
MKodde Jan 18, 2024
d1527f5
Update start-dev-en-sh script
MKodde Feb 7, 2024
3436e87
Include SelfService SAT tests
MKodde Feb 8, 2024
d2244d8
Update identity.feature expectations
MKodde Feb 8, 2024
53ea8c7
Skip all failin tests
MKodde Feb 8, 2024
75fdcb8
Repair the sso.feature
MKodde Feb 8, 2024
15759ac
Skip sfo.feature for now
MKodde Feb 8, 2024
a8f4f05
Repair self_vet.feature
MKodde Feb 8, 2024
73b1bde
Repair ra_vet.feature
MKodde Feb 8, 2024
5e09e49
Repair ra.feature
MKodde Feb 8, 2024
ec8c495
WIP ra_export.feature
MKodde Feb 8, 2024
53bbbb2
Enable FGA use cases
MKodde Feb 8, 2024
2b127e7
Enable and repair fga-use-case-c.feature
MKodde Feb 12, 2024
f7d960a
Repair the ra_candidate features
MKodde Feb 12, 2024
698c176
Open up port 3306 to the mariadb host
MKodde Feb 14, 2024
e66ee7b
Repair the ra_export.feature
MKodde Feb 15, 2024
d916bfe
Optimize start-dev-env.sh
MKodde Feb 19, 2024
5d3a35a
Repair ra_grants.feature
MKodde Feb 19, 2024
96c490b
Refine ra_insitution-configuration.feature
MKodde Feb 19, 2024
f6264d3
Re enable the ra_locations feature
MKodde Feb 19, 2024
456d447
Re enable ra_login-exception.feature
MKodde Feb 19, 2024
40f799b
Repair ra_multiple_tokens feature
MKodde Feb 19, 2024
adbb180
Enable ra_profile.feature
MKodde Feb 19, 2024
384efca
Enable ra_select-raa features
MKodde Feb 19, 2024
24d7a54
Behat Docker fixes
quartje Feb 19, 2024
18985e7
Run Behat tests on Github Actions workflow
MKodde Feb 20, 2024
3606c0f
Optimize start-dev-env.sh
MKodde Feb 21, 2024
d76935a
Update README.md
MKodde Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/build-push-test-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: build-push-test-docker-image

on:
workflow_dispatch:

jobs:
build-push-test-docker-image:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set docker labels and tags
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/openconext/OpenConext-devconf/OpenConext-devconf
flavor: |
latest=false
suffix=-test
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=sha
type=raw,suffix=,value=test

- name: Build and push the TEST image
uses: docker/build-push-action@v5
with:
context: .
file: stepup/tests/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
43 changes: 43 additions & 0 deletions .github/workflows/stepup-behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: stepup-behat
on:
pull_request:
push:
branches: [ main, feature/*, bugfix/* ]
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
env:
DOCKER_COMPOSE: docker compose -f docker-compose.yml -f docker-compose-behat.yml
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Init environment
run: |
cd stepup
cp .env.test .env
cp gateway/surfnet_yubikey.yaml.dist gateway/surfnet_yubikey.yaml
${DOCKER_COMPOSE} up -d
- name: Install composer dependencies on the Behat container
run: |
cd stepup
${DOCKER_COMPOSE} exec -T behat bash -lc "composer install --ignore-platform-reqs -n"
- name: Sleep for 10 seconds
run: sleep 10s
- name: Run Behat tests
run: |
cd stepup
docker exec -t stepup-behat-1 bash -lc "./behat"
- name: Output logs on failure
if: failure()
run: |
cd stepup
${DOCKER_COMPOSE} logs
2 changes: 2 additions & 0 deletions stepup/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_ENV=smoketest
STEPUP_VERSION:test
64 changes: 64 additions & 0 deletions stepup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,70 @@ To mount the code in multiple containers:
You can add as many services+local code paths that you need.
The recommended way is to use absolute paths and the script requires the name of the service and local code path to be separated by a `:`, for each service.

# Accessing the database from your IDE
The Maria DB container exposes her 3306 port to the outside. So you should be able to connect to the database with
your favorite DBA tool. In PHPStorm I was able to connect to the `mariadb` host by using these setting.

```
host: localhost
user: root
password: you know the secret ;)
```

# PHP 8.2 for development
The default development container is based on the base image with PHP7.2. You can override this on a per service basis. Uncomment the appropiate line for this in the file ".env" so it uses the PHP8.2 container. An .env.dist is included that you can use to have your own .env. file. .env is in .gitigore so you can make your own changes.

# Functional testing
The stepup application suite comes with a set of Behat (Gherkin) features. These features test the stepup applications
functionally. These tests range from simple smoketests (can we still vet a token), to more bug report driven
functional tests. And everything in between.

These tests live in this folder: `stepup/tests/behat/features`

Custom Contexts where created to perform Stepup specific actions. Some details about these contexts can be read about below.

## Running the tests
1. The tests are automatically triggered on GitHub Actions when building a Pull Request. The action is named: [`stepup-behat`](https://github.com/OpenConext/OpenConext-devconf/actions/workflows/stepup-behat.yml)
2. Run them manually.

Step two can be achieved by following these actions.

1: You must instruct the `devconf` environment that you want to run functional tests.
1. Option 1: Copy the `.env.test` to be the `.env`
2. Option 2: Add these two lines to your existing `.env` file

```shell
APP_ENV=smoketest
STEPUP_VERSION=test
```

2: Next you should start the devconf containers in test mode
1. `$ ./start-dev-env.sh` will start the environment using test images for every component.
2. `$ ./start-dev-env.sh selfservice:/path/to/SelfService` to start certain components with local code mounted (useful during development)
3. Choose if you want to run the containers in the back- or foreground.

3: Once the containers are up and running, you can run the behat tests
1. Open a shell in the `behat` container `$ docker exec -it stepup-behat-1 bash`
2. Run the tests:
1. `./behat` will run all available behat tests that are not excluded using the `@SKIP` tag
2. `./behat features/ra.feature` will only run the `ra.feature` found in the features folder
3. `./behat features/ra.feature:20` will only run the scenario found on line 20 of the `ra.feature`
4. TODO: `./behat --filter=selfservice` will only run features marked with the `@selfservice` tag

## Writing tests
Many of the step definitions are coded in our own Contexts. These contexts are divided into five main contexts.
It should be straightforward where to add new definitions. The contexts are not following all the clean code or solid principles. This code is messy, be warned.

It can be useful during debugging to use the `$this->diePrintingContent();` statement. This outputs the URI of the browser, and the last received html response. As it is hard to step debug the code that is run in a CURL based browser.

TODO: Mark your tests with at least one of the pre-defined tags:

`selfservice`
`ra`
`gateway`
`middleware`
`tiqr`
`demogssp`
`webauthn`

Note that these tags match the `devconf` names given to the different components.
2 changes: 1 addition & 1 deletion stepup/azuremfa/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ services:
volumes:
- ${AZUREMFA_CODE_PATH}:/var/www/html
environment:
- APP_ENV=dev
- APP_ENV=${APP_ENV:-dev}
- APP_DEBUG=true
14 changes: 14 additions & 0 deletions stepup/dbschema/createdbs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@ CREATE DATABASE IF NOT EXISTS webauthn;
CREATE DATABASE IF NOT EXISTS tiqr;
CREATE DATABASE IF NOT EXISTS gateway;
CREATE DATABASE IF NOT EXISTS middleware;
CREATE DATABASE IF NOT EXISTS webauthn_test;
CREATE DATABASE IF NOT EXISTS tiqr_test;
CREATE DATABASE IF NOT EXISTS gateway_test;
CREATE DATABASE IF NOT EXISTS middleware_test;

CREATE USER IF NOT EXISTS 'webauthn_user'@'%' IDENTIFIED BY 'webauthn_secret';
GRANT ALL PRIVILEGES ON webauthn.* TO 'webauthn_user'@'%';
GRANT ALL PRIVILEGES ON webauthn_test.* TO 'webauthn_user'@'%';

CREATE USER IF NOT EXISTS 'tiqr_user'@'%' IDENTIFIED BY 'tiqr_secret';
GRANT ALL PRIVILEGES ON tiqr.* TO 'tiqr_user'@'%';
GRANT ALL PRIVILEGES ON tiqr_test.* TO 'tiqr_user'@'%';

CREATE USER IF NOT EXISTS 'gateway_user'@'%' IDENTIFIED BY 'gateway_secret';
GRANT SELECT ON gateway.* TO 'gateway_user'@'%';
GRANT SELECT ON gateway_test.* TO 'gateway_user'@'%';

CREATE USER IF NOT EXISTS 'middleware_user'@'%' IDENTIFIED BY 'middleware_secret';
GRANT SELECT,INSERT,DELETE,UPDATE ON middleware.* TO 'middleware_user'@'%';
GRANT SELECT,INSERT,DELETE,UPDATE ON middleware_test.* TO 'middleware_user'@'%';

CREATE USER IF NOT EXISTS 'mw_gateway_user'@'%' IDENTIFIED BY 'mw_gateway_secret';
GRANT SELECT,INSERT,DELETE,UPDATE ON gateway.* TO 'mw_gateway_user'@'%';
GRANT SELECT,INSERT,DELETE,UPDATE ON middleware.* TO 'middleware_user'@'%';
GRANT SELECT,INSERT,DELETE,UPDATE ON gateway_test.* TO 'mw_gateway_user'@'%';
GRANT SELECT,INSERT,DELETE,UPDATE ON middleware_test.* TO 'middleware_user'@'%';

CREATE USER IF NOT EXISTS 'mw_deploy_user'@'%' IDENTIFIED BY 'mw_deploy_secret';
GRANT ALL PRIVILEGES ON gateway.* TO 'mw_deploy_user'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON middleware.* TO 'mw_deploy_user'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON gateway_test.* TO 'mw_deploy_user'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON middleware_test.* TO 'mw_deploy_user'@'%' WITH GRANT OPTION;

CREATE USER IF NOT EXISTS 'gw_deploy_user'@'%' IDENTIFIED BY 'gw_deploy_secret';
GRANT ALL PRIVILEGES ON gateway.* TO 'gw_deploy_user'@'%';
GRANT ALL PRIVILEGES ON gateway_test.* TO 'gw_deploy_user'@'%';
2 changes: 1 addition & 1 deletion stepup/demogssp/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ services:
volumes:
- ${DEMOGSSP_CODE_PATH}:/var/www/html
environment:
- APP_ENV=dev
- APP_ENV=${APP_ENV:-dev}
- APP_DEBUG=true
13 changes: 13 additions & 0 deletions stepup/docker-compose-behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:

behat:
image: ghcr.io/openconext/openconext-devconf/openconext-devconf:test
environment:
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
- ${PWD}/:/config
- /var/run/docker.sock:/var/run/docker.sock
56 changes: 37 additions & 19 deletions stepup/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,47 @@ services:
openconextdev:
aliases:
- ra.dev.openconext.local
- ssp.dev.openconext.local
- selfservice.dev.openconext.local
- middleware.dev.openconext.local
- gateway.dev.openconext.local
- demogssp.dev.openconext.local
- webauthn.dev.openconext.local
- tiqr.dev.openconext.local
- mailcatcher.dev.openconext.local
hostname: haproxy.docker



mariadb:
image: mariadb:10.6
environment:
MYSQL_ROOT_PASSWORD: secret
ports:
- 3306:3306
networks:
openconextdev:
volumes:
- ${PWD}/dbschema:/docker-entrypoint-initdb.d
- stepup_mariadb:/var/lib/mysql
hostname: mariadb.docker

behat:
image: ghcr.io/openconext/openconext-devconf/openconext-devconf:test
environment:
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
- ${PWD}/:/config
- /var/run/docker.sock:/var/run/docker.sock

webauthn:
image: ghcr.io/openconext/stepup-webauthn/stepup-webauthn:prod
image: ghcr.io/openconext/stepup-webauthn/stepup-webauthn:${STEPUP_VERSION:-prod}
ports:
- 8080:8080
environment:
DATABASE_URL: "mysql://webauthn_user:webauthn_secret@mariadb:3306/webauthn"
APP_ENV: prod
- APP_ENV=${APP_ENV:-prod}
volumes:
- ${PWD}/:/config
networks:
Expand All @@ -51,9 +69,9 @@ services:


middleware:
image: ghcr.io/openconext/stepup-middleware/stepup-middleware:prod
image: ghcr.io/openconext/stepup-middleware/stepup-middleware:${STEPUP_VERSION:-prod}
environment:
- APP_ENV=prod
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
Expand All @@ -63,9 +81,9 @@ services:
hostname: middleware.docker

gateway:
image: ghcr.io/openconext/stepup-gateway/stepup-gateway:prod
image: ghcr.io/openconext/stepup-gateway/stepup-gateway:${STEPUP_VERSION:-prod}
environment:
- APP_ENV=prod
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
Expand All @@ -77,9 +95,9 @@ services:


ra:
image: ghcr.io/openconext/stepup-ra/stepup-ra:prod
image: ghcr.io/openconext/stepup-ra/stepup-ra:${STEPUP_VERSION:-prod}
environment:
- APP_ENV=prod
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
Expand All @@ -89,9 +107,9 @@ services:
hostname: ra.docker

selfservice:
image: ghcr.io/openconext/stepup-selfservice/stepup-selfservice:prod
image: ghcr.io/openconext/stepup-selfservice/stepup-selfservice:${STEPUP_VERSION:-prod}
environment:
- APP_ENV=prod
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
Expand All @@ -101,41 +119,41 @@ services:
hostname: selfservice.docker

demogssp:
image: ghcr.io/openconext/stepup-gssp-example/stepup-gssp-example:prod
image: ghcr.io/openconext/stepup-gssp-example/stepup-gssp-example:${STEPUP_VERSION:-prod}
environment:
- APP_ENV=prod
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
- ${PWD}/:/config
extra_hosts:
- "host.docker.internal:host-gateway"
hostname: demogssp.docker

tiqr:
image: ghcr.io/openconext/stepup-tiqr/stepup-tiqr:prod
environment:
- APP_ENV=prod
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
- ${PWD}/:/config
extra_hosts:
- "host.docker.internal:host-gateway"
hostname: tiqr.docker

azuremfa:
image: ghcr.io/openconext/stepup-azuremfa/stepup-azuremfa:prod
image: ghcr.io/openconext/stepup-azuremfa/stepup-azuremfa:${STEPUP_VERSION:-prod}
environment:
- APP_ENV=prod
- APP_ENV=${APP_ENV:-prod}
networks:
openconextdev:
volumes:
- ${PWD}/:/config
extra_hosts:
- "host.docker.internal:host-gateway"
hostname: azuremfa.docker

mailcatcher:
image: sj26/mailcatcher:latest
ports:
Expand Down
Loading
Loading