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
46 echo "=== Simulator hello world ==="
50 echo "=== Check used and implemented interfaces ==="
51 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']"
52 do_curl GET /container_interfaces 200
54 echo "=== Reset simulator instances ==="
55 RESULT="All policy instances deleted"
56 do_curl POST /deleteinstances 200
58 echo "=== Reset simulator, all ==="
59 RESULT="All policy instances and types deleted"
60 do_curl POST /deleteall 200
62 echo "=== Get counter: interface ==="
64 do_curl GET /counter/interface 200
66 echo "=== Get counter: remote hosts ==="
68 do_curl GET /counter/remote_hosts 200
70 echo "=== Get counter: intstance ==="
72 do_curl GET /counter/num_instances 200
74 echo "=== Get counter: types (shall be 0)==="
76 do_curl GET /counter/num_types 200
78 echo "=== API: Get policy types, shall be empty array =="
80 do_curl GET /A1-P/v2/policytypes 200
82 echo "=== API: Get policy instances for type 1, type not found=="
83 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"1\"}"
84 do_curl GET /A1-P/v2/policytypes/1/policies 404
86 echo "=== API: Get policy instances, type not found=="
87 RESULT="json:{\"title\": \"The policy type does not exist.\", \"status\": 404, \"instance\": \"test\"}"
88 do_curl GET /A1-P/v2/policytypes/test/policies 404
90 echo "=== Put a policy type: STD_1 ==="
91 RESULT="Policy type STD_1 is OK."
92 do_curl PUT '/policytype?id=STD_1' 201 jsonfiles/std_1.json
94 echo "=== Put a policy type: STD_1, again ==="
95 RESULT="Policy type STD_1 is OK."
96 do_curl PUT '/policytype?id=STD_1' 200 jsonfiles/std_1.json
98 echo "=== API: Get policy type ids, shall contain type STD_1 =="
99 RESULT="json:[ \"STD_1\" ]"
100 do_curl GET /A1-P/v2/policytypes 200
102 echo "=== Delete a policy type: STD_1 ==="
104 do_curl DELETE '/policytype?id=STD_1' 204
106 echo "=== API: Get policy type ids, shall be empty =="
108 do_curl GET /A1-P/v2/policytypes 200
110 echo "=== Put a policy type: STD_1 ==="
111 RESULT="Policy type STD_1 is OK."
112 do_curl PUT '/policytype?id=STD_1' 201 jsonfiles/std_1.json
114 echo "=== API: Get policy type ids, shall contain type STD_1 =="
115 RESULT="json:[ \"STD_1\" ]"
116 do_curl GET /A1-P/v2/policytypes 200
118 echo "=== Get counter: types (shall be 1)==="
120 do_curl GET /counter/num_types 200
122 echo "=== API: Get policy type: STD_1 ==="
123 res=$(cat jsonfiles/std_1.json)
125 do_curl GET /A1-P/v2/policytypes/STD_1 200
127 echo "=== API: Get policy instances, shall be empty=="
129 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
131 echo "=== API: Create policy instance pi1 of type: STD_1 ==="
132 res=$(cat jsonfiles/pi1.json)
134 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 201 jsonfiles/pi1.json
136 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
137 res=$(cat jsonfiles/pi1.json)
139 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
141 echo "=== API: Update policy instance pi1 of type: STD_1==="
142 res=$(cat jsonfiles/pi1.json)
144 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1.json
146 echo "=== API: Update policy instance pi1 of type: STD_1==="
147 res=$(cat jsonfiles/pi1_updated.json)
149 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1_updated.json
151 echo "=== API: Duplicate policy instance pi2 of type: STD_1==="
152 res=$(cat jsonfiles/pi1_updated.json)
153 RESULT="json:{\"title\": \"Duplicate, the policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}"
154 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 400 jsonfiles/pi1_updated.json
156 echo "=== API: Get policy instances, shall contain pi1=="
157 RESULT="json:[ \"pi1\" ]"
158 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
160 echo "=== Get counter: types (shall be 1)==="
162 do_curl GET /counter/num_types 200
164 echo "=== Get counter: intstance ==="
166 do_curl GET /counter/num_instances 200
169 echo "=== Set force response code 409. ==="
171 do_curl POST '/forceresponse?code=409' 200
173 echo "=== API: Get policy instances, shall fail with 409 =="
174 RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}"
175 do_curl GET /A1-P/v2/policytypes/STD_1/policies 409
177 echo "=== API: Get policy status ==="
178 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
179 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1/status 200
181 echo "=== API: Create policy instance pi2 of type: STD_1 ==="
182 res=$(cat jsonfiles/pi2.json)
184 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi2.json
186 echo "=== API: Update policy instance pi2 of type: STD_1 ==="
187 res=$(cat jsonfiles/pi2.json)
189 do_curl PUT '/A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json
191 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
192 RESULT="json:[ \"pi1\", \"pi2\" ]"
193 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
195 echo "=== Get counter: types (shall be 1)==="
197 do_curl GET /counter/num_types 200
199 echo "=== Get counter: intstance ==="
201 do_curl GET /counter/num_instances 200
203 echo "=== Set force delay 10. ==="
204 RESULT="Force delay: 10 sec set for all A1 responses"
205 do_curl POST '/forcedelay?delay=10' 200
207 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
208 RESULT="json:[ \"pi1\", \"pi2\" ]"
209 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
211 echo "=== Reset force delay. ==="
212 RESULT="Force delay: None sec set for all A1 responses"
213 do_curl POST /forcedelay 200
215 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
216 res=$(cat jsonfiles/pi1_updated.json)
218 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
220 echo "=== API: Get policy instance pi2 of type: STD_1 ==="
221 res=$(cat jsonfiles/pi2.json)
223 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2 200
225 echo "=== API: DELETE policy instance pi1 ==="
227 do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi1 204
229 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
230 RESULT="json:[ \"pi2\" ]"
231 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
233 echo "=== API: Get policy status ==="
234 RESULT="json:{\"enforceStatus\": \"\", \"enforceReason\": \"\"}"
235 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
237 echo "=== Set status for policy instance pi2 ==="
238 RESULT="Status set to OK for policy: pi2"
239 do_curl PUT '/status?policyid=pi2&status=OK' 200
241 echo "=== API: Get policy status ==="
242 RESULT="json:{\"enforceStatus\": \"OK\"}"
243 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
245 echo "=== Set status for policy instance pi2 ==="
246 RESULT="Status set to NOTOK and notok_reason for policy: pi2"
247 do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200
249 echo "=== API: Get policy status ==="
250 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\":\"notok_reason\"}"
251 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2/status 200
253 echo "=== Send status for pi2==="
254 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
255 do_curl POST '/sendstatus?policyid=pi2' 200
257 echo "=== Get counter: datadelivery ==="
259 do_curl GET /counter/datadelivery 200
261 echo "=== Send data ==="
264 do_curl POST /datadelivery 200 .p.json
266 echo "=== Get counter: datadelivery ==="
268 do_curl GET /counter/datadelivery 200
270 echo "=== Get counter: intstance ==="
272 do_curl GET /counter/num_instances 200
274 echo "=== Get counter: types (shall be 0)==="
276 do_curl GET /counter/num_types 200
278 echo "=== Get counter: interface ==="
280 do_curl GET /counter/interface 200
282 echo "=== Get counter: remote hosts ==="
284 do_curl GET /counter/remote_hosts 200
286 echo "********************"
287 echo "*** All tests ok ***"
288 echo "********************"