f97d9457b02b048cc1a928e650050d46f7406d5c
[sim/a1-interface.git] / near-rt-ric-simulator / test / OSC_2.1.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 "
25     exit 1
26 }
27
28 if [ $# -ne 2 ]; then
29     print_usage
30 fi
31 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
32     print_usage
33 fi
34 if [ "$2" == "duplicate-check" ]; then
35     DUP_CHECK=1
36 elif [ "$2" == "ignore-duplicate" ]; then
37     DUP_CHECK=0
38 else
39     print_usage
40 fi
41
42 if [ $1 == "nonsecure" ]; then
43     #Default http port for the simulator
44     PORT=8085
45     # Set http protocol
46     HTTPX="http"
47 else
48     #Default https port for the simulator
49     PORT=8185
50     # Set https protocol
51     HTTPX="https"
52 fi
53
54 . ../common/test_common.sh
55
56 echo "=== Simulator hello world ==="
57 RESULT="OK"
58 do_curl GET / 200
59
60 echo "=== Check used and implemented interfaces ==="
61 RESULT="Current interface: OSC_2.1.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']"
62 do_curl GET /container_interfaces 200
63
64 echo "=== Reset simulator instances ==="
65 RESULT="All policy instances deleted"
66 do_curl POST /deleteinstances 200
67
68 echo "=== Reset simulator, all ==="
69 RESULT="All policy instances and types deleted"
70 do_curl POST /deleteall 200
71
72 echo "=== API: Healthcheck ==="
73 RESULT=""
74 do_curl GET /a1-p/healthcheck 200
75
76 echo "=== API: Get policy types, shall be empty array =="
77 RESULT="json:[]"
78 do_curl GET /a1-p/policytypes 200
79
80 echo "=== API: Delete a policy type, shall fail =="
81 RESULT=""
82 do_curl DELETE /a1-p/policytypes/1 404
83
84 echo "=== API: Get policy instances for type 1, shall fail =="
85 RESULT=""
86 do_curl GET /a1-p/policytypes/1/policies 404
87
88 echo "=== API: Put a policy type: 1 ==="
89 RESULT=""
90 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
91
92 echo "=== API: Put a policy type: 1, again ==="
93 RESULT=""
94 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
95
96 echo "=== API: Delete a policy type: 1 ==="
97 RESULT=""
98 do_curl DELETE /a1-p/policytypes/1 204
99
100 echo "=== API: Get policy type ids, shall be empty =="
101 RESULT="json:[]"
102 do_curl GET /a1-p/policytypes 200
103
104 echo "=== API: Load a policy type: 1 ==="
105 RESULT=""
106 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
107
108 echo "=== API: Get policy type ids, shall contain type 1 =="
109 RESULT="json:[ 1 ]"
110 do_curl GET /a1-p/policytypes 200
111
112 echo "=== API: Get instances for type 1, shall be empty ==="
113 RESULT="json:[]"
114 do_curl GET '/a1-p/policytypes/1/policies' 200
115
116 echo "=== API: Create policy instance pi1 of type: 1 ==="
117 RESULT=""
118 # res=$(cat jsonfiles/pi1.json)
119 # RESULT="json:$res"
120 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
121
122 echo "=== API: Update policy instance pi1 of type: 1 ==="
123 RESULT=""
124 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
125 # res=$(cat jsonfiles/pi1.json)
126 # RESULT="json:$res"
127 # do_curl PUT '/a1-p/policytypes/1/policies/pi1' 200 jsonfiles/pi1.json
128
129 echo "=== API: Load a policy type: 1, shall fail ==="
130 RESULT=""
131 do_curl PUT /a1-p/policytypes/1 400 jsonfiles/pt1.json
132
133 echo "=== API: Get instances for type 1, shall contain pi1 ==="
134 RESULT="json:[ \"pi1\" ]"
135 do_curl GET '/a1-p/policytypes/1/policies' 200
136
137 if [ $DUP_CHECK == 1 ]; then
138     echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail ==="
139     RESULT=""
140     do_curl PUT '/a1-p/policytypes/1/policies/pi2' 400 jsonfiles/pi1.json
141 else
142     echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall succeed ==="
143     RESULT=""
144     do_curl PUT '/a1-p/policytypes/1/policies/pi2' 202 jsonfiles/pi1.json
145     # res=$(cat jsonfiles/pi1.json)
146     # RESULT="json:$res"
147     # do_curl PUT '/a1-p/policytypes/1/policies/pi2' 200 jsonfiles/pi1.json
148
149     echo "=== Delete policy instance: pi2 ==="
150     RESULT=""
151     do_curl DELETE '/a1-p/policytypes/1/policies/pi2' 202
152 fi
153
154 echo "=== Set force response code 401. ==="
155 RESULT="*"
156 do_curl POST '/forceresponse?code=401' 200
157
158 echo "=== API: Get policy type 1. Shall fail with forced code ==="
159 RESULT=""
160 do_curl GET '/a1-p/policytypes/1' 401
161
162 echo "=== API: Get policy status ==="
163 RESULT="json:{\"enforceStatus\": \"NOT_ENFORCED\", \"enforceReason\": \"OTHER_REASON\"}"
164 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
165
166 echo "=== Load a policy type: 2 ==="
167 RESULT="Policy type 2 is OK."
168 do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json
169
170 echo "=== Load a policy type: 2 again. ==="
171 RESULT="Policy type 2 is OK."
172 do_curl PUT '/policytype?id=2' 200 jsonfiles/pt2.json
173
174 echo "=== API: Get policy type ids, shall contain type 1 and 2 =="
175 RESULT="json:[ 1, 2 ]"
176 do_curl GET /a1-p/policytypes 200
177
178 echo "=== Get policy type ids, shall contain type 1 and 2 =="
179 RESULT="json:[\"1\", \"2\"]"
180 do_curl GET /policytypes 200
181
182 echo "=== API: Get policy type 2 =="
183 RESULT="json:{\"name\": \"pt2\", \"description\": \"pt2 policy type\", \"policy_type_id\": 2, \"create_schema\": {\"\$schema\": \"http://json-schema.org/draft-07/schema#\", \"title\": \"STD_QoSNudging_0.2.0\", \"description\": \"QoS policy type\", \"type\": \"object\", \"properties\": {\"scope\": {\"type\": \"object\", \"properties\": {\"ueId\": {\"type\": \"string\"}, \"qosId\": {\"type\": \"string\"}}, \"additionalProperties\": false, \"required\": [\"ueId\", \"qosId\"]}, \"statement\": {\"type\": \"object\", \"properties\": {\"priorityLevel\": {\"type\": \"number\"}}, \"additionalProperties\": false, \"required\": [\"priorityLevel\"]}}}}"
184 do_curl GET /a1-p/policytypes/2 200
185
186 echo "=== Delete policy type: 2 ==="
187 RESULT=""
188 do_curl DELETE '/policytype?id=2' 204 jsonfiles/pt2.json
189
190 echo "=== API: Get policy type ids, shall contain type 1 =="
191 RESULT="json:[ 1 ]"
192 do_curl GET /a1-p/policytypes 200
193
194 echo "=== Load a policy type: 2 ==="
195 RESULT="Policy type 2 is OK."
196 do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json
197
198 echo "=== API: Get policy type 2 =="
199 RESULT="json:{\"name\": \"pt2\", \"description\": \"pt2 policy type\", \"policy_type_id\": 2, \"create_schema\": {\"\$schema\": \"http://json-schema.org/draft-07/schema#\", \"title\": \"STD_QoSNudging_0.2.0\", \"description\": \"QoS policy type\", \"type\": \"object\", \"properties\": {\"scope\": {\"type\": \"object\", \"properties\": {\"ueId\": {\"type\": \"string\"}, \"qosId\": {\"type\": \"string\"}}, \"additionalProperties\": false, \"required\": [\"ueId\", \"qosId\"]}, \"statement\": {\"type\": \"object\", \"properties\": {\"priorityLevel\": {\"type\": \"number\"}}, \"additionalProperties\": false, \"required\": [\"priorityLevel\"]}}}}"
200 do_curl GET /a1-p/policytypes/2 200
201
202 echo "=== API: Get instances for type 2, shall be empty ==="
203 RESULT="json:[]"
204 do_curl GET '/a1-p/policytypes/2/policies' 200
205
206 echo "=== API: Create duplicate policy instance id pi1 of type: 2 (pi1 exist for type 1), shall fail==="
207 RESULT=""
208 do_curl PUT '/a1-p/policytypes/2/policies/pi1' 400 jsonfiles/pi1.json
209
210 echo "=== API: Create policy instance pi2 of type: 2. Missing param, shall fail. ==="
211 RESULT=""
212 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 400 jsonfiles/pi2_missing_param.json
213
214 echo "=== API: Create policy instance pi2 of type: 2 ==="
215 RESULT=""
216 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
217 # res=$(cat jsonfiles/pi2.json)
218 # RESULT="json:$res"
219 # do_curl PUT '/a1-p/policytypes/2/policies/pi2' 200 jsonfiles/pi2.json
220
221 echo "=== API: Update policy instance pi2 of type: 2 ==="
222 RESULT=""
223 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
224
225 echo "=== API: Update policy instance pi2 of type: 2 ==="
226 RESULT=""
227 do_curl PUT "/a1-p/policytypes/2/policies/pi2?notificationDestination=http://localhost:${PORT}/statustest" 202 jsonfiles/pi2.json
228
229 echo "=== Send status for pi2==="
230 RESULT="OK"
231 do_curl POST '/sendstatus?policyid=pi2' 201 jsonfiles/pi2.json
232
233 echo "=== API: Get instances for type 1, shall contain pi1 ==="
234 RESULT="json:[ \"pi1\" ]"
235 do_curl GET '/a1-p/policytypes/1/policies' jsonfiles/200
236
237 echo "=== API: Get instances for type 2, shall contain pi2 ==="
238 RESULT="json:[ \"pi2\" ]"
239 do_curl GET '/a1-p/policytypes/2/policies' 200
240
241 if [ $DUP_CHECK == 1 ]; then
242     echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail ==="
243     RESULT=""
244     do_curl PUT '/a1-p/policytypes/1/policies/pi11' 400 jsonfiles/pi1.json
245 else
246     echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall succeed ==="
247     RESULT=""
248     do_curl PUT '/a1-p/policytypes/1/policies/pi11' 202 jsonfiles/pi1.json
249     # res=$(cat jsonfiles/pi1.json)
250     # RESULT="json:$res"
251     # do_curl PUT '/a1-p/policytypes/1/policies/pi11' 200 jsonfiles/pi1.json
252
253     echo "=== Delete policy instance: pi11 ==="
254     RESULT=""
255     do_curl DELETE '/a1-p/policytypes/1/policies/pi11' 202
256 fi
257
258 if [ $DUP_CHECK == 1 ]; then
259     echo "=== API: Create policy instance pi3 (copy of pi1) of type: 2. Shall fail ==="
260     RESULT=""
261     do_curl PUT '/a1-p/policytypes/1/policies/pi3' 400 jsonfiles/pi1.json
262 else
263     echo "=== API: Create policy instance pi3 (copy of pi1) of type: 1. Shall succeed ==="
264     RESULT=""
265     do_curl PUT '/a1-p/policytypes/1/policies/pi3' 202 jsonfiles/pi1.json
266     # res=$(cat jsonfiles/pi1.json)
267     # RESULT="json:$res"
268     # do_curl PUT '/a1-p/policytypes/1/policies/pi3' 200 jsonfiles/pi1.json
269
270     echo "=== Delete policy instance: pi3 ==="
271     RESULT=""
272     do_curl DELETE '/a1-p/policytypes/1/policies/pi3' 202
273 fi
274
275 echo "=== API: Get instances for type 1, shall contain pi1 ==="
276 RESULT="json:[ \"pi1\" ]"
277 do_curl GET '/a1-p/policytypes/1/policies' jsonfiles/200
278
279 echo "=== API: Get instances for type 2, shall contain pi2 ==="
280 RESULT="json:[ \"pi2\" ]"
281 do_curl GET '/a1-p/policytypes/2/policies' 200
282
283 echo "=== Set force response code 401. ==="
284 RESULT="*"
285 do_curl POST '/forceresponse?code=401' 200
286
287 echo "=== API: Get policy status for pi1, shall fail ==="
288 RESULT=""
289 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 401
290
291 echo "=== Set force delay 10. ==="
292 RESULT="Force delay: 10 sec set for all A1 responses"
293 do_curl POST '/forcedelay?delay=10' 200
294
295 echo "=== API: Get policy status for pi1. Shall delay 10 sec ==="
296 RESULT="json:{\"enforceStatus\": \"NOT_ENFORCED\", \"enforceReason\": \"OTHER_REASON\"}"
297 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
298
299 echo "=== Reset force delay. ==="
300 RESULT="Force delay: None sec set for all A1 responses"
301 do_curl POST '/forcedelay' 200
302
303 echo "=== Set status for pi1 ==="
304 RESULT="Status set to ENFORCED for policy: pi1"
305 do_curl PUT '/status?policyid=pi1&status=ENFORCED' 200
306
307 echo "=== API: Get policy status for pi1 ==="
308 RESULT="json:{\"enforceStatus\": \"ENFORCED\", \"enforceReason\": null}"
309 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
310
311 echo "=== Set status for pi1 ==="
312 RESULT="Status set to ENFORCED for policy: pi1"
313 do_curl PUT '/status?policyid=pi1&status=ENFORCED' 200
314
315 echo "=== API: Get policy status for pi1 ==="
316 RESULT="json:{\"enforceStatus\": \"ENFORCED\", \"enforceReason\": null}"
317 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
318
319 echo "=== Get counter: instances ==="
320 RESULT="2"
321 do_curl GET '/counter/num_instances' 200
322
323 echo "=== Get counter: types ==="
324 RESULT="2"
325 do_curl GET '/counter/num_types' 200
326
327 echo "=== Get counter: interface ==="
328 RESULT="OSC_2.1.0"
329 do_curl GET '/counter/interface' 200
330
331 echo "=== Get counter: remote hosts ==="
332 RESULT="*"
333 do_curl GET '/counter/remote_hosts' 200
334
335 echo "=== DELETE policy pi1 ==="
336 RESULT=""
337 do_curl DELETE /a1-p/policytypes/1/policies/pi1 202
338
339 echo "=== API: Get instances for type 1, shall be empty ==="
340 RESULT="[]"
341 do_curl GET /a1-p/policytypes/1/policies 200
342
343 echo "=== API: Get instances for type 2, shall contain pi2 ==="
344 RESULT="[ \"pi2\" ]"
345 do_curl GET /a1-p/policytypes/2/policies 200
346
347 echo "=== Get counter: instances ==="
348 RESULT="1"
349 do_curl GET /counter/num_instances 200
350
351 echo "=== Get counter: datadelivery ==="
352 RESULT="0"
353 do_curl GET /counter/datadelivery 200
354
355 echo "********************"
356 echo "*** All tests ok ***"
357 echo "********************"