From 0908ca0eaf7e46291c0ab540c500629e9295a3b9 Mon Sep 17 00:00:00 2001
From: Mark <mark@openappstack.net>
Date: Fri, 6 Dec 2019 18:13:26 +0100
Subject: [PATCH] Add more instructions

---
 test/login_logout/README.md | 85 +++++++++++++++++++++++++++++++++----
 1 file changed, 76 insertions(+), 9 deletions(-)

diff --git a/test/login_logout/README.md b/test/login_logout/README.md
index b3a914c..f5551e7 100644
--- a/test/login_logout/README.md
+++ b/test/login_logout/README.md
@@ -1,6 +1,36 @@
 This is a test application to verify that all of the components provided in this repository
 work together according to [OpenID Connect Standards](https://openid.net/developers/specs/)
 
+## Prerequisites
+
+The single sign-on application needs to be up and running. Instructions on how to accomplish
+that can be found in `../../README.md`.
+
+### Create oAuth Client
+You also need to create an oAuth2-Client to enable this application to communicate with the 
+oAuth server.
+
+To do that you can run the `create-hydra-client` script in this repository:
+```
+bash ../create-hydra-client.bash testapplication clientsecret http://localhost:4445 http://localhost:13337/callback
+```
+`http://localhost:4445` refers to the hydra-admin service. `http://localhost:13337/callback` is the
+callback address of the test application. Make sure it matches the address specified in `../../docker-compose.yml`
+> `serve all --dangerous-force-http --dangerous-allow-insecure-redirect-urls "http://localhost:13337/callback":`
+
+### Create users
+
+In the default setup, users can be created by executing the scripts contained in `../../user-panel/utils/`
+
+```
+bash ../../user-panel/utils/create-user.bash admin adminadmin admin@example.net
+bash ../../user-panel/utils/create-application.bash testapplication
+bash ../../user-panel/utils/grant-access.bash admin testapplication
+bash ../../user-panel/utils/create-role.bash admin
+bash ../../user-panel/utils/assign-role.bash admin admin
+```
+## Installation
+
 Install the requirements with:
 
 ```
@@ -9,22 +39,59 @@ virtualenv venv
 pip3 install -r requrements.txt
 ```
 
-Before running the application with `flask run --port=????`, make sure you export the following
-environment variables with values according to your setup.
+## Configuration
+
+Make sure you export the following
+environment variables with values according to your setup. Use the default values provided here
+if you run your setup locally.
 
 ```
-export BASE_URL=http://sso.oas.example.net:4444/ # Hydra public API Base
-export ACCESS_TOKEN_URL=http://sso.oas.example.net:4444/oauth2/token # Hydra token endpoint
-export LOGOUT_URL=http://sso.oas.example.net:4444/oauth2/sessions/logout # Hydra logout endpoint
-export AUTHORIZE_URL=http://sso.oas.example.net:4444/oauth2/auth # Hydra authentication endpoint
-export USERINFO_URL=http://sso.oas.example.net:4444/userinfo # Hydra OpenID Connect userinfo endpoint
+export BASE_URL=http://localhost:4444/ # Hydra public API Base
+export ACCESS_TOKEN_URL=http://localhost:4444/oauth2/token # Hydra token endpoint
+export LOGOUT_URL=http://localhost:4444/oauth2/sessions/logout # Hydra logout endpoint
+export AUTHORIZE_URL=http://localhost:4444/oauth2/auth # Hydra authentication endpoint
+export USERINFO_URL=http://localhost:4444/userinfo # Hydra OpenID Connect userinfo endpoint
 export KEY=testapplication # name of your oauth/openID Connect client (application)
 export SECRET=clientsecret # secret of yout oauth/openID Connect client (application)
 ```
 
-Navigate to `localhost:port/` to trigger the openID connect authentication flow. During the login
+
+## Run the tests
+Start the application with:
+```
+flask run --port=13337
+```
+Navigate to `http://localhost:13337/` to trigger the openID connect authentication flow. During the login
 process your agent's browser will be redirected multiple times. If successful, you will see a
 json reply containing your oAuth token.
 
-Navigate to `localhost:port/userinfo` after you received the token to pull userinfo via openID
+Navigate to `http://localhost:13337/userinfo` after you received the token to pull userinfo via openID
 Connect scopes.
+
+### Run auto tests
+
+Run the following commands to run the tests
+```
+export TESTUSER_USERNAME=user
+export TESTUSER_PASSWORD=secret
+export TESTUSER_USERNAME2=user2
+export TESTUSER_EMAIL=test@example.net
+export ROLE=admin
+bash ../../user-panel/utils/create-user.bash $TESTUSER_USERNAME $TESTUSER_PASSWORD $TESTUSER_EMAIL
+bash ../../user-panel/utils/create-user.bash $TESTUSER_USERNAME2 RANDOMPW $TESTUSER_EMAIL
+bash ../../user-panel/utils/create-application.bash testapplication
+bash ../../user-panel/utils/grant-access.bash $TESTUSER_USERNAME testapplication
+bash ../../user-panel/utils/create-role.bash $ROLE
+bash ../../user-panel/utils/assign-role.bash $TESTUSER_USERNAME $ROLE
+python3 -m behave \
+-D headless=True \
+-D url=http://localhost:13337 \
+-D logout_url=http://localhost:5000/logout \
+-D userinfo_url=http://localhost:4444/userinfo \
+-D username=${TESTUSER_USERNAME} \
+-D username2=${TESTUSER_USERNAME2} \
+-D password=${TESTUSER_PASSWORD} \
+-D email=${TESTUSER_EMAIL} \
+-D role=${ROLE}
+```
+Note: You need to have chromedriver isntalled to run the tests
-- 
GitLab