From 1aaa0d399c3660af699262e9ca2d382e82828415 Mon Sep 17 00:00:00 2001
From: Mark <mark@openappstack.net>
Date: Thu, 26 Sep 2019 14:45:25 +0200
Subject: [PATCH] Add integration test to pipeline

---
 .gitlab-ci.yml | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4bbf9ca..0290f10 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,6 +2,7 @@ stages:
   - build
   - build-testimages
   - application-test
+  - integration-test
 
 consent-provider:
   stage: build
@@ -103,3 +104,77 @@ behave-login:
     changes:
       - login_provider/**/*
       - .gitlab-ci.yml
+
+behave-integration:
+  stage: integration-test
+  services:
+    - name: postgres:latest
+      alias: postgres
+    - name: ${CI_REGISTRY_IMAGE}/login_provider:${CI_COMMIT_REF_NAME}
+      alias: login
+    - name: ${CI_REGISTRY_IMAGE}/consent_provider:${CI_COMMIT_REF_NAME}
+      alias: consent
+    - name: oryd/hydra:latest
+      alias: hydra
+      command:
+        - serve
+        - all
+        - --dangerous-force-http
+        - --dangerous-allow-insecure-redirect-urls
+        - http://oauth:5000/callback
+    - name: open.greenhost.net:4567/openappstack/user-panel:integration
+      alias: backend
+    - name: ${CI_REGISTRY_IMAGE}/login_logout:${CI_COMMIT_REF_NAME}
+      alias: oauth
+  variables:
+    # Gitlab CI does not propagate service names to service containers
+    # it assigns addresses incrementally starting from 172.17.0.2
+    # in the order that the services are started which is the order of
+    # the services listed in the job configuration
+    DATABASE_HOST: "172.17.0.2" # 172.17.0.2 -> postgres
+    URLS_LOGIN: "http://172.17.0.3:5000/" # 172.17.0.3 -> login
+    URLS_LOGOUT: "http://172.17.0.3:5000/logout"
+    URLS_CONSENT: "http://172.17.0.4:5001/" # 172.17.0.4 -> consent
+    URLS_SELF_ISSUER: "http://172.17.0.5:4444/" # 172.17.0.5 -> hydra
+    HYDRA_ADMIN_URL: "http://172.17.0.5:4445"
+    BASE_URL: "http://172.17.0.5:4444"
+    ACCESS_TOKEN_URL: "http://172.17.0.5:4444/oauth2/token"
+    AUTHORIZE_URL: "http://172.17.0.5:4444/oauth2/auth"
+    GRAPHQL_URL: "http://172.17.0.6:5000/graphql" # 172.17.0.6 -> backend
+    GIT_SUBMODULE_STRATEGY: "recursive"
+    TESTUSER_USERNAME: "testuser"
+    TESTUSER_PASSWORD: "password"
+    TESTUSER_EMAIL: "testuser@example.net"
+    DSN: "memory"
+    SECRETS_SYSTEM: "youReallyNeedToChangeThis"
+    OIDC_SUBJECT_TYPES_SUPPORTED: "public,pairwise"
+    OIDC_SUBJECT_TYPE_PAIRWISE_SALT: "youReallyNeedToChangeThis"
+    DATABASE_USER: postgres
+    DATABASE_PASSWORD: secret
+    DATABASE_NAME: postgres
+    POSTGRES_PASSWORD: secret
+    POSTGRES_USER: postgres
+    POSTGRES_DB: postgres
+    OAUTHLIB_INSECURE_TRANSPORT: "true"
+    KEY: "testapp"
+    SECRET: "secret"
+    DEBUG: "true"
+    FLASK_ENV: "development"
+  image: ${CI_REGISTRY_IMAGE}/integration_ci_test:${CI_COMMIT_REF_NAME}
+  script:
+    - echo "WAIT FOR SERVICES TO INITIALIZE" && sleep 20
+    - /bin/sh user-panel/utils/create-user.sh ${TESTUSER_USERNAME} ${TESTUSER_PASSWORD} ${TESTUSER_EMAIL} backend 5000
+    - /bin/sh user-panel/utils/create-application.sh ${KEY} backend 5000
+    - /bin/sh user-panel/utils/grant-access.sh ${TESTUSER_USERNAME} ${KEY} backend 5000
+    - /bin/sh test/create-hydra-client.sh ${KEY} ${SECRET} hydra 4445 http://oauth:5000/callback
+    - cd test/login_logout/test/behave/
+    - python3 -m behave -D headless=True -D url=http://oauth:5000 -D username=${TESTUSER_USERNAME} -D password=${TESTUSER_PASSWORD}
+  artifacts:
+    paths:
+      - test/login_logout/test/behave/screenshots/
+    expire_in: 1 month
+    when: on_failure
+  only:
+    changes:
+      - login_provider/**/*
+      - .gitlab-ci.yml
-- 
GitLab