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 # res=$(cat jsonfiles/pi1.json)
120 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
122 echo "=== API: Update policy instance pi1 of type: 1 ==="
124 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
125 # res=$(cat jsonfiles/pi1.json)
127 # do_curl PUT '/a1-p/policytypes/1/policies/pi1' 200 jsonfiles/pi1.json
129 echo "=== API: Load a policy type: 1, shall fail ==="
131 do_curl PUT /a1-p/policytypes/1 400 jsonfiles/pt1.json
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
137 if [ $DUP_CHECK == 1 ]; then
138 echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail ==="
140 do_curl PUT '/a1-p/policytypes/1/policies/pi2' 400 jsonfiles/pi1.json
142 echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall succeed ==="
144 do_curl PUT '/a1-p/policytypes/1/policies/pi2' 202 jsonfiles/pi1.json
145 # res=$(cat jsonfiles/pi1.json)
147 # do_curl PUT '/a1-p/policytypes/1/policies/pi2' 200 jsonfiles/pi1.json
149 echo "=== Delete policy instance: pi2 ==="
151 do_curl DELETE '/a1-p/policytypes/1/policies/pi2' 202
154 echo "=== Set force response code 401. ==="
156 do_curl POST '/forceresponse?code=401' 200
158 echo "=== API: Get policy type 1. Shall fail with forced code ==="
160 do_curl GET '/a1-p/policytypes/1' 401
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
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
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
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
178 echo "=== Get policy type ids, shall contain type 1 and 2 =="
179 RESULT="json:[\"1\", \"2\"]"
180 do_curl GET /policytypes 200
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
186 echo "=== Delete policy type: 2 ==="
188 do_curl DELETE '/policytype?id=2' 204 jsonfiles/pt2.json
190 echo "=== API: Get policy type ids, shall contain type 1 =="
192 do_curl GET /a1-p/policytypes 200
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
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
202 echo "=== API: Get instances for type 2, shall be empty ==="
204 do_curl GET '/a1-p/policytypes/2/policies' 200
206 echo "=== API: Create duplicate policy instance id pi1 of type: 2 (pi1 exist for type 1), shall fail==="
208 do_curl PUT '/a1-p/policytypes/2/policies/pi1' 400 jsonfiles/pi1.json
210 echo "=== API: Create policy instance pi2 of type: 2. Missing param, shall fail. ==="
212 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 400 jsonfiles/pi2_missing_param.json
214 echo "=== API: Create policy instance pi2 of type: 2 ==="
216 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
217 # res=$(cat jsonfiles/pi2.json)
219 # do_curl PUT '/a1-p/policytypes/2/policies/pi2' 200 jsonfiles/pi2.json
221 echo "=== API: Update policy instance pi2 of type: 2 ==="
223 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
225 echo "=== API: Update policy instance pi2 of type: 2 ==="
227 do_curl PUT "/a1-p/policytypes/2/policies/pi2?notificationDestination=http://localhost:${PORT}/statustest" 202 jsonfiles/pi2.json
229 echo "=== Send status for pi2==="
231 do_curl POST '/sendstatus?policyid=pi2' 201 jsonfiles/pi2.json
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
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
241 if [ $DUP_CHECK == 1 ]; then
242 echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail ==="
244 do_curl PUT '/a1-p/policytypes/1/policies/pi11' 400 jsonfiles/pi1.json
246 echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall succeed ==="
248 do_curl PUT '/a1-p/policytypes/1/policies/pi11' 202 jsonfiles/pi1.json
249 # res=$(cat jsonfiles/pi1.json)
251 # do_curl PUT '/a1-p/policytypes/1/policies/pi11' 200 jsonfiles/pi1.json
253 echo "=== Delete policy instance: pi11 ==="
255 do_curl DELETE '/a1-p/policytypes/1/policies/pi11' 202
258 if [ $DUP_CHECK == 1 ]; then
259 echo "=== API: Create policy instance pi3 (copy of pi1) of type: 2. Shall fail ==="
261 do_curl PUT '/a1-p/policytypes/1/policies/pi3' 400 jsonfiles/pi1.json
263 echo "=== API: Create policy instance pi3 (copy of pi1) of type: 1. Shall succeed ==="
265 do_curl PUT '/a1-p/policytypes/1/policies/pi3' 202 jsonfiles/pi1.json
266 # res=$(cat jsonfiles/pi1.json)
268 # do_curl PUT '/a1-p/policytypes/1/policies/pi3' 200 jsonfiles/pi1.json
270 echo "=== Delete policy instance: pi3 ==="
272 do_curl DELETE '/a1-p/policytypes/1/policies/pi3' 202
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
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
283 echo "=== Set force response code 401. ==="
285 do_curl POST '/forceresponse?code=401' 200
287 echo "=== API: Get policy status for pi1, shall fail ==="
289 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 401
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
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
299 echo "=== Reset force delay. ==="
300 RESULT="Force delay: None sec set for all A1 responses"
301 do_curl POST '/forcedelay' 200
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
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
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
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
319 echo "=== Get counter: instances ==="
321 do_curl GET '/counter/num_instances' 200
323 echo "=== Get counter: types ==="
325 do_curl GET '/counter/num_types' 200
327 echo "=== Get counter: interface ==="
329 do_curl GET '/counter/interface' 200
331 echo "=== Get counter: remote hosts ==="
333 do_curl GET '/counter/remote_hosts' 200
335 echo "=== DELETE policy pi1 ==="
337 do_curl DELETE /a1-p/policytypes/1/policies/pi1 202
339 echo "=== API: Get instances for type 1, shall be empty ==="
341 do_curl GET /a1-p/policytypes/1/policies 200
343 echo "=== API: Get instances for type 2, shall contain pi2 ==="
344 RESULT="json:[ \"pi2\" ]"
345 do_curl GET /a1-p/policytypes/2/policies 200
347 echo "=== Get counter: instances ==="
349 do_curl GET /counter/num_instances 200
351 echo "=== Get counter: datadelivery ==="
353 do_curl GET /counter/datadelivery 200
355 echo "********************"
356 echo "*** All tests ok ***"
357 echo "********************"