Blame view

kea_integration.groovy 4.61 KB
7f2cc895f   George Vlahavas   Add KEA-TIE integ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  /**
  * Jenkinsfile to deploy multiple Docker containers based on docker-compose into a DEV server and run any test.
  * This pipeline will run the Docker containers, execute the tests and then stop and remove the containers from the DEV  
  * server automatically.
  **/
  
  
  pipeline {
  
    agent any
  
      environment {
        
        APP_URL = "https://kea.curex-project.eu"
972595bcc   George Vlahavas   Change Master to ...
15
        KEYCLOAK_URL = "https://keycloak.curex-project.eu/auth/realms/master/protocol/openid-connect/token"
7f2cc895f   George Vlahavas   Add KEA-TIE integ...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
        USER = credentials('keycloak-test-user')
        PASSWORD = credentials('keycloak-test-password')
        CLIENT_ID = "KEA"
  
      }
  
    stages {
      
      stage('Run tests') {
        steps {
          script {
            echo '*************'
            echo '*** TESTS ***'
            echo '*************'
            /* Here do your tests */
            try {
              // Get Keycloak auth token
              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)
34948db69   George Vlahavas   Split integration...
34
              // MLTD
7f2cc895f   George Vlahavas   Add KEA-TIE integ...
35
              String testName = "KEA_TIE_I001"
395830623   George Vlahavas   Add MLTD integrat...
36

395830623   George Vlahavas   Add MLTD integrat...
37
              String url = "$APP_URL/api/v1/mltd/start"
7f2cc895f   George Vlahavas   Add KEA-TIE integ...
38
39
40
41
42
              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)
              echo responseCode
              if (!responseCode.endsWith('200')) {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
395830623   George Vlahavas   Add MLTD integrat...
43
44
              String processId = responseCode.split(",")[1].split(":")[1];
              url = "$APP_URL/api/v1/xlsiem"
719cc4338   George Vlahavas   Set content-type ...
45
              responseCode = sh(label: testName, script: "curl -m 10 -sL -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json' -H 'Content-Type: application/json' -F file=@pcap-data/mltd1-unix.json $url -o /dev/null", returnStdout: true)
395830623   George Vlahavas   Add MLTD integrat...
46
47
48
49
              echo responseCode
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
719cc4338   George Vlahavas   Set content-type ...
50
              responseCode = sh(label: testName, script: "curl -m 10 -sL -w '%{http_code}' -H 'Authorization: Bearer $token' -H 'Accept: application/json' -H 'Content-Type: application/json'-F file=@pcap-data/mltd2-unix.json $url -o /dev/null", returnStdout: true)
395830623   George Vlahavas   Add MLTD integrat...
51
52
53
54
55
56
57
58
59
60
61
62
              echo responseCode
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              url = "$APP_URL/api/v1/mltd/stop/$processId"
              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)
              echo responseCode
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
  
              // OD
34948db69   George Vlahavas   Split integration...
63
              testName = "KEA_TIE_I002"
395830623   George Vlahavas   Add MLTD integrat...
64
65
66
67
68
69
70
              url = "$APP_URL/api/v1/od/start"
              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)
              echo responseCode
              if (!responseCode.endsWith('200')) {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              processId = responseCode.split(",")[1].split(":")[1].split('"')[1];
7f2cc895f   George Vlahavas   Add KEA-TIE integ...
71
              url = "$APP_URL/api/v1/od/analyze/$processId"
9e372b60c   George Vlahavas   Remove -I switch ...
72
              responseCode = sh(label: testName, script: "curl -m 10 -sL -w '%{http_code}' -H 'Authorization: Bearer $token' -F file=@pcap-data/big.pcap $url -o /dev/null", returnStdout: true)
7f2cc895f   George Vlahavas   Add KEA-TIE integ...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
              echo responseCode
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              url = "$APP_URL/api/v1/od/stop/$processId"
              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)
              echo responseCode
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              
            } catch (ignored) {
              currentBuild.result = 'FAILURE'
              echo "KEA Deployment Tests failed"
            }
          }
        }
      }
  
    }
  }