Tidy up readme file markdown
[sim/a1-interface.git] / near-rt-ric-simulator / test / STD_2.0.0 / basic_test.sh
1 #!/bin/bash
2
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
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
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=================================================
18 #
19
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
22
23 print_usage() {
24     echo "Usage: ./basic_test.sh nonsecure|secure duplicate-check|ignore-duplicate "
25     exit 1
26 }
27
28 if [ $# -ne 2 ]; then
29     print_usage
30 fi
31 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
32     print_usage
33 fi
34 if [ "$2" == "duplicate-check" ]; then
35     DUP_CHECK=1
36 elif [ "$2" == "ignore-duplicate" ]; then
37     DUP_CHECK=0
38 else
39     print_usage
40 fi
41
42 if [ $1 == "nonsecure" ]; then
43     #Default http port for the simulator
44     PORT=8085
45     # Set http protocol
46     HTTPX="http"
47 else
48     #Default https port for the simulator
49     PORT=8185
50     # Set https protocol
51     HTTPX="https"
52 fi
53
54 . ../common/test_common.sh
55
56
57 echo "=== Simulator hello world ==="
58 RESULT="OK"
59 do_curl GET / 200
60
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
64
65 echo "=== Reset simulator instances ==="
66 RESULT="All policy instances deleted"
67 do_curl POST /deleteinstances 200
68
69 echo "=== Reset simulator, all ==="
70 RESULT="All policy instances and types deleted"
71 do_curl POST /deleteall 200
72
73 echo "=== Get counter: interface ==="
74 RESULT="STD_2.0.0"
75 do_curl GET /counter/interface 200
76
77 echo "=== Get counter: remote hosts ==="
78 RESULT="*"
79 do_curl GET /counter/remote_hosts 200
80
81 echo "=== Get counter: intstance ==="
82 RESULT="0"
83 do_curl GET /counter/num_instances 200
84
85 echo "=== Get counter: types (shall be 0)==="
86 RESULT="0"
87 do_curl GET /counter/num_types 200
88
89 echo "=== API: Get policy types, shall be empty array =="
90 RESULT="json:[]"
91 do_curl GET /A1-P/v2/policytypes 200
92
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
96
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
100
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
104
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
108
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
112
113 echo "=== Delete a policy type: STD_1 ==="
114 RESULT=""
115 do_curl DELETE  '/policytype?id=STD_1' 204
116
117 echo "=== API: Get policy type ids, shall be empty =="
118 RESULT="json:[]"
119 do_curl GET  /A1-P/v2/policytypes 200
120
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
124
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
128
129 echo "=== Get counter: types (shall be 1)==="
130 RESULT="1"
131 do_curl GET /counter/num_types 200
132
133 echo "=== API: Get policy type: STD_1 ==="
134 res=$(cat jsonfiles/std_1.json)
135 RESULT="json:$res"
136 do_curl GET /A1-P/v2/policytypes/STD_1 200
137
138 echo "=== API: Get policy instances, shall be empty=="
139 RESULT="json:[ ]"
140 do_curl GET /A1-P/v2/policytypes/STD_1/policies 200
141
142 echo "=== API: Create policy instance pi1 of type: STD_1 ==="
143 res=$(cat jsonfiles/pi1.json)
144 RESULT="json:$res"
145 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 201 jsonfiles/pi1.json
146
147 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
148 res=$(cat jsonfiles/pi1.json)
149 RESULT="json:$res"
150 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
151
152 echo "=== API: Update policy instance pi1 of type: STD_1==="
153 res=$(cat jsonfiles/pi1.json)
154 RESULT="json:$res"
155 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1.json
156
157 echo "=== API: Update policy instance pi1 of type: STD_1==="
158 res=$(cat jsonfiles/pi1_updated.json)
159 RESULT="json:$res"
160 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi1 200 jsonfiles/pi1_updated.json
161
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
168 else
169     #OK without dupl check
170     res=$(cat jsonfiles/pi1_updated.json)
171     RESULT="json:$res"
172     do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi1_updated.json
173
174     echo "=== API: DELETE policy instance pi2 ==="
175     RESULT=""
176     do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi2 204
177 fi
178
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
182
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
186
187
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
192
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
196
197 echo "=== Get counter: types (shall be 2)==="
198 RESULT="2"
199 do_curl GET /counter/num_types 200
200
201 echo "=== Get counter: intstance ==="
202 RESULT="1"
203 do_curl GET /counter/num_instances 200
204
205
206 echo "=== Set force response code 409. ==="
207 RESULT="*"
208 do_curl POST '/forceresponse?code=409' 200
209
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
213
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
217
218 echo "=== API: Create policy instance pi2 of type: STD_1 ==="
219 res=$(cat jsonfiles/pi2.json)
220 RESULT="json:$res"
221 do_curl PUT /A1-P/v2/policytypes/STD_1/policies/pi2 201 jsonfiles/pi2.json
222
223 echo "=== API: Update policy instance pi2 of type: STD_1 ==="
224 res=$(cat jsonfiles/pi2.json)
225 RESULT="json:$res"
226 do_curl PUT '/A1-P/v2/policytypes/STD_1/policies/pi2?notificationDestination=http://localhost:2223/statustest' 200 jsonfiles/pi2.json
227
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
231
232 echo "=== Get counter: types (shall be 2)==="
233 RESULT="2"
234 do_curl GET /counter/num_types 200
235
236 echo "=== Get counter: intstance ==="
237 RESULT="2"
238 do_curl GET /counter/num_instances 200
239
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
243
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
247
248 echo "=== Reset force delay. ==="
249 RESULT="Force delay: None sec set for all A1 responses"
250 do_curl POST /forcedelay 200
251
252 echo "=== API: Get policy instance pi1 of type: STD_1 ==="
253 res=$(cat jsonfiles/pi1_updated.json)
254 RESULT="json:$res"
255 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi1 200
256
257 echo "=== API: Get policy instance pi2 of type: STD_1 ==="
258 res=$(cat jsonfiles/pi2.json)
259 RESULT="json:$res"
260 do_curl GET /A1-P/v2/policytypes/STD_1/policies/pi2 200
261
262 echo "=== API: DELETE policy instance pi1 ==="
263 RESULT=""
264 do_curl DELETE /A1-P/v2/policytypes/STD_1/policies/pi1 204
265
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
269
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
273
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
277
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
281
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
285
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
289
290 echo "=== Send status for pi2==="
291 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
292 do_curl POST '/sendstatus?policyid=pi2' 200
293
294 echo "=== Get counter: datadelivery ==="
295 RESULT="0"
296 do_curl GET /counter/datadelivery 200
297
298 echo "=== Send data ==="
299 echo "{}" > .p.json
300 RESULT=""
301 do_curl POST /datadelivery 200 .p.json
302
303 echo "=== Get counter: datadelivery ==="
304 RESULT="1"
305 do_curl GET /counter/datadelivery 200
306
307 echo "=== Get counter: intstance ==="
308 RESULT="1"
309 do_curl GET /counter/num_instances 200
310
311 echo "=== Get counter: types (shall be 2)==="
312 RESULT="2"
313 do_curl GET /counter/num_types 200
314
315 echo "=== Get counter: interface ==="
316 RESULT="STD_2.0.0"
317 do_curl GET /counter/interface 200
318
319 echo "=== Get counter: remote hosts ==="
320 RESULT="*"
321 do_curl GET /counter/remote_hosts 200
322
323 echo "********************"
324 echo "*** All tests ok ***"
325 echo "********************"