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 # Automated test script for mrstub container
22 # Run the build_and_start with the same arg as this script
24 echo "Usage: ./basic_test nonsecure|secure"
27 if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
28 echo "Usage: ./basic_test nonsecure|secure"
32 if [ $1 == "nonsecure" ]; then
33 #Default http port for the simulator
38 #Default https port for the mr-stub
44 # source function to do curl and check result
45 . ../common/do_curl_function.sh
47 echo "=== Stub hello world ==="
51 echo "=== Stub reset ==="
53 do_curl GET /reset 200
55 ## Test with json response
57 echo "=== Send a request ==="
60 echo "{\"data\": \"data-value\"}" > .tmp.json
62 do_curl POST '/send-request?operation=PUT&url=/test' 200 .tmp.json
66 echo "=== Fetch a response, shall be empty ==="
68 do_curl GET '/receive-response?correlationid='$CORRID 204
70 echo "=== Fetch a request ==="
71 RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"PUT\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{\"data\": \"data-value\"},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test\"}]"
72 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
74 echo "=== Send a json response ==="
75 # Create minimal accepted response message, array
76 echo "[{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}]" > .tmp.json
78 do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
80 echo "=== Fetch a response ==="
81 RESULT="{\"test\": \"testresponse\"}200"
82 do_curl GET '/receive-response?correlationid='$CORRID 200
84 echo "=== Send a json response ==="
85 # Create minimal accepted response message, single message - no array
86 echo "{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse2\"}, \"status\": \"200\"}" > .tmp.json
88 do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
90 echo "=== Fetch a response ==="
91 RESULT="{\"test\": \"testresponse2\"}200"
92 do_curl GET '/receive-response?correlationid='$CORRID 200
94 ### Test with plain text response
96 echo "=== Send a request ==="
98 do_curl POST '/send-request?operation=GET&url=/test2' 200
102 echo "=== Fetch a response, shall be empty ==="
104 do_curl GET '/receive-response?correlationid='$CORRID 204
106 echo "=== Fetch a request ==="
107 RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"GET\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test2\"}]"
108 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
110 echo "=== Fetch a request, empty. Shall delay 10 seconds ==="
113 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
115 if [ $(($T2-$T1)) -lt 10 ] || [ $(($T2-$T1)) -gt 15 ]; then
116 echo "Delay to short or too long"$(($T2-$T1))". Should be default 10 sec"
119 echo " Delay ok:"$(($T2-$T1))
122 echo "=== Fetch a request, empty. Shall delay 5 seconds ==="
125 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=5000' 200
127 if [ $(($T2-$T1)) -lt 5 ] || [ $(($T2-$T1)) -gt 7 ]; then
128 echo "Delay too short or too long"$(($T2-$T1))". Should be 10 sec"
131 echo " Delay ok:"$(($T2-$T1))
134 echo "=== Fetch a request with limit 25, shall be empty. ==="
135 RESULT="json-array-size:0"
136 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=25' 200
138 echo "=== Send 5 request to test limit on MR GET==="
142 do_curl POST '/send-request?operation=GET&url=/test2' 200
145 echo "=== Fetch a request with limit 3. ==="
146 RESULT="json-array-size:3"
147 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
149 echo "=== Fetch a request with limit 3, shall return 2. ==="
150 RESULT="json-array-size:2"
151 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
153 echo "=== Fetch a request with limit 3, shall return 0. ==="
154 RESULT="json-array-size:0"
155 do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
157 echo "=== Send a json response ==="
158 # Create minimal accepted response message
159 echo "[{\"correlationId\": \""$CORRID"\", \"message\": \"test2-response\", \"status\": \"200\"}]" > .tmp.json
161 do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
163 echo "=== Fetch a response ==="
164 RESULT="test2-response200"
165 do_curl GET '/receive-response?correlationid='$CORRID 200
167 echo "********************"
168 echo "*** All tests ok ***"
169 echo "********************"