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
57 echo "=== Simulator hello world ==="
61 echo "=== Check used and implemented interfaces ==="
62 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']"
63 do_curl GET /container_interfaces 200
65 echo "=== Reset simulator instances ==="
66 RESULT="All policy instances deleted"
67 do_curl POST /deleteinstances 200
69 echo "=== Reset simulator, all ==="
70 RESULT="All policy instances and types deleted"
71 do_curl POST /deleteall 200
73 echo "=== Get counter: interface ==="
75 do_curl GET /counter/interface 200
77 echo "=== Get counter: remote hosts ==="
79 do_curl GET /counter/remote_hosts 200
81 echo "=== Get counter: intstance ==="
83 do_curl GET /counter/num_instances 200
85 echo "=== Get counter: types (shall be 0)==="
87 do_curl GET /counter/num_types 200
89 echo "=== API: Get policy types, shall be empty array =="
91 do_curl GET /A1-P/v2/policytypes 200
93 echo "=== API: Get policy instances for type 1, type not found=="
94 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"1\"}"
95 do_curl GET /A1-P/v2/policytypes/1/policies 404
97 echo "=== API: Get policy instances, type not found=="
98 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"test\"}"
99 do_curl GET /A1-P/v2/policytypes/test/policies 404
101 echo "=== Put a policy type: STD_1 ==="
102 RESULT="Policy type STD_1 is OK."
103 do_curl PUT '/policytype?id=STD_1' 201 jsonfiles/std_1.json
105 echo "=== Put a policy type: STD_1, again ==="
106 RESULT="Policy type STD_1 is OK."
107 do_curl PUT '/policytype?id=STD_1' 200 jsonfiles/std_1.json
109 echo "=== API: Get policy type ids, shall contain type STD_1 =="
110 RESULT="json:[ \"STD_1\" ]"
111 do_curl GET /A1-P/v2/policytypes 200
113 echo "=== Delete a policy type: STD_1 ==="
115 do_curl DELETE '/policytype?id=STD_1' 204
117 echo "=== API: Get policy type ids, shall be empty =="
119 do_curl GET /A1-P/v2/policytypes 200
121 echo "=== Put a policy type: STD_1 ==="
122 RESULT="Policy type STD_1 is OK."
123 do_curl PUT '/policytype?id=STD_1' 201 jsonfiles/std_1.json
125 echo "=== API: Get policy type ids, shall contain type STD_1 =="
126 RESULT="json:[ \"STD_1\" ]"
127 do_curl GET /A1-P/v2/policytypes 200
129 echo "=== Get counter: types (shall be 1)==="
131 do_curl GET /counter/num_types 200
133 echo "=== API: Get policy type: STD_1 ==="
134 res=$(cat jsonfiles/std_1.json)
136 do_curl GET /A1-P/v2/policytypes/STD_1 200
138 echo "=== API: Get policy instances, shall be empty=="
140 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
142 echo "=== API: Create policy instance pi1 of type: STD_1 ==="
143 res=$(cat jsonfiles/pi1.json)
145 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 201 jsonfiles/pi1.json
147 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
148 res=$(cat jsonfiles/pi1.json)
150 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
152 echo "=== API: Update policy instance pi1 of type: STD_1==="
153 res=$(cat jsonfiles/pi1.json)
155 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1.json
157 echo "=== API: Update policy instance pi1 of type: STD_1==="
158 res=$(cat jsonfiles/pi1_updated.json)
160 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1_updated.json
162 echo "=== API: Duplicate policy instance json, pi2 of type: STD_1==="
163 res=$(cat jsonfiles/pi1_updated.json)
164 if [ $DUP_CHECK == 1 ]; then
165 #Fail with dupl check
166 RESULT="json:{\"title\": \"Duplicate, the policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}"
167 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 400 jsonfiles/pi1_updated.json
169 #OK without dupl check
170 res=$(cat jsonfiles/pi1_updated.json)
172 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi1_updated.json
174 echo "=== API: DELETE policy instance pi2 ==="
176 do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi2 204
179 echo "=== API: Get policy instances, shall contain pi1=="
180 RESULT="json:[ \"pi1\" ]"
181 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
183 echo "=== Put a policy type: STD_2 ==="
184 RESULT="Policy type STD_2 is OK."
185 do_curl PUT '/policytype?id=STD_2' 201 jsonfiles/std_2.json
188 echo "=== API: Duplicate policy instance id pi1 of type: STD_2==="
189 res=$(cat jsonfiles/pi1_updated.json)
190 RESULT="json:{\"title\": \"The policy id already exist for other policy type.\", \"status\": 400, \"instance\": \"pi1\"}"
191 do_curl PUT /A1-P/v2/policytypes/STD_2/policies/pi1 400 jsonfiles/pi1_updated.json
193 echo "=== API: Get policy type ids, shall contain type STD_1 and STD_2 =="
194 RESULT="json:[ \"STD_1\", \"STD_2\" ]"
195 do_curl GET /A1-P/v2/policytypes 200
197 echo "=== Get counter: types (shall be 2)==="
199 do_curl GET /counter/num_types 200
201 echo "=== Get counter: intstance ==="
203 do_curl GET /counter/num_instances 200
206 echo "=== Set force response code 409. ==="
208 do_curl POST '/forceresponse?code=409' 200
210 echo "=== API: Get policy instances, shall fail with 409 =="
211 RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}"
212 do_curl GET /A1-P/v2/policytypes/STD_1/policies 409
214 echo "=== API: Get policy status ==="
215 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
216 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1/status 200
218 echo "=== API: Create policy instance pi2 of type: STD_1 ==="
219 res=$(cat jsonfiles/pi2.json)
221 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi2.json
223 echo "=== API: Update policy instance pi2 of type: STD_1 ==="
224 res=$(cat jsonfiles/pi2.json)
226 do_curl PUT '/A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json
228 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
229 RESULT="json:[ \"pi1\", \"pi2\" ]"
230 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
232 echo "=== Get counter: types (shall be 2)==="
234 do_curl GET /counter/num_types 200
236 echo "=== Get counter: intstance ==="
238 do_curl GET /counter/num_instances 200
240 echo "=== Set force delay 10. ==="
241 RESULT="Force delay: 10 sec set for all A1 responses"
242 do_curl POST '/forcedelay?delay=10' 200
244 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
245 RESULT="json:[ \"pi1\", \"pi2\" ]"
246 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
248 echo "=== Reset force delay. ==="
249 RESULT="Force delay: None sec set for all A1 responses"
250 do_curl POST /forcedelay 200
252 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
253 res=$(cat jsonfiles/pi1_updated.json)
255 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
257 echo "=== API: Get policy instance pi2 of type: STD_1 ==="
258 res=$(cat jsonfiles/pi2.json)
260 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2 200
262 echo "=== API: DELETE policy instance pi1 ==="
264 do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi1 204
266 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
267 RESULT="json:[ \"pi2\" ]"
268 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
270 echo "=== API: Get policy status ==="
271 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
272 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
274 echo "=== Set status for policy instance pi2 ==="
275 RESULT="Status set to OK for policy: pi2"
276 do_curl PUT '/status?policyid=pi2&status=OK' 200
278 echo "=== API: Get policy status ==="
279 RESULT="json:{\"enforceStatus\": \"OK\"}"
280 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
282 echo "=== Set status for policy instance pi2 ==="
283 RESULT="Status set to NOTOK and notok_reason for policy: pi2"
284 do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200
286 echo "=== API: Get policy status ==="
287 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\":\"notok_reason\"}"
288 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
290 echo "=== Send status for pi2==="
291 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
292 do_curl POST '/sendstatus?policyid=pi2' 200
294 echo "=== Get counter: datadelivery ==="
296 do_curl GET /counter/datadelivery 200
298 echo "=== Send data ==="
301 do_curl POST /datadelivery 200 .p.json
303 echo "=== Get counter: datadelivery ==="
305 do_curl GET /counter/datadelivery 200
307 echo "=== Get counter: intstance ==="
309 do_curl GET /counter/num_instances 200
311 echo "=== Get counter: types (shall be 2)==="
313 do_curl GET /counter/num_types 200
315 echo "=== Get counter: interface ==="
317 do_curl GET /counter/interface 200
319 echo "=== Get counter: remote hosts ==="
321 do_curl GET /counter/remote_hosts 200
323 echo "********************"
324 echo "*** All tests ok ***"
325 echo "********************"