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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
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
24 echo "Usage: ./basic_test.sh nonsecure|secure duplicate-check|ignore-duplicate "
31 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
34 if [ "$2" == "duplicate-check" ]; then
36 elif [ "$2" == "ignore-duplicate" ]; then
42 if [ $1 == "nonsecure" ]; then
43 #Default http port for the simulator
48 #Default https port for the simulator
54 . ../common/test_common.sh
56 echo "=== Simulator hello world ==="
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
64 echo "=== Reset simulator instances ==="
65 RESULT="All policy instances deleted"
66 do_curl POST /deleteinstances 200
68 echo "=== Reset simulator, all ==="
69 RESULT="All policy instances and types deleted"
70 do_curl POST /deleteall 200
72 echo "=== API: Healthcheck ==="
74 do_curl GET /a1-p/healthcheck 200
76 echo "=== API: Get policy types, shall be empty array =="
78 do_curl GET /a1-p/policytypes 200
80 echo "=== API: Delete a policy type, shall fail =="
82 do_curl DELETE /a1-p/policytypes/1 404
84 echo "=== API: Get policy instances for type 1, shall fail =="
86 do_curl GET /a1-p/policytypes/1/policies 404
88 echo "=== API: Put a policy type: 1 ==="
90 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
92 echo "=== API: Put a policy type: 1, again ==="
94 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
96 echo "=== API: Delete a policy type: 1 ==="
98 do_curl DELETE /a1-p/policytypes/1 204
100 echo "=== API: Get policy type ids, shall be empty =="
102 do_curl GET /a1-p/policytypes 200
104 echo "=== API: Load a policy type: 1 ==="
106 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
108 echo "=== API: Get policy type ids, shall contain type 1 =="
110 do_curl GET /a1-p/policytypes 200
112 echo "=== API: Get instances for type 1, shall be empty ==="
114 do_curl GET '/a1-p/policytypes/1/policies' 200
116 echo "=== API: Create policy instance pi1 of type: 1 ==="
118 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
120 echo "=== API: Update policy instance pi1 of type: 1 ==="
122 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
124 echo "=== API: Load a policy type: 1, shall fail ==="
126 do_curl PUT /a1-p/policytypes/1 400 jsonfiles/pt1.json
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
132 if [ $DUP_CHECK == 1 ]; then
133 echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail ==="
135 do_curl PUT '/a1-p/policytypes/1/policies/pi2' 400 jsonfiles/pi1.json
137 echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall succeed ==="
139 do_curl PUT '/a1-p/policytypes/1/policies/pi2' 202 jsonfiles/pi1.json
141 echo "=== Delete policy instance: pi2 ==="
143 do_curl DELETE '/a1-p/policytypes/1/policies/pi2' 202
146 echo "=== Set force response code 401. ==="
148 do_curl POST '/forceresponse?code=401' 200
150 echo "=== API: Get policy type 1. Shall fail with forced code ==="
152 do_curl GET '/a1-p/policytypes/1' 401
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
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
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
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
170 echo "=== Get policy type ids, shall contain type 1 and 2 =="
171 RESULT="json:[\"1\", \"2\"]"
172 do_curl GET /policytypes 200
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
178 echo "=== Delete policy type: 2 ==="
180 do_curl DELETE '/policytype?id=2' 204 jsonfiles/pt2.json
182 echo "=== API: Get policy type ids, shall contain type 1 =="
184 do_curl GET /a1-p/policytypes 200
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
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
194 echo "=== API: Get instances for type 2, shall be empty ==="
196 do_curl GET '/a1-p/policytypes/2/policies' 200
198 echo "=== API: Create duplicate policy instance id pi1 of type: 2 (pi1 exist for type 1), shall fail==="
200 do_curl PUT '/a1-p/policytypes/2/policies/pi1' 400 jsonfiles/pi1.json
202 echo "=== API: Create policy instance pi2 of type: 2. Missing param, shall fail. ==="
204 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 400 jsonfiles/pi2_missing_param.json
206 echo "=== API: Create policy instance pi2 of type: 2 ==="
208 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
210 echo "=== API: Update policy instance pi2 of type: 2 ==="
212 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
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
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
222 if [ $DUP_CHECK == 1 ]; then
223 echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail ==="
225 do_curl PUT '/a1-p/policytypes/1/policies/pi11' 400 jsonfiles/pi1.json
227 echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall succeed ==="
229 do_curl PUT '/a1-p/policytypes/1/policies/pi11' 202 jsonfiles/pi1.json
231 echo "=== Delete policy instance: pi11 ==="
233 do_curl DELETE '/a1-p/policytypes/1/policies/pi11' 202
236 if [ $DUP_CHECK == 1 ]; then
237 echo "=== API: Create policy instance pi3 (copy of pi1) of type: 2. Shall fail ==="
239 do_curl PUT '/a1-p/policytypes/1/policies/pi3' 400 jsonfiles/pi1.json
241 echo "=== API: Create policy instance pi3 (copy of pi1) of type: 1. Shall succeed ==="
243 do_curl PUT '/a1-p/policytypes/1/policies/pi3' 202 jsonfiles/pi1.json
245 echo "=== Delete policy instance: pi3 ==="
247 do_curl DELETE '/a1-p/policytypes/1/policies/pi3' 202
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
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
261 echo "=== Set force response code 401. ==="
263 do_curl POST '/forceresponse?code=401' 200
265 echo "=== API: Get policy status for pi1, shall fail ==="
267 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 401
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
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
277 echo "=== Reset force delay. ==="
278 RESULT="Force delay: None sec set for all A1 responses"
279 do_curl POST '/forcedelay' 200
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
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
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
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
297 echo "=== Get counter: instances ==="
299 do_curl GET '/counter/num_instances' 200
301 echo "=== Get counter: types ==="
303 do_curl GET '/counter/num_types' 200
305 echo "=== Get counter: interface ==="
307 do_curl GET '/counter/interface' 200
309 echo "=== Get counter: remote hosts ==="
311 do_curl GET '/counter/remote_hosts' 200
313 echo "=== DELETE policy pi1 ==="
315 do_curl DELETE /a1-p/policytypes/1/policies/pi1 202
317 echo "=== API: Get instances for type 1, shall be empty ==="
319 do_curl GET /a1-p/policytypes/1/policies 200
321 echo "=== API: Get instances for type 2, shall contain pi2 ==="
323 do_curl GET /a1-p/policytypes/2/policies 200
325 echo "=== Get counter: instances ==="
327 do_curl GET /counter/num_instances 200
329 echo "********************"
330 echo "*** All tests ok ***"
331 echo "********************"