3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 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 as this script
23 echo "Usage: ./basic_test.sh nonsecure|secure"
26 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
27 echo "Usage: ./basic_test.sh nonsecure|secure"
31 if [ $1 == "nonsecure" ]; then
32 #Default http port for the simulator
37 #Default https port for the simulator
43 . ../common/test_common.sh
45 echo "=== Simulator hello world ==="
49 echo "=== Check used and implemented interfaces ==="
50 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']"
51 do_curl GET /container_interfaces 200
53 echo "=== Reset simulator instances ==="
54 RESULT="All policy instances deleted"
55 do_curl POST /deleteinstances 200
57 echo "=== Reset simulator, all ==="
58 RESULT="All policy instances and types deleted"
59 do_curl POST /deleteall 200
61 echo "=== API: Healthcheck ==="
63 do_curl GET /a1-p/healthcheck 200
65 echo "=== API: Get policy types, shall be empty array =="
67 do_curl GET /a1-p/policytypes 200
69 echo "=== API: Delete a policy type, shall fail =="
71 do_curl DELETE /a1-p/policytypes/1 404
73 echo "=== API: Get policy instances for type 1, shall fail =="
75 do_curl GET /a1-p/policytypes/1/policies 404
77 echo "=== API: Put a policy type: 1 ==="
79 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
81 echo "=== API: Put a policy type: 1, again ==="
83 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
85 echo "=== API: Delete a policy type: 1 ==="
87 do_curl DELETE /a1-p/policytypes/1 204
89 echo "=== API: Get policy type ids, shall be empty =="
91 do_curl GET /a1-p/policytypes 200
93 echo "=== API: Load a policy type: 1 ==="
95 do_curl PUT /a1-p/policytypes/1 201 jsonfiles/pt1.json
97 echo "=== API: Get policy type ids, shall contain type 1 =="
99 do_curl GET /a1-p/policytypes 200
101 echo "=== API: Get instances for type 1, shall be empty ==="
103 do_curl GET '/a1-p/policytypes/1/policies' 200
105 echo "=== API: Create policy instance pi1 of type: 1 ==="
107 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
109 echo "=== API: Update policy instance pi1 of type: 1 ==="
111 do_curl PUT '/a1-p/policytypes/1/policies/pi1' 202 jsonfiles/pi1.json
113 echo "=== API: Load a policy type: 1, shall fail ==="
115 do_curl PUT /a1-p/policytypes/1 400 jsonfiles/pt1.json
117 echo "=== API: Get instances for type 1, shall contain pi1 ==="
118 RESULT="json:[ \"pi1\" ]"
119 do_curl GET '/a1-p/policytypes/1/policies' 200
121 echo "=== API: Create policy instance pi2 (copy of pi1) of type: 1. Shall fail ==="
123 do_curl PUT '/a1-p/policytypes/1/policies/pi2' 400 jsonfiles/pi1.json
125 echo "=== Set force response code 401. ==="
127 do_curl POST '/forceresponse?code=401' 200
129 echo "=== API: Get policy type 1. Shall fail with forced code ==="
131 do_curl GET '/a1-p/policytypes/1' 401
133 echo "=== API: Get policy status ==="
134 RESULT="json:{\"instance_status\": \"NOT IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
135 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
137 echo "=== Load a policy type: 2 ==="
138 RESULT="Policy type 2 is OK."
139 do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json
141 echo "=== Load a policy type: 2 again. ==="
142 RESULT="Policy type 2 is OK."
143 do_curl PUT '/policytype?id=2' 200 jsonfiles/pt2.json
145 echo "=== API: Get policy type ids, shall contain type 1 and 2 =="
146 RESULT="json:[ 1, 2 ]"
147 do_curl GET /a1-p/policytypes 200
149 echo "=== Get policy type ids, shall contain type 1 and 2 =="
150 RESULT="json:[\"1\", \"2\"]"
151 do_curl GET /policytypes 200
153 echo "=== API: Get policy type 2 =="
154 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\"]}}}}"
155 do_curl GET /a1-p/policytypes/2 200
157 echo "=== Delete policy type: 2 ==="
159 do_curl DELETE '/policytype?id=2' 204 jsonfiles/pt2.json
161 echo "=== API: Get policy type ids, shall contain type 1 =="
163 do_curl GET /a1-p/policytypes 200
165 echo "=== Load a policy type: 2 ==="
166 RESULT="Policy type 2 is OK."
167 do_curl PUT '/policytype?id=2' 201 jsonfiles/pt2.json
169 echo "=== API: Get policy type 2 =="
170 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\"]}}}}"
171 do_curl GET /a1-p/policytypes/2 200
173 echo "=== API: Get instances for type 2, shall be empty ==="
175 do_curl GET '/a1-p/policytypes/2/policies' 200
177 echo "=== API: Create policy instance pi1 of type: 2, shall fail==="
179 do_curl PUT '/a1-p/policytypes/2/policies/pi1' 400 jsonfiles/pi1.json
181 echo "=== API: Create policy instance pi2 of type: 2. Missing param, shall fail. ==="
183 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 400 jsonfiles/pi2_missing_param.json
185 echo "=== API: Create policy instance pi2 of type: 2 ==="
187 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
189 echo "=== API: Update policy instance pi2 of type: 2 ==="
191 do_curl PUT '/a1-p/policytypes/2/policies/pi2' 202 jsonfiles/pi2.json
193 echo "=== API: Get instances for type 1, shall contain pi1 ==="
194 RESULT="json:[ \"pi1\" ]"
195 do_curl GET '/a1-p/policytypes/1/policies' jsonfiles/200
197 echo "=== API: Get instances for type 2, shall contain pi2 ==="
198 RESULT="json:[ \"pi2\" ]"
199 do_curl GET '/a1-p/policytypes/2/policies' 200
201 echo "=== API: Create policy instance pi11 (copy of pi1) of type: 1. Shall fail ==="
203 do_curl PUT '/a1-p/policytypes/1/policies/pi11' 400 jsonfiles/pi1.json
205 echo "=== Set force response code 401. ==="
207 do_curl POST '/forceresponse?code=401' 200
209 echo "=== API: Get policy status for pi1, shall fail ==="
211 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 401
213 echo "=== Set force delay 10. ==="
214 RESULT="Force delay: 10 sec set for all A1 responses"
215 do_curl POST '/forcedelay?delay=10' 200
217 echo "=== API: Get policy status for pi1. Shall delay 10 sec ==="
218 RESULT="json:{\"instance_status\": \"NOT IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
219 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
221 echo "=== Reset force delay. ==="
222 RESULT="Force delay: None sec set for all A1 responses"
223 do_curl POST '/forcedelay' 200
225 echo "=== Set status for pi1 ==="
226 RESULT="Status set to IN EFFECT for policy: pi1"
227 do_curl PUT '/status?policyid=pi1&status=IN%20EFFECT' 200
229 echo "=== API: Get policy status for pi1 ==="
230 RESULT="json:{\"instance_status\": \"IN EFFECT\", \"has_been_deleted\": \"false\", \"created_at\": \"????\"}"
231 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
233 echo "=== Set status for pi1 ==="
234 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"
235 do_curl PUT '/status?policyid=pi1&status=IN%20EFFECT&deleted=true&created_at=2020-03-30%2012:00:00' 200
237 echo "=== API: Get policy status for pi1 ==="
238 RESULT="json:{\"instance_status\": \"IN EFFECT\", \"has_been_deleted\": \"true\", \"created_at\": \"2020-03-30 12:00:00\"}"
239 do_curl GET '/a1-p/policytypes/1/policies/pi1/status' 200
241 echo "=== Get counter: instances ==="
243 do_curl GET '/counter/num_instances' 200
245 echo "=== Get counter: types ==="
247 do_curl GET '/counter/num_types' 200
249 echo "=== Get counter: interface ==="
251 do_curl GET '/counter/interface' 200
253 echo "=== Get counter: remote hosts ==="
255 do_curl GET '/counter/remote_hosts' 200
257 echo "=== DELETE policy pi1 ==="
259 do_curl DELETE /a1-p/policytypes/1/policies/pi1 202
261 echo "=== API: Get instances for type 1, shall be empty ==="
263 do_curl GET /a1-p/policytypes/1/policies 200
265 echo "=== API: Get instances for type 2, shall contain pi2 ==="
267 do_curl GET /a1-p/policytypes/2/policies 200
269 echo "=== Get counter: instances ==="
271 do_curl GET /counter/num_instances 200
273 echo "********************"
274 echo "*** All tests ok ***"
275 echo "********************"