Commit 866567c3cfd1a380a69b13c93f34b7a3ccf56f7a
1 parent
3f984279e5
Exists in
master
and in
2 other branches
Add keycloak failed auth test
Showing 1 changed file with 129 additions and 0 deletions
keycloak_test.groovy
View file @
866567c
1 | +/** | |
2 | +* Jenkinsfile to deploy multiple Docker containers based on docker-compose into a DEV server and run any test. | |
3 | +* This pipeline will run the Docker containers, execute the tests and then stop and remove the containers from the DEV | |
4 | +* server automatically. | |
5 | +**/ | |
6 | + | |
7 | + | |
8 | +pipeline { | |
9 | + | |
10 | + agent any | |
11 | + | |
12 | + environment { | |
13 | + // Keep as is the following two lines | |
14 | + PRIVATE_REGISTRY = "https://registry.curex-project.eu:443/curex-local/" | |
15 | + ARTIFACTORY_URL = "registry.curex-project.eu:443/curex-local/" | |
16 | + | |
17 | + HOST_IP = "116.203.166.220" | |
18 | + DEPLOYMENT_HOST = "${HOST_IP}:2376" | |
19 | + DEPLOYMENT_HOST_CREDENTIALS = "vm2-creds" | |
20 | + | |
21 | + // KEA specific | |
22 | + APP_NAME = "KEA" | |
23 | + APP_ENV = "production" | |
24 | + APP_DEBUG = "true" | |
25 | + APP_URL = "https://kea.curex-project.eu" | |
26 | + | |
27 | + KIBANA_PORT = "5601" | |
28 | + GRAFANA_PORT = "3000" | |
29 | + | |
30 | + LOG_CHANNEL = "stack" | |
31 | + | |
32 | + DB_CONNECTION = "pgsql" | |
33 | + DB_HOST = "timescaledb" | |
34 | + DB_PORT = "5432" | |
35 | + DB_DATABASE = "kea" | |
36 | + DB_USERNAME = "postgres" | |
37 | + DB_PASSWORD = "postgres" | |
38 | + | |
39 | + BROADCAST_DRIVER = "log" | |
40 | + CACHE_DRIVER = "file" | |
41 | + QUEUE_CONNECTION = "sync" | |
42 | + SESSION_DRIVER = "file" | |
43 | + SESSION_LIFETIME = "120" | |
44 | + | |
45 | + JWT_TTL = "1440" | |
46 | + | |
47 | + ELASTICSEARCH_HOST = "elasticsearch" | |
48 | + ELASTICSEARCH_PORT = "9200" | |
49 | + ELASTICSEARCH_SCHEME = "http" | |
50 | + | |
51 | + MQTT_HOST = "mosquitto" | |
52 | + MQTT_PORT = "1883" | |
53 | + MQTT_DEBUG = "false" | |
54 | + MQTT_QOS = "0" | |
55 | + MQTT_RETAIN = "0" | |
56 | + | |
57 | + MLTD_HOST = "mltd" | |
58 | + MLTD_PORT = "5000" | |
59 | + OD_HOST = "od" | |
60 | + OD_PORT = "9091" | |
61 | + | |
62 | + KEYCLOAK_REALM_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAg9OruW+gRnBcm4S1da+TDj7LdDXTFykExlg2z5Fx/vv4ldJf1/vCAEdSP/HZXRMq5TRefnkzVyv66COmjyPjGNB2P240HOOzBPnU5ibsu7H2betZvR+uj/y9o5T3hUpPy+Gbb02i57xoKyECy+yRtPjmF63R0rFfFBV/LdScWdnltTY7YfmRe6dRcBZG5QZ8bKTWP40QUzwG2PnJpIEi3KdYp4qDx4LvXnSvIC0Z6E59R2oialMKQtPO5Xu9Ea6fYe4guqX9zdpoC+bcvxjJ275zj+RoFVaQHhGBZDPeK4VITmXiUWkBbTGQwEVY8ZY4b62kWFwjOg9yOv47s6N7cQIDAQAB" | |
63 | + KEYCLOAK_LOAD_USER_FROM_DATABASE = "false" | |
64 | + KEYCLOAK_USER_PROVIDER_CREDENTIAL = "name" | |
65 | + KEYCLOAK_TOKEN_PRINCIPAL_ATTRIBUTE = "preferred_username" | |
66 | + KEYCLOAK_APPEND_DECODED_TOKEN = "false" | |
67 | + KEYCLOAK_ALLOWED_RESOURCES = "account" | |
68 | + | |
69 | + AUTH_ENABLED = "true" | |
70 | + } | |
71 | + | |
72 | + stages { | |
73 | + | |
74 | + stage('Checkout the source code') { | |
75 | + steps { | |
76 | + checkout scm | |
77 | + } | |
78 | + } | |
79 | + | |
80 | + | |
81 | + stage('Deploy Docker containers in DEV server') { | |
82 | + steps { | |
83 | + script { | |
84 | + docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") { | |
85 | + docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') { | |
86 | + echo 'Deploying the specified Docker containers in DEV server' | |
87 | + sh 'sh deploy_hetzner.sh' | |
88 | + } | |
89 | + } | |
90 | + } | |
91 | + } | |
92 | + } | |
93 | + | |
94 | + stage('Run tests') { | |
95 | + steps { | |
96 | + script { | |
97 | + echo '*************' | |
98 | + echo '*** TESTS ***' | |
99 | + echo '*************' | |
100 | + /* Here do your tests */ | |
101 | + sleep 90 | |
102 | + try { | |
103 | + String testName = "KEA_keycloak_fail" | |
104 | + String url = "$APP_URL/api/v1/od/status" | |
105 | + String responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true) | |
106 | + if ( responseCode != '401' ) { | |
107 | + error("$testName: Returned status code = $responseCode when calling $url") | |
108 | + } | |
109 | + } | |
110 | + } | |
111 | + } | |
112 | + } | |
113 | + | |
114 | + stage('Stop and remove the Docker containers in DEV server') { | |
115 | + steps { | |
116 | + script { | |
117 | + docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") { | |
118 | + docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') { | |
119 | + | |
120 | + //echo 'Stop and remove the specified Docker containers from the DEV server' | |
121 | + sh 'sh delete_hetzner.sh' | |
122 | + } | |
123 | + } | |
124 | + } | |
125 | + } | |
126 | + } | |
127 | + } | |
128 | +} |