Commit 7f2cc895fccb130904c89700fcc133d468b88947

Authored by George Vlahavas
1 parent d9d40e537d

Add KEA-TIE integration test

Showing 1 changed file with 66 additions and 0 deletions

kea_integration.groovy View file @ 7f2cc89
  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 +
  14 + APP_URL = "https://kea.curex-project.eu"
  15 + KEYCLOAK_URL = "https://keycloak-curex.gnubila.fr/auth/realms/Integration/protocol/openid-connect/token"
  16 + USER = credentials('keycloak-test-user')
  17 + PASSWORD = credentials('keycloak-test-password')
  18 + CLIENT_ID = "KEA"
  19 +
  20 + }
  21 +
  22 + stages {
  23 +
  24 + stage('Run tests') {
  25 + steps {
  26 + script {
  27 + echo '*************'
  28 + echo '*** TESTS ***'
  29 + echo '*************'
  30 + /* Here do your tests */
  31 + try {
  32 + // Get Keycloak auth token
  33 + String token = sh(label: "get_keycloak_token", script: "curl -s -X POST $KEYCLOAK_URL -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=$USER' -d 'password=$PASSWORD' -d 'grant_type=password' -d 'client_id=$CLIENT_ID' | sed 's/.*access_token\":\"//g' | sed 's/\".*//g'", returnStdout: true)
  34 +
  35 + String testName = "KEA_TIE_I001"
  36 + String url = "$APP_URL/api/v1/od/start"
  37 + String responseCode = sh(label: testName, script: "curl -m 10 -sL -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url", returnStdout: true)
  38 + echo responseCode
  39 + if (!responseCode.endsWith('200')) {
  40 + error("$testName: Returned status code = $responseCode when calling $url")
  41 + }
  42 + String processId = responseCode.split(",")[1].split(":")[1].split('"')[1];
  43 + url = "$APP_URL/api/v1/od/analyze/$processId"
  44 + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -F file=@pcap-data/big.pcap $url -o /dev/null", returnStdout: true)
  45 + echo responseCode
  46 + if (responseCode != '200') {
  47 + error("$testName: Returned status code = $responseCode when calling $url")
  48 + }
  49 + url = "$APP_URL/api/v1/od/stop/$processId"
  50 + responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
  51 + echo responseCode
  52 + if (responseCode != '200') {
  53 + error("$testName: Returned status code = $responseCode when calling $url")
  54 + }
  55 +
  56 + } catch (ignored) {
  57 + currentBuild.result = 'FAILURE'
  58 + echo "KEA Deployment Tests failed"
  59 + }
  60 + }
  61 + }
  62 + }
  63 +
  64 + }
  65 +}