Blame view

kea_testing.groovy 9.13 KB
a7a0d7905   George Vlahavas   Add initial Jenki...
1
2
3
4
5
6
7
8
9
10
  /**
  * 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
097a24e19   George Vlahavas   Fix whitespace
11
      environment {
fb793d4ad   George Vlahavas   Revert "Revert "A...
12
        
97fe60fba   George Vlahavas   Remove deployment...
13
        APP_URL = "https://kea.curex-project.eu"
972595bcc   George Vlahavas   Change Master to ...
14
        KEYCLOAK_URL = "https://keycloak.curex-project.eu/auth/realms/master/protocol/openid-connect/token"
97fe60fba   George Vlahavas   Remove deployment...
15
16
17
        USER = credentials('keycloak-test-user')
        PASSWORD = credentials('keycloak-test-password')
        CLIENT_ID = "KEA"
a7a0d7905   George Vlahavas   Add initial Jenki...
18
19
20
      }
  
    stages {
a7a0d7905   George Vlahavas   Add initial Jenki...
21
      
097a24e19   George Vlahavas   Fix whitespace
22
      stage('Run tests') {
a7a0d7905   George Vlahavas   Add initial Jenki...
23
24
        steps {
          script {
f7afd8ea9   George Vlahavas   Add a simple test
25
26
27
            echo '*************'
            echo '*** TESTS ***'
            echo '*************'
a7a0d7905   George Vlahavas   Add initial Jenki...
28
            /* Here do your tests */
f7afd8ea9   George Vlahavas   Add a simple test
29
            try {
97fe60fba   George Vlahavas   Remove deployment...
30
31
              // 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)
686bf5b89   George Vlahavas   Add tests KEA_F00...
32
              String testName = "KEA_F001"
97fe60fba   George Vlahavas   Remove deployment...
33
34
              String url = "$APP_URL"
              String 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)
3e893a46f   George Vlahavas   Always echo the r...
35
              echo responseCode
f7afd8ea9   George Vlahavas   Add a simple test
36
37
38
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
39

55bf5645f   George Vlahavas   Move F004 and F00...
40
              testName = "KEA_F002"
97fe60fba   George Vlahavas   Remove deployment...
41
42
              url = "$APP_URL/components/od"
              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)
3e893a46f   George Vlahavas   Always echo the r...
43
              echo responseCode
55bf5645f   George Vlahavas   Move F004 and F00...
44
45
46
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
47

55bf5645f   George Vlahavas   Move F004 and F00...
48
              testName = "KEA_F003"
97fe60fba   George Vlahavas   Remove deployment...
49
50
              url = "$APP_URL/components/mltd"
              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)
3e893a46f   George Vlahavas   Always echo the r...
51
              echo responseCode
97fe60fba   George Vlahavas   Remove deployment...
52
53
54
55
56
57
58
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
  
              testName = "KEA_F004"
              url = "$APP_URL/api/config"
              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)
3e893a46f   George Vlahavas   Always echo the r...
59
              echo responseCode
55bf5645f   George Vlahavas   Move F004 and F00...
60
61
62
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
63
64
65
66
  
              testName = "KEA_F005"
              url = "$APP_URL/api/capec"
              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)
3e893a46f   George Vlahavas   Always echo the r...
67
              echo responseCode
3d1540d58   George Vlahavas   Revert "Disable t...
68
69
70
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
71

9396f6c4a   George Vlahavas   Move back grafana...
72
73
74
              testName = "KEA_F006"
              url = "https://kea-grafana.vlahavas.com/api/dashboards/home"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' -H 'Αuthorization: Bearer $token' -H 'Accept: application/json, text/plain, */*' $url -o /dev/null", returnStdout: true)
3e893a46f   George Vlahavas   Always echo the r...
75
              echo responseCode
cfd27a3cb   George Vlahavas   Add back all tests
76
77
78
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
79

9396f6c4a   George Vlahavas   Move back grafana...
80
81
              testName = "KEA_F007"
              url = "https://kea-kibana.vlahavas.com/app/kibana"
97fe60fba   George Vlahavas   Remove deployment...
82
              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)
3e893a46f   George Vlahavas   Always echo the r...
83
              echo responseCode
546bec5fd   George Vlahavas   Revert "Disable t...
84
85
86
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
87

9396f6c4a   George Vlahavas   Move back grafana...
88
89
              testName = "KEA_F008"
              url = "$APP_URL/components/ceptd"
97fe60fba   George Vlahavas   Remove deployment...
90
              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)
3e893a46f   George Vlahavas   Always echo the r...
91
              echo responseCode
a440995cf   George Vlahavas   Move KEA_F003 to ...
92
93
94
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
97fe60fba   George Vlahavas   Remove deployment...
95

296ef6417   George Vlahavas   Add OD test
96
97
              testName = "KEA_F009"
              url = "$APP_URL/api/v1/od/start"
7ebc5964e   George Vlahavas   Don't fetch only ...
98
              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)
1504b1017   George Vlahavas   Add echo
99
              echo responseCode
296ef6417   George Vlahavas   Add OD test
100
101
102
103
104
105
              if (!responseCode.endsWith('200')) {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              String processId = responseCode.split(",")[1].split(":")[1].split('"')[1];
              url = "$APP_URL/api/v1/od/status"
              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)
3e893a46f   George Vlahavas   Always echo the r...
106
              echo responseCode
296ef6417   George Vlahavas   Add OD test
107
108
109
110
111
              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)
3e893a46f   George Vlahavas   Always echo the r...
112
              echo responseCode
296ef6417   George Vlahavas   Add OD test
113
114
115
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
88b814847   George Vlahavas   Add MLTD tests
116
117
118
119
120
121
122
123
              
              testName = "KEA_F010"
              url = "$APP_URL/api/v1/mltd/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")
              }
d852a28bf   George Vlahavas   Process ID is not...
124
              processId = responseCode.split(",")[1].split(":")[1];
88b814847   George Vlahavas   Add MLTD tests
125
126
127
128
129
130
131
132
133
134
135
136
              url = "$APP_URL/api/v1/mltd/status"
              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")
              }
              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")
              }
955d7930b   George Vlahavas   Test ADT and VDM ...
137
138
139
140
141
142
143
144
145
146
              
              testName = "KEA_F011"
              url = "$APP_URL/api/v1/adt"
              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")
              }
              
              testName = "KEA_F012"
6b180da53   George Vlahavas   Actually test VDM...
147
              url = "$APP_URL/api/v1/vdm"
955d7930b   George Vlahavas   Test ADT and VDM ...
148
149
150
151
152
              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")
              }
a515f488e   George Vlahavas   Add xlsiem test
153
154
155
156
157
158
159
160
              
              testName = "KEA_F013"
              url = "$APP_URL/api/v1/xlsiem"
              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")
              }
296ef6417   George Vlahavas   Add OD test
161

f7afd8ea9   George Vlahavas   Add a simple test
162
163
164
165
            } catch (ignored) {
              currentBuild.result = 'FAILURE'
              echo "KEA Deployment Tests failed"
            }
a7a0d7905   George Vlahavas   Add initial Jenki...
166
167
168
          }
        }
      }
a7a0d7905   George Vlahavas   Add initial Jenki...
169
170
    }
  }
097a24e19   George Vlahavas   Fix whitespace
171