Added payload logging and configurable duplicate check
[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 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
119
120 echo "=== API: Update policy instance pi1 of type: 1 ==="
121 RESULT=""
122 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
123
124 echo "=== API: Load a policy type: 1, shall fail ==="
125 RESULT=""
126 do_curl PUT /a1-p/policytypes/1 400 jsonfiles/pt1.json
127
128 echo "=== API: Get instances for type 1, shall contain pi1 ==="
129 RESULT="json:[ \"pi1\" ]"
130 do_curl GET '/a1-p/policytypes/1/policies' 200
131
132 if [ $DUP_CHECK == 1 ]; then
133     echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail ==="
134     RESULT=""
135     do_curl PUT '/a1-p/policytypes/1/policies/pi2' 400 jsonfiles/pi1.json
136 else
137     echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall succeed ==="
138     RESULT=""
139     do_curl PUT '/a1-p/policytypes/1/policies/pi2' 202 jsonfiles/pi1.json
140
141     echo "=== Delete policy instance: pi2 ==="
142     RESULT=""
143     do_curl DELETE '/a1-p/policytypes/1/policies/pi2' 202
144 fi
145
146 echo "=== Set force response code 401. ==="
147 RESULT="*"
148 do_curl POST '/forceresponse?code=401' 200
149
150 echo "=== API: Get policy type 1. Shall fail with forced code ==="
151 RESULT=""
152 do_curl GET '/a1-p/policytypes/1' 401
153
154 echo "=== API: Get policy status ==="
155 RESULT="json:{\"instance_status\": \"NOT IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
156 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
157
158 echo "=== Load a policy type: 2 ==="
159 RESULT="Policy type 2 is OK."
160 do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json
161
162 echo "=== Load a policy type: 2 again. ==="
163 RESULT="Policy type 2 is OK."
164 do_curl PUT '/policytype?id=2' 200 jsonfiles/pt2.json
165
166 echo "=== API: Get policy type ids, shall contain type 1 and 2 =="
167 RESULT="json:[ 1, 2 ]"
168 do_curl GET /a1-p/policytypes 200
169
170 echo "=== Get policy type ids, shall contain type 1 and 2 =="
171 RESULT="json:[\"1\", \"2\"]"
172 do_curl GET /policytypes 200
173
174 echo "=== API: Get policy type 2 =="
175 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\"]}}}}"
176 do_curl GET /a1-p/policytypes/2 200
177
178 echo "=== Delete policy type: 2 ==="
179 RESULT=""
180 do_curl DELETE '/policytype?id=2' 204 jsonfiles/pt2.json
181
182 echo "=== API: Get policy type ids, shall contain type 1 =="
183 RESULT="json:[ 1 ]"
184 do_curl GET /a1-p/policytypes 200
185
186 echo "=== Load a policy type: 2 ==="
187 RESULT="Policy type 2 is OK."
188 do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json
189
190 echo "=== API: Get policy type 2 =="
191 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\"]}}}}"
192 do_curl GET /a1-p/policytypes/2 200
193
194 echo "=== API: Get instances for type 2, shall be empty ==="
195 RESULT="json:[]"
196 do_curl GET '/a1-p/policytypes/2/policies' 200
197
198 echo "=== API: Create duplicate policy instance id pi1 of type: 2 (pi1 exist for type 1), shall fail==="
199 RESULT=""
200 do_curl PUT '/a1-p/policytypes/2/policies/pi1' 400 jsonfiles/pi1.json
201
202 echo "=== API: Create policy instance pi2 of type: 2. Missing param, shall fail. ==="
203 RESULT=""
204 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 400 jsonfiles/pi2_missing_param.json
205
206 echo "=== API: Create policy instance pi2 of type: 2 ==="
207 RESULT=""
208 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
209
210 echo "=== API: Update policy instance pi2 of type: 2 ==="
211 RESULT=""
212 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
213
214 echo "=== API: Get instances for type 1, shall contain pi1 ==="
215 RESULT="json:[ \"pi1\" ]"
216 do_curl GET '/a1-p/policytypes/1/policies' jsonfiles/200
217
218 echo "=== API: Get instances for type 2, shall contain pi2 ==="
219 RESULT="json:[ \"pi2\" ]"
220 do_curl GET '/a1-p/policytypes/2/policies' 200
221
222 if [ $DUP_CHECK == 1 ]; then
223     echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail ==="
224     RESULT=""
225     do_curl PUT '/a1-p/policytypes/1/policies/pi11' 400 jsonfiles/pi1.json
226 else
227     echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall succeed ==="
228     RESULT=""
229     do_curl PUT '/a1-p/policytypes/1/policies/pi11' 202 jsonfiles/pi1.json
230
231     echo "=== Delete policy instance: pi11 ==="
232     RESULT=""
233     do_curl DELETE '/a1-p/policytypes/1/policies/pi11' 202
234 fi
235
236 if [ $DUP_CHECK == 1 ]; then
237     echo "=== API: Create policy instance pi3 (copy of pi1) of type: 2. Shall fail ==="
238     RESULT=""
239     do_curl PUT '/a1-p/policytypes/1/policies/pi3' 400 jsonfiles/pi1.json
240 else
241     echo "=== API: Create policy instance pi3 (copy of pi1) of type: 1. Shall succeed ==="
242     RESULT=""
243     do_curl PUT '/a1-p/policytypes/1/policies/pi3' 202 jsonfiles/pi1.json
244
245     echo "=== Delete policy instance: pi3 ==="
246     RESULT=""
247     do_curl DELETE '/a1-p/policytypes/1/policies/pi3' 202
248 fi
249
250
251 echo "=== API: Get instances for type 1, shall contain pi1 ==="
252 RESULT="json:[ \"pi1\" ]"
253 do_curl GET '/a1-p/policytypes/1/policies' jsonfiles/200
254
255 echo "=== API: Get instances for type 2, shall contain pi2 ==="
256 RESULT="json:[ \"pi2\" ]"
257 do_curl GET '/a1-p/policytypes/2/policies' 200
258
259
260
261 echo "=== Set force response code 401. ==="
262 RESULT="*"
263 do_curl POST '/forceresponse?code=401' 200
264
265 echo "=== API: Get policy status for pi1, shall fail ==="
266 RESULT=""
267 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 401
268
269 echo "=== Set force delay 10. ==="
270 RESULT="Force delay: 10 sec set for all A1 responses"
271 do_curl POST '/forcedelay?delay=10' 200
272
273 echo "=== API: Get policy status for pi1. Shall delay 10 sec ==="
274 RESULT="json:{\"instance_status\": \"NOT IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
275 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
276
277 echo "=== Reset force delay. ==="
278 RESULT="Force delay: None sec set for all A1 responses"
279 do_curl POST '/forcedelay' 200
280
281 echo "=== Set status for pi1 ==="
282 RESULT="Status set to IN EFFECT for policy: pi1"
283 do_curl PUT '/status?policyid=pi1&status=IN%20EFFECT' 200
284
285 echo "=== API: Get policy status for pi1 ==="
286 RESULT="json:{\"instance_status\": \"IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
287 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
288
289 echo "=== Set status for pi1 ==="
290 RESULT="Status set to IN EFFECT and has_been_deleted set to true and created_at set to 2020-03-30 12:00:00 for policy: pi1"
291 do_curl PUT '/status?policyid=pi1&status=IN%20EFFECT&deleted=true&created_at=2020-03-30%2012:00:00' 200
292
293 echo "=== API: Get policy status for pi1 ==="
294 RESULT="json:{\"instance_status\": \"IN EFFECT\", \"has_been_deleted\": \"true\", \"created_at\": \"2020-03-30 12:00:00\"}"
295 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
296
297 echo "=== Get counter: instances ==="
298 RESULT="2"
299 do_curl GET '/counter/num_instances' 200
300
301 echo "=== Get counter: types ==="
302 RESULT="2"
303 do_curl GET '/counter/num_types' 200
304
305 echo "=== Get counter: interface ==="
306 RESULT="OSC_2.1.0"
307 do_curl GET '/counter/interface' 200
308
309 echo "=== Get counter: remote hosts ==="
310 RESULT="*"
311 do_curl GET '/counter/remote_hosts' 200
312
313 echo "=== DELETE policy pi1 ==="
314 RESULT=""
315 do_curl DELETE /a1-p/policytypes/1/policies/pi1 202
316
317 echo "=== API: Get instances for type 1, shall be empty ==="
318 RESULT="[]"
319 do_curl GET /a1-p/policytypes/1/policies 200
320
321 echo "=== API: Get instances for type 2, shall contain pi2 ==="
322 RESULT="[ \"pi2\" ]"
323 do_curl GET /a1-p/policytypes/2/policies 200
324
325 echo "=== Get counter: instances ==="
326 RESULT="1"
327 do_curl GET /counter/num_instances 200
328
329 echo "********************"
330 echo "*** All tests ok ***"
331 echo "********************"