Update a1-interface with nginx to support https
[sim/a1-interface.git] / near-rt-ric-simulator / test / STD_1.1.3 / basic_test.sh
1 #!/bin/bash
2
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
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 as this script
22 if [ $# -ne 1 ]; then
23     echo "Usage: ./basic_test.sh nonsecure|secure"
24     exit 1
25 fi
26 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
27     echo "Usage: ./basic_test.sh nonsecure|secure"
28     exit 1
29 fi
30
31 if [ $1 == "nonsecure" ]; then
32     #Default http port for the simulator
33     PORT=8085
34     # Set http protocol
35     HTTPX="http"
36 else
37     #Default https port for the simulator
38     PORT=8185
39     # Set https protocol
40     HTTPX="https"
41 fi
42
43 . ../common/test_common.sh
44
45
46 echo "=== Simulator hello world ==="
47 RESULT="OK"
48 do_curl GET / 200
49
50 echo "=== Check used and implemented interfaces ==="
51 RESULT="Current interface: STD_1.1.3 All supported A1 interface yamls in this container: ['1.1.x-alpha.2', 'OSC_2.1.0', 'STD_1.1.3']"
52 do_curl GET /container_interfaces 200
53
54 echo "=== Reset simulator instances ==="
55 RESULT="All policy instances deleted"
56 do_curl POST /deleteinstances 200
57
58 echo "=== Reset simulator, all ==="
59 RESULT="All policy instances deleted"
60 do_curl POST /deleteall 200
61
62 echo "=== API: Get policy instances, shall be empty=="
63 RESULT="json:[]"
64 do_curl GET /A1-P/v1/policies 200
65
66 echo "=== API: Create policy instance pi1 ==="
67 RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 5}}"
68 do_curl PUT /A1-P/v1/policies/pi1 201 jsonfiles/pi1.json
69
70 echo "=== API: Update policy instance pi1 ==="
71 RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 6}}"
72 do_curl PUT /A1-P/v1/policies/pi1 200 jsonfiles/pi1_updated.json
73
74 echo "=== API: Get policy instances, shall contain pi1=="
75 RESULT="json:[ \"pi1\" ]"
76 do_curl GET /A1-P/v1/policies 200
77
78 echo "=== API: Create policy instance pi2 (copy of pi1). Shall fail ==="
79 RESULT="json:{\"title\": \"The policy json already exists.\", \"status\": 400, \"instance\": \"pi2\"}"
80 do_curl PUT /A1-P/v1/policies/pi2 400 jsonfiles/pi1_updated.json
81
82 echo "=== Set force response code 409. ==="
83 RESULT="*"
84 do_curl POST '/forceresponse?code=409' 200
85
86 echo "=== API: Get policy instances, shall fail =="
87 RESULT="json:{\"title\": \"Conflict\", \"status\": 409, \"detail\": \"Request could not be processed in the current state of the resource\"}"
88 do_curl GET /A1-P/v1/policies 409
89
90 echo "=== API: Get policy status ==="
91 RESULT="json:{\"enforceStatus\": \"UNDEFINED\"}"
92 do_curl GET /A1-P/v1/policies/pi1/status 200
93
94 echo "=== API: Create policy instance pi2 ==="
95 RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}"
96 do_curl PUT /A1-P/v1/policies/pi2 201 jsonfiles/pi2.json
97
98 echo "=== API: Update policy instance pi2 ==="
99 RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}"
100 do_curl PUT '/A1-P/v1/policies/pi2?notificationDestination='$HTTPX'://localhost:'$PORT'/statustest' 200 jsonfiles/pi2.json
101
102 echo "=== API: Get policy instances, shall contain pi1 and pi2=="
103 RESULT="json:[ \"pi1\", \"pi2\" ]"
104 do_curl GET /A1-P/v1/policies 200
105
106 echo "=== Set force delay 10. ==="
107 RESULT="Force delay: 10 sec set for all A1 responses"
108 do_curl POST '/forcedelay?delay=10' 200
109
110 echo "=== API: Get policy instances, shall contain pi1 and pi2 and delayed 10 sec=="
111 RESULT="json:[ \"pi1\", \"pi2\" ]"
112 do_curl GET /A1-P/v1/policies 200
113
114 echo "=== Reset force delay. ==="
115 RESULT="Force delay: None sec set for all A1 responses"
116 do_curl POST /forcedelay 200
117
118 echo "=== API: GET policy instance pi1 ==="
119 RESULT="json:{\"scope\": {\"ueId\": \"ue1\", \"groupId\": \"group1\", \"sliceId\": \"slice1\", \"qosId\": \"qos1\", \"cellId\": \"cell1\"}, \"statement\": {\"priorityLevel\": 6}}"
120 do_curl GET /A1-P/v1/policies/pi1 200
121
122 echo "=== API: GET policy instance pi2 ==="
123 RESULT="json:{\"scope\": {\"ueId\": \"ue2\", \"groupId\": \"group2\", \"sliceId\": \"slice2\", \"qosId\": \"qos2\", \"cellId\": \"cell2\"}, \"statement\": {\"priorityLevel\": 10}}"
124 do_curl GET /A1-P/v1/policies/pi2 200
125
126 echo "=== API: DELETE policy instance pi1 ==="
127 RESULT=""
128 do_curl DELETE /A1-P/v1/policies/pi1 204
129
130 echo "=== API: Get policy status for pi1, shall fail==="
131 RESULT="json:{\"title\": \"The policy identity does not exist.\", \"status\": 404, \"detail\": \"There is no existing policy instance with the identity: pi1\", \"instance\": \"pi1\"}"
132 do_curl GET /A1-P/v1/policies/pi1/status 404
133
134 echo "=== Set status for policy instance pi2 ==="
135 RESULT="Status set to OK for policy: pi2"
136 do_curl PUT '/status?policyid=pi2&status=OK' 200
137
138 echo "=== API: Get policy status for pi2==="
139 RESULT="json:{\"enforceStatus\": \"OK\"}"
140 do_curl GET /A1-P/v1/policies/pi2/status 200
141
142 echo "=== Set status for policy instance pi2 ==="
143 RESULT="Status set to NOTOK and notok_reason for policy: pi2"
144 do_curl PUT '/status?policyid=pi2&status=NOTOK&reason=notok_reason' 200
145
146 echo "=== API: Get policy status for pi2 ==="
147 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
148 do_curl GET /A1-P/v1/policies/pi2/status 200
149
150 echo "=== Send status for pi2==="
151 RESULT="json:{\"enforceStatus\": \"NOTOK\", \"enforceReason\": \"notok_reason\"}"
152 do_curl POST '/sendstatus?policyid=pi2' 200
153
154 echo "=== Get counter: intstance ==="
155 RESULT="1"
156 do_curl GET /counter/num_instances 200
157
158 echo "=== Get counter: types (shall be 0)==="
159 RESULT="0"
160 do_curl GET /counter/num_types 200
161
162 echo "=== Get counter: interface ==="
163 RESULT="STD_1.1.3"
164 do_curl GET /counter/interface 200
165
166 echo "=== Get counter: remote hosts ==="
167 RESULT="*"
168 do_curl GET '/counter/remote_hosts' 200
169
170 echo "********************"
171 echo "*** All tests ok ***"
172 echo "********************"