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 ext-srv|ext-srv-secure|ignore-ext-srv"
32 if [ $1 != "nonsecure" ] && [ $1 != "secure" ]; then
36 if [ $2 != "duplicate-check" ] && [ $2 != "ignore-duplicate" ]; then
40 if [ $3 != "ext-srv" ] && [ $3 != "ext-srv-secure" ] && [ $3 != "ignore-ext-srv" ]; then
45 if [ $1 == "nonsecure" ]; then
46 #Default http port for the simulator
51 #Default https port for the simulator
57 if [ $2 == "duplicate-check" ]; then
63 if [ $3 == "ext-srv" ]; then
64 #Default http port for the external server
66 # Set http protocol for external server
69 elif [ $3 == "ext-srv-secure" ]; then
70 #Default https port for the external server
72 # Set https protocol for external server
79 . ../common/test_common.sh
82 echo "=== Simulator hello world ==="
86 echo "=== Check used and implemented interfaces ==="
87 RESULT="Current interface: STD_2.0.0 All supported A1 interface yamls in this container: ['OSC_2.1.0', 'STD_1.1.3', 'STD_2.0.0']"
88 do_curl GET /container_interfaces 200
90 echo "=== Reset simulator instances ==="
91 RESULT="All policy instances deleted"
92 do_curl POST /deleteinstances 200
94 echo "=== Reset simulator, all ==="
95 RESULT="All policy instances and types deleted"
96 do_curl POST /deleteall 200
98 #Test all admin functions in the external server
99 if [ $EXT_SRV_EXIST == 1 ]; then
100 echo "=== External server, hello world ==="
102 do_curl_ext_srv GET / 200
104 echo "=== External server, reset all ==="
105 RESULT="All a1 policy instances deleted"
106 do_curl_ext_srv POST /serveradmin/deleteinstances 200
108 echo "=== External server, reset force delay ==="
109 RESULT="Force delay has been resetted for all external server responses"
110 do_curl_ext_srv POST /serveradmin/forcedelay 200
113 echo "=== Get counter: interface ==="
115 do_curl GET /counter/interface 200
117 echo "=== Get counter: remote hosts ==="
119 do_curl GET /counter/remote_hosts 200
121 echo "=== Get counter: intstance ==="
123 do_curl GET /counter/num_instances 200
125 echo "=== Get counter: types (shall be 0)==="
127 do_curl GET /counter/num_types 200
129 echo "=== API: Get policy types, shall be empty array =="
131 do_curl GET /A1-P/v2/policytypes 200
133 echo "=== API: Get policy instances for type 1, type not found=="
134 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"1\"}"
135 do_curl GET /A1-P/v2/policytypes/1/policies 404
137 echo "=== API: Get policy instances, type not found=="
138 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"test\"}"
139 do_curl GET /A1-P/v2/policytypes/test/policies 404
141 echo "=== Put a policy type: STD_1 ==="
142 RESULT="Policy type STD_1 is OK."
143 do_curl PUT '/policytype?id=STD_1' 201 jsonfiles/std_1.json
145 echo "=== Put a policy type: STD_1, again ==="
146 RESULT="Policy type STD_1 is OK."
147 do_curl PUT '/policytype?id=STD_1' 200 jsonfiles/std_1.json
149 echo "=== API: Get policy type ids, shall contain type STD_1 =="
150 RESULT="json:[ \"STD_1\" ]"
151 do_curl GET /A1-P/v2/policytypes 200
153 echo "=== Delete a policy type: STD_1 ==="
155 do_curl DELETE '/policytype?id=STD_1' 204
157 echo "=== API: Get policy type ids, shall be empty =="
159 do_curl GET /A1-P/v2/policytypes 200
161 echo "=== Put a policy type: STD_1 ==="
162 RESULT="Policy type STD_1 is OK."
163 do_curl PUT '/policytype?id=STD_1' 201 jsonfiles/std_1.json
165 echo "=== API: Get policy type ids, shall contain type STD_1 =="
166 RESULT="json:[ \"STD_1\" ]"
167 do_curl GET /A1-P/v2/policytypes 200
169 echo "=== Get counter: types (shall be 1)==="
171 do_curl GET /counter/num_types 200
173 echo "=== API: Get policy type: STD_1 ==="
174 res=$(cat jsonfiles/std_1.json)
176 do_curl GET /A1-P/v2/policytypes/STD_1 200
178 echo "=== API: Get policy instances, shall be empty=="
180 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
182 echo "=== API: Create policy instance pi1 of type: STD_1 ==="
183 res=$(cat jsonfiles/pi1.json)
185 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 201 jsonfiles/pi1.json
187 if [ $EXT_SRV_EXIST == 1 ]; then
188 echo "=== External server, get a pi1 policy: pi1 ==="
189 res=$(cat jsonfiles/pi1.json)
191 do_curl_ext_srv GET /a1policy/pi1 200
194 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
195 res=$(cat jsonfiles/pi1.json)
197 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
199 echo "=== API: Update policy instance pi1 of type: STD_1==="
200 res=$(cat jsonfiles/pi1.json)
202 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1.json
204 if [ $EXT_SRV_EXIST == 1 ]; then
205 echo "=== External server, get a pi1 policy: pi1 ==="
206 res=$(cat jsonfiles/pi1.json)
208 do_curl_ext_srv GET /a1policy/pi1 200
211 echo "=== API: Update policy instance pi1 of type: STD_1==="
212 res=$(cat jsonfiles/pi1_updated.json)
214 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1_updated.json
216 if [ $EXT_SRV_EXIST == 1 ]; then
217 echo "=== External server, get a pi1 policy: pi1 ==="
218 res=$(cat jsonfiles/pi1_updated.json)
220 do_curl_ext_srv GET /a1policy/pi1 200
223 echo "=== API: Duplicate policy instance json, pi2 of type: STD_1==="
224 res=$(cat jsonfiles/pi1_updated.json)
225 if [ $DUP_CHECK == 1 ]; then
226 #Fail with dupl check
227 RESULT="json:{\"title\": \"Duplicate, the policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}"
228 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 400 jsonfiles/pi1_updated.json
230 #OK without dupl check
231 res=$(cat jsonfiles/pi1_updated.json)
233 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi1_updated.json
235 if [ $EXT_SRV_EXIST == 1 ]; then
236 echo "=== External server, get a pi2 policy: pi2 ==="
237 res=$(cat jsonfiles/pi1_updated.json)
239 do_curl_ext_srv GET /a1policy/pi2 200
242 echo "=== API: DELETE policy instance pi2 ==="
244 do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi2 204
246 if [ $EXT_SRV_EXIST == 1 ]; then
247 echo "=== External server, get a pi2 policy: policy instance not found ==="
248 RESULT="json:{\"title\": \"The A1 policy requested does not exist.\", \"status\": 404, \"instance\": \"pi2\"}"
249 do_curl_ext_srv GET /a1policy/pi2 404
253 echo "=== API: Get policy instances, shall contain pi1=="
254 RESULT="json:[ \"pi1\" ]"
255 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
257 if [ $EXT_SRV_EXIST == 1 ]; then
258 echo "=== External server, get policy instances, shall contain pi1=="
259 RESULT="json:[ \"pi1\" ]"
260 do_curl_ext_srv GET /a1policies 200
263 echo "=== Put a policy type: STD_2 ==="
264 RESULT="Policy type STD_2 is OK."
265 do_curl PUT '/policytype?id=STD_2' 201 jsonfiles/std_2.json
267 echo "=== API: Duplicate policy instance id pi1 of type: STD_2==="
268 res=$(cat jsonfiles/pi1_updated.json)
269 RESULT="json:{\"title\": \"The policy id already exist for other policy type.\", \"status\": 400, \"instance\": \"pi1\"}"
270 do_curl PUT /A1-P/v2/policytypes/STD_2/policies/pi1 400 jsonfiles/pi1_updated.json
272 echo "=== API: Get policy type ids, shall contain type STD_1 and STD_2 =="
273 RESULT="json:[ \"STD_1\", \"STD_2\" ]"
274 do_curl GET /A1-P/v2/policytypes 200
276 echo "=== Get counter: types (shall be 2)==="
278 do_curl GET /counter/num_types 200
280 echo "=== Get counter: intstance ==="
282 do_curl GET /counter/num_instances 200
284 echo "=== Set force response code 409. ==="
286 do_curl POST '/forceresponse?code=409' 200
288 echo "=== API: Get policy instances, shall fail with 409 =="
289 RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}"
290 do_curl GET /A1-P/v2/policytypes/STD_1/policies 409
292 echo "=== API: Get policy status ==="
293 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
294 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1/status 200
296 echo "=== API: Create policy instance pi2 of type: STD_1 ==="
297 res=$(cat jsonfiles/pi2.json)
299 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi2.json
301 echo "=== API: Update policy instance pi2 of type: STD_1 ==="
302 res=$(cat jsonfiles/pi2.json)
304 do_curl PUT '/A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json
306 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
307 RESULT="json:[ \"pi1\", \"pi2\" ]"
308 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
310 echo "=== Get counter: types (shall be 2)==="
312 do_curl GET /counter/num_types 200
314 echo "=== Get counter: intstance ==="
316 do_curl GET /counter/num_instances 200
318 echo "=== Set force delay 10. ==="
319 RESULT="Force delay: 10 sec set for all A1 responses"
320 do_curl POST '/forcedelay?delay=10' 200
322 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
323 RESULT="json:[ \"pi1\", \"pi2\" ]"
324 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
326 echo "=== Reset force delay. ==="
327 RESULT="Force delay: None sec set for all A1 responses"
328 do_curl POST /forcedelay 200
330 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
331 res=$(cat jsonfiles/pi1_updated.json)
333 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
335 echo "=== API: Get policy instance pi2 of type: STD_1 ==="
336 res=$(cat jsonfiles/pi2.json)
338 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2 200
340 echo "=== API: DELETE policy instance pi1 ==="
342 do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi1 204
344 echo "=== API: Get policy instances, shall contain pi2=="
345 RESULT="json:[ \"pi2\" ]"
346 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
348 if [ $EXT_SRV_EXIST == 1 ]; then
349 echo "=== External server, get policy instances, shall contain pi2=="
350 RESULT="json:[ \"pi2\" ]"
351 do_curl_ext_srv GET /a1policies 200
354 echo "=== API: Get policy status ==="
355 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
356 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
358 echo "=== Set status for policy instance pi2 ==="
359 RESULT="Status set to OK for policy: pi2"
360 do_curl PUT '/status?policyid=pi2&status=OK' 200
362 echo "=== API: Get policy status ==="
363 RESULT="json:{\"enforceStatus\": \"OK\"}"
364 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
366 echo "=== Set status for policy instance pi2 ==="
367 RESULT="Status set to NOTOK and notok_reason for policy: pi2"
368 do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200
370 echo "=== API: Get policy status ==="
371 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\":\"notok_reason\"}"
372 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
374 echo "=== Send status for pi2==="
375 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
376 do_curl POST '/sendstatus?policyid=pi2' 200
378 echo "=== Get counter: datadelivery ==="
380 do_curl GET /counter/datadelivery 200
382 echo "=== Send data ==="
385 do_curl POST /datadelivery 200 .p.json
387 echo "=== Get counter: datadelivery ==="
389 do_curl GET /counter/datadelivery 200
391 echo "=== Get counter: intstance ==="
393 do_curl GET /counter/num_instances 200
395 echo "=== Get counter: types (shall be 2)==="
397 do_curl GET /counter/num_types 200
399 echo "=== Get counter: interface ==="
401 do_curl GET /counter/interface 200
403 echo "=== Get counter: remote hosts ==="
405 do_curl GET /counter/remote_hosts 200
407 echo "********************"
408 echo "*** All tests ok ***"
409 echo "********************"