blob: 6e854ead36b533ae1d65eb8734d5d8ca8810cc11 [file] [log] [blame]
BjornMagnussonXA80a92002020-03-19 14:31:06 +01001#!/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# Automated test script for mrstub container
21
BjornMagnussonXA72667f12020-04-24 09:20:18 +020022# Run the build_and_start with the same arg as this script
23if [ $# -ne 1 ]; then
24 echo "Usage: ./basic_test nonsecure|secure"
25 exit 1
26fi
27if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
28 echo "Usage: ./basic_test nonsecure|secure"
29 exit 1
30fi
31
32if [ $1 == "nonsecure" ]; then
33 #Default http port for the simulator
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010034 PORT=3904
BjornMagnussonXA72667f12020-04-24 09:20:18 +020035 # Set http protocol
36 HTTPX="http"
37else
38 #Default https port for the mr-stub
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010039 PORT=3905
BjornMagnussonXA72667f12020-04-24 09:20:18 +020040 # Set https protocol
41 HTTPX="https"
42fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +010043
44# source function to do curl and check result
45. ../common/do_curl_function.sh
46
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +010047RESP_CONTENT='*' #Dont check resp content type
48
BjornMagnussonXA80a92002020-03-19 14:31:06 +010049echo "=== Stub hello world ==="
50RESULT="OK"
51do_curl GET / 200
52
53echo "=== Stub reset ==="
54RESULT="OK"
55do_curl GET /reset 200
56
57## Test with json response
58
59echo "=== Send a request ==="
60RESULT="*"
61#create payload
62echo "{\"data\": \"data-value\"}" > .tmp.json
63
64do_curl POST '/send-request?operation=PUT&url=/test' 200 .tmp.json
65#Save id for later
66CORRID=$body
67
68echo "=== Fetch a response, shall be empty ==="
69RESULT=""
70do_curl GET '/receive-response?correlationid='$CORRID 204
71
72echo "=== Fetch a request ==="
73RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"PUT\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{\"data\": \"data-value\"},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test\"}]"
74do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
75
76echo "=== Send a json response ==="
BjornMagnussonXA0f9d5172020-06-17 15:43:39 +020077# Create minimal accepted response message, array
BjornMagnussonXA80a92002020-03-19 14:31:06 +010078echo "[{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}]" > .tmp.json
ecaiyanlinux67355802020-05-11 12:53:23 +020079RESULT="{}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +010080do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
81
82echo "=== Fetch a response ==="
83RESULT="{\"test\": \"testresponse\"}200"
84do_curl GET '/receive-response?correlationid='$CORRID 200
85
BjornMagnussonXA0f9d5172020-06-17 15:43:39 +020086echo "=== Send a json response ==="
87# Create minimal accepted response message, single message - no array
88echo "{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse2\"}, \"status\": \"200\"}" > .tmp.json
89RESULT="{}"
90do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
91
92echo "=== Fetch a response ==="
93RESULT="{\"test\": \"testresponse2\"}200"
94do_curl GET '/receive-response?correlationid='$CORRID 200
95
BjornMagnussonXA80a92002020-03-19 14:31:06 +010096### Test with plain text response
97
98echo "=== Send a request ==="
99RESULT="*"
100do_curl POST '/send-request?operation=GET&url=/test2' 200
101#Save id for later
102CORRID=$body
103
104echo "=== Fetch a response, shall be empty ==="
105RESULT=""
106do_curl GET '/receive-response?correlationid='$CORRID 204
107
108echo "=== Fetch a request ==="
109RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"GET\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test2\"}]"
110do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
111
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200112echo "=== Fetch a request, empty. Shall delay 10 seconds ==="
113T1=$SECONDS
114RESULT="json:[]"
115do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
116T2=$SECONDS
117if [ $(($T2-$T1)) -lt 10 ] || [ $(($T2-$T1)) -gt 15 ]; then
118 echo "Delay to short or too long"$(($T2-$T1))". Should be default 10 sec"
119 exit 1
120else
121 echo " Delay ok:"$(($T2-$T1))
122fi
123
124echo "=== Fetch a request, empty. Shall delay 5 seconds ==="
125T1=$SECONDS
126RESULT="json:[]"
127do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=5000' 200
128T2=$SECONDS
129if [ $(($T2-$T1)) -lt 5 ] || [ $(($T2-$T1)) -gt 7 ]; then
ecaiyanlinux67355802020-05-11 12:53:23 +0200130 echo "Delay too short or too long"$(($T2-$T1))". Should be 10 sec"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200131 exit 1
132else
133 echo " Delay ok:"$(($T2-$T1))
134fi
135
136echo "=== Fetch a request with limit 25, shall be empty. ==="
137RESULT="json-array-size:0"
138do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=25' 200
139
140echo "=== Send 5 request to test limit on MR GET==="
141RESULT="*"
142for i in {1..5}
143do
144 do_curl POST '/send-request?operation=GET&url=/test2' 200
145done
146
147echo "=== Fetch a request with limit 3. ==="
148RESULT="json-array-size:3"
149do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
150
151echo "=== Fetch a request with limit 3, shall return 2. ==="
152RESULT="json-array-size:2"
153do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
154
155echo "=== Fetch a request with limit 3, shall return 0. ==="
156RESULT="json-array-size:0"
157do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
158
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100159echo "=== Send a json response ==="
160# Create minimal accepted response message
161echo "[{\"correlationId\": \""$CORRID"\", \"message\": \"test2-response\", \"status\": \"200\"}]" > .tmp.json
ecaiyanlinux67355802020-05-11 12:53:23 +0200162RESULT="{}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100163do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
164
165echo "=== Fetch a response ==="
166RESULT="test2-response200"
167do_curl GET '/receive-response?correlationid='$CORRID 200
168
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100169
170echo "=== Send a json response ==="
171# Create minimal accepted response message, array
172echo "{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}" > .tmp.json
173RESULT="{}"
174do_curl POST /events/generic-path 200 .tmp.json
175
176echo "=== Fetch a request ==="
BjornMagnussonXAc8f92e92022-02-28 15:16:37 +0100177RESULT="json:[\"{\\\"correlationId\\\": \\\""$CORRID"\\\", \\\"message\\\": {\\\"test\\\": \\\"testresponse\\\"}, \\\"status\\\": \\\"200\\\"}\"]"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100178do_curl GET '/events/generic-path' 200
179
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100180echo "********************"
181echo "*** All tests ok ***"
ecaiyanlinux67355802020-05-11 12:53:23 +0200182echo "********************"