Merge "Callout hooks towards external server for create and delete operations"
[sim/a1-interface.git] / near-rt-ric-simulator / test / STD_2.0.0 / basic_test.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2021 Nordix Foundation. All rights reserved.
5 #  ========================================================================
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License.
17 #  ============LICENSE_END=================================================
18 #
19
20 # Script for basic test of the simulator.
21 # Run the build_and_start with the same arg, except arg 'nonsecure|secure', as this script
22
23 print_usage() {
24     echo "Usage: ./basic_test.sh nonsecure|secure duplicate-check|ignore-duplicate ext-srv|ext-srv-secure|ignore-ext-srv"
25     exit 1
26 }
27
28 if [ $# -ne 3 ]; then
29     print_usage
30 fi
31
32 if [ $1 != "nonsecure" ] && [ $1 != "secure" ]; then
33     print_usage
34 fi
35
36 if [ $2 != "duplicate-check" ] && [ $2 != "ignore-duplicate" ]; then
37     print_usage
38 fi
39
40 if [ $3 != "ext-srv" ] && [ $3 != "ext-srv-secure" ] && [ $3 != "ignore-ext-srv" ]; then
41     print_usage
42 fi
43
44
45 if [ $1 == "nonsecure" ]; then
46     #Default http port for the simulator
47     PORT=8085
48     # Set http protocol
49     HTTPX="http"
50 else
51     #Default https port for the simulator
52     PORT=8185
53     # Set https protocol
54     HTTPX="https"
55 fi
56
57 if [ $2 == "duplicate-check" ]; then
58     DUP_CHECK=1
59 else
60     DUP_CHECK=0
61 fi
62
63 if [ $3 == "ext-srv" ]; then
64     #Default http port for the external server
65     PORT_EXT_SRV=9095
66     # Set http protocol for external server
67     HTTPX_EXT_SRV="http"
68     EXT_SRV_EXIST=1
69 elif [ $3 == "ext-srv-secure" ]; then
70     #Default https port for the external server
71     PORT_EXT_SRV=9195
72     # Set https protocol for external server
73     HTTPX_EXT_SRV="https"
74     EXT_SRV_EXIST=1
75 else
76     EXT_SRV_EXIST=0
77 fi
78
79 . ../common/test_common.sh
80
81
82 echo "=== Simulator hello world ==="
83 RESULT="OK"
84 do_curl GET / 200
85
86 echo "=== Check used and implemented interfaces ==="
87 RESULT="Current interface: STD_2.0.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']"
88 do_curl GET /container_interfaces 200
89
90 echo "=== Reset simulator instances ==="
91 RESULT="All policy instances deleted"
92 do_curl POST /deleteinstances 200
93
94 echo "=== Reset simulator, all ==="
95 RESULT="All policy instances and types deleted"
96 do_curl POST /deleteall 200
97
98 #Test all admin functions in the external server
99 if [ $EXT_SRV_EXIST == 1 ]; then
100     echo "=== External server, hello world ==="
101     RESULT="OK"
102     do_curl_ext_srv GET / 200
103
104     echo "=== External server, reset all ==="
105     RESULT="All a1 policy instances deleted"
106     do_curl_ext_srv POST /serveradmin/deleteinstances 200
107
108     echo "=== External server, reset force delay ==="
109     RESULT="Force delay has been resetted for all external server responses"
110     do_curl_ext_srv POST /serveradmin/forcedelay 200
111 fi
112
113 echo "=== Get counter: interface ==="
114 RESULT="STD_2.0.0"
115 do_curl GET /counter/interface 200
116
117 echo "=== Get counter: remote hosts ==="
118 RESULT="*"
119 do_curl GET /counter/remote_hosts 200
120
121 echo "=== Get counter: intstance ==="
122 RESULT="0"
123 do_curl GET /counter/num_instances 200
124
125 echo "=== Get counter: types (shall be 0)==="
126 RESULT="0"
127 do_curl GET /counter/num_types 200
128
129 echo "=== API: Get policy types, shall be empty array =="
130 RESULT="json:[]"
131 do_curl GET /A1-P/v2/policytypes 200
132
133 echo "=== API: Get policy instances for type 1, type not found=="
134 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"1\"}"
135 do_curl GET /A1-P/v2/policytypes/1/policies 404
136
137 echo "=== API: Get policy instances, type not found=="
138 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"test\"}"
139 do_curl GET /A1-P/v2/policytypes/test/policies 404
140
141 echo "=== Put a policy type: STD_1 ==="
142 RESULT="Policy type STD_1 is OK."
143 do_curl PUT  '/policytype?id=STD_1' 201 jsonfiles/std_1.json
144
145 echo "=== Put a policy type: STD_1, again ==="
146 RESULT="Policy type STD_1 is OK."
147 do_curl PUT  '/policytype?id=STD_1' 200 jsonfiles/std_1.json
148
149 echo "=== API: Get policy type ids, shall contain type STD_1 =="
150 RESULT="json:[ \"STD_1\" ]"
151 do_curl GET /A1-P/v2/policytypes 200
152
153 echo "=== Delete a policy type: STD_1 ==="
154 RESULT=""
155 do_curl DELETE  '/policytype?id=STD_1' 204
156
157 echo "=== API: Get policy type ids, shall be empty =="
158 RESULT="json:[]"
159 do_curl GET  /A1-P/v2/policytypes 200
160
161 echo "=== Put a policy type: STD_1 ==="
162 RESULT="Policy type STD_1 is OK."
163 do_curl PUT  '/policytype?id=STD_1' 201 jsonfiles/std_1.json
164
165 echo "=== API: Get policy type ids, shall contain type STD_1 =="
166 RESULT="json:[ \"STD_1\" ]"
167 do_curl GET /A1-P/v2/policytypes 200
168
169 echo "=== Get counter: types (shall be 1)==="
170 RESULT="1"
171 do_curl GET /counter/num_types 200
172
173 echo "=== API: Get policy type: STD_1 ==="
174 res=$(cat jsonfiles/std_1.json)
175 RESULT="json:$res"
176 do_curl GET /A1-P/v2/policytypes/STD_1 200
177
178 echo "=== API: Get policy instances, shall be empty=="
179 RESULT="json:[ ]"
180 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
181
182 echo "=== API: Create policy instance pi1 of type: STD_1 ==="
183 res=$(cat jsonfiles/pi1.json)
184 RESULT="json:$res"
185 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 201 jsonfiles/pi1.json
186
187 if [ $EXT_SRV_EXIST == 1 ]; then
188     echo "=== External server, get a pi1 policy: pi1 ==="
189     res=$(cat jsonfiles/pi1.json)
190     RESULT="json:$res"
191     do_curl_ext_srv GET /a1policy/pi1 200
192 fi
193
194 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
195 res=$(cat jsonfiles/pi1.json)
196 RESULT="json:$res"
197 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
198
199 echo "=== API: Update policy instance pi1 of type: STD_1==="
200 res=$(cat jsonfiles/pi1.json)
201 RESULT="json:$res"
202 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1.json
203
204 if [ $EXT_SRV_EXIST == 1 ]; then
205     echo "=== External server, get a pi1 policy: pi1 ==="
206     res=$(cat jsonfiles/pi1.json)
207     RESULT="json:$res"
208     do_curl_ext_srv GET /a1policy/pi1 200
209 fi
210
211 echo "=== API: Update policy instance pi1 of type: STD_1==="
212 res=$(cat jsonfiles/pi1_updated.json)
213 RESULT="json:$res"
214 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1_updated.json
215
216 if [ $EXT_SRV_EXIST == 1 ]; then
217     echo "=== External server, get a pi1 policy: pi1 ==="
218     res=$(cat jsonfiles/pi1_updated.json)
219     RESULT="json:$res"
220     do_curl_ext_srv GET /a1policy/pi1 200
221 fi
222
223 echo "=== API: Duplicate policy instance json,  pi2 of type: STD_1==="
224 res=$(cat jsonfiles/pi1_updated.json)
225 if [ $DUP_CHECK == 1 ]; then
226     #Fail with dupl check
227     RESULT="json:{\"title\": \"Duplicate, the policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}"
228     do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 400 jsonfiles/pi1_updated.json
229 else
230     #OK without dupl check
231     res=$(cat jsonfiles/pi1_updated.json)
232     RESULT="json:$res"
233     do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi1_updated.json
234
235     if [ $EXT_SRV_EXIST == 1 ]; then
236         echo "=== External server, get a pi2 policy: pi2 ==="
237         res=$(cat jsonfiles/pi1_updated.json)
238         RESULT="json:$res"
239         do_curl_ext_srv GET /a1policy/pi2 200
240     fi
241
242     echo "=== API: DELETE policy instance pi2 ==="
243     RESULT=""
244     do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi2 204
245
246     if [ $EXT_SRV_EXIST == 1 ]; then
247         echo "=== External server, get a pi2 policy: policy instance not found ==="
248         RESULT="json:{\"title\": \"The A1 policy requested does not exist.\", \"status\": 404, \"instance\": \"pi2\"}"
249         do_curl_ext_srv GET /a1policy/pi2 404
250     fi
251 fi
252
253 echo "=== API: Get policy instances, shall contain pi1=="
254 RESULT="json:[ \"pi1\" ]"
255 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
256
257 if [ $EXT_SRV_EXIST == 1 ]; then
258     echo "=== External server, get policy instances, shall contain pi1=="
259     RESULT="json:[ \"pi1\" ]"
260     do_curl_ext_srv GET /a1policies 200
261 fi
262
263 echo "=== Put a policy type: STD_2 ==="
264 RESULT="Policy type STD_2 is OK."
265 do_curl PUT  '/policytype?id=STD_2' 201 jsonfiles/std_2.json
266
267 echo "=== API: Duplicate policy instance id pi1 of type: STD_2==="
268 res=$(cat jsonfiles/pi1_updated.json)
269 RESULT="json:{\"title\": \"The policy id already exist for other policy type.\", \"status\": 400, \"instance\": \"pi1\"}"
270 do_curl PUT /A1-P/v2/policytypes/STD_2/policies/pi1 400 jsonfiles/pi1_updated.json
271
272 echo "=== API: Get policy type ids, shall contain type STD_1  and STD_2 =="
273 RESULT="json:[ \"STD_1\", \"STD_2\" ]"
274 do_curl GET /A1-P/v2/policytypes 200
275
276 echo "=== Get counter: types (shall be 2)==="
277 RESULT="2"
278 do_curl GET /counter/num_types 200
279
280 echo "=== Get counter: intstance ==="
281 RESULT="1"
282 do_curl GET /counter/num_instances 200
283
284 echo "=== Set force response code 409. ==="
285 RESULT="*"
286 do_curl POST '/forceresponse?code=409' 200
287
288 echo "=== API: Get policy instances, shall fail with 409 =="
289 RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}"
290 do_curl GET /A1-P/v2/policytypes/STD_1/policies 409
291
292 echo "=== API: Get policy status ==="
293 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
294 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1/status 200
295
296 echo "=== API: Create policy instance pi2 of type: STD_1 ==="
297 res=$(cat jsonfiles/pi2.json)
298 RESULT="json:$res"
299 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi2.json
300
301 echo "=== API: Update policy instance pi2 of type: STD_1 ==="
302 res=$(cat jsonfiles/pi2.json)
303 RESULT="json:$res"
304 do_curl PUT '/A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json
305
306 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
307 RESULT="json:[ \"pi1\", \"pi2\" ]"
308 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
309
310 echo "=== Get counter: types (shall be 2)==="
311 RESULT="2"
312 do_curl GET /counter/num_types 200
313
314 echo "=== Get counter: intstance ==="
315 RESULT="2"
316 do_curl GET /counter/num_instances 200
317
318 echo "=== Set force delay 10. ==="
319 RESULT="Force delay: 10 sec set for all A1 responses"
320 do_curl POST '/forcedelay?delay=10' 200
321
322 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
323 RESULT="json:[ \"pi1\", \"pi2\" ]"
324 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
325
326 echo "=== Reset force delay. ==="
327 RESULT="Force delay: None sec set for all A1 responses"
328 do_curl POST /forcedelay 200
329
330 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
331 res=$(cat jsonfiles/pi1_updated.json)
332 RESULT="json:$res"
333 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
334
335 echo "=== API: Get policy instance pi2 of type: STD_1 ==="
336 res=$(cat jsonfiles/pi2.json)
337 RESULT="json:$res"
338 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2 200
339
340 echo "=== API: DELETE policy instance pi1 ==="
341 RESULT=""
342 do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi1 204
343
344 echo "=== API: Get policy instances, shall contain pi2=="
345 RESULT="json:[ \"pi2\" ]"
346 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
347
348 if [ $EXT_SRV_EXIST == 1 ]; then
349     echo "=== External server, get policy instances, shall contain pi2=="
350     RESULT="json:[ \"pi2\" ]"
351     do_curl_ext_srv GET /a1policies 200
352 fi
353
354 echo "=== API: Get policy status ==="
355 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
356 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
357
358 echo "=== Set status for policy instance pi2 ==="
359 RESULT="Status set to OK for policy: pi2"
360 do_curl PUT '/status?policyid=pi2&status=OK' 200
361
362 echo "=== API: Get policy status ==="
363 RESULT="json:{\"enforceStatus\": \"OK\"}"
364 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
365
366 echo "=== Set status for policy instance pi2 ==="
367 RESULT="Status set to NOTOK and notok_reason for policy: pi2"
368 do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200
369
370 echo "=== API: Get policy status ==="
371 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\":\"notok_reason\"}"
372 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
373
374 echo "=== Send status for pi2==="
375 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
376 do_curl POST '/sendstatus?policyid=pi2' 200
377
378 echo "=== Get counter: datadelivery ==="
379 RESULT="0"
380 do_curl GET /counter/datadelivery 200
381
382 echo "=== Send data ==="
383 echo "{}" > .p.json
384 RESULT=""
385 do_curl POST /datadelivery 200 .p.json
386
387 echo "=== Get counter: datadelivery ==="
388 RESULT="1"
389 do_curl GET /counter/datadelivery 200
390
391 echo "=== Get counter: intstance ==="
392 RESULT="1"
393 do_curl GET /counter/num_instances 200
394
395 echo "=== Get counter: types (shall be 2)==="
396 RESULT="2"
397 do_curl GET /counter/num_types 200
398
399 echo "=== Get counter: interface ==="
400 RESULT="STD_2.0.0"
401 do_curl GET /counter/interface 200
402
403 echo "=== Get counter: remote hosts ==="
404 RESULT="*"
405 do_curl GET /counter/remote_hosts 200
406
407 echo "********************"
408 echo "*** All tests ok ***"
409 echo "********************"