blob: e9ca1d25000b111ac24ba75f720d308ba5763b1b [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
34 PORT=3905
35 # Set http protocol
36 HTTPX="http"
37else
38 #Default https port for the mr-stub
39 PORT=3906
40 # 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
47echo "=== Stub hello world ==="
48RESULT="OK"
49do_curl GET / 200
50
51echo "=== Stub reset ==="
52RESULT="OK"
53do_curl GET /reset 200
54
55## Test with json response
56
57echo "=== Send a request ==="
58RESULT="*"
59#create payload
60echo "{\"data\": \"data-value\"}" > .tmp.json
61
62do_curl POST '/send-request?operation=PUT&url=/test' 200 .tmp.json
63#Save id for later
64CORRID=$body
65
66echo "=== Fetch a response, shall be empty ==="
67RESULT=""
68do_curl GET '/receive-response?correlationid='$CORRID 204
69
70echo "=== Fetch a request ==="
71RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"PUT\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{\"data\": \"data-value\"},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test\"}]"
72do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
73
74echo "=== Send a json response ==="
75# Create minimal accepted response message
76echo "[{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}]" > .tmp.json
ecaiyanlinux67355802020-05-11 12:53:23 +020077RESULT="{}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +010078do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
79
80echo "=== Fetch a response ==="
81RESULT="{\"test\": \"testresponse\"}200"
82do_curl GET '/receive-response?correlationid='$CORRID 200
83
84### Test with plain text response
85
86echo "=== Send a request ==="
87RESULT="*"
88do_curl POST '/send-request?operation=GET&url=/test2' 200
89#Save id for later
90CORRID=$body
91
92echo "=== Fetch a response, shall be empty ==="
93RESULT=""
94do_curl GET '/receive-response?correlationid='$CORRID 204
95
96echo "=== Fetch a request ==="
97RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"GET\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test2\"}]"
98do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
99
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200100echo "=== Fetch a request, empty. Shall delay 10 seconds ==="
101T1=$SECONDS
102RESULT="json:[]"
103do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200
104T2=$SECONDS
105if [ $(($T2-$T1)) -lt 10 ] || [ $(($T2-$T1)) -gt 15 ]; then
106 echo "Delay to short or too long"$(($T2-$T1))". Should be default 10 sec"
107 exit 1
108else
109 echo " Delay ok:"$(($T2-$T1))
110fi
111
112echo "=== Fetch a request, empty. Shall delay 5 seconds ==="
113T1=$SECONDS
114RESULT="json:[]"
115do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=5000' 200
116T2=$SECONDS
117if [ $(($T2-$T1)) -lt 5 ] || [ $(($T2-$T1)) -gt 7 ]; then
ecaiyanlinux67355802020-05-11 12:53:23 +0200118 echo "Delay too short or too long"$(($T2-$T1))". Should be 10 sec"
BjornMagnussonXA72667f12020-04-24 09:20:18 +0200119 exit 1
120else
121 echo " Delay ok:"$(($T2-$T1))
122fi
123
124echo "=== Fetch a request with limit 25, shall be empty. ==="
125RESULT="json-array-size:0"
126do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=25' 200
127
128echo "=== Send 5 request to test limit on MR GET==="
129RESULT="*"
130for i in {1..5}
131do
132 do_curl POST '/send-request?operation=GET&url=/test2' 200
133done
134
135echo "=== Fetch a request with limit 3. ==="
136RESULT="json-array-size:3"
137do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
138
139echo "=== Fetch a request with limit 3, shall return 2. ==="
140RESULT="json-array-size:2"
141do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
142
143echo "=== Fetch a request with limit 3, shall return 0. ==="
144RESULT="json-array-size:0"
145do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200
146
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100147echo "=== Send a json response ==="
148# Create minimal accepted response message
149echo "[{\"correlationId\": \""$CORRID"\", \"message\": \"test2-response\", \"status\": \"200\"}]" > .tmp.json
ecaiyanlinux67355802020-05-11 12:53:23 +0200150RESULT="{}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100151do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json
152
153echo "=== Fetch a response ==="
154RESULT="test2-response200"
155do_curl GET '/receive-response?correlationid='$CORRID 200
156
157echo "********************"
158echo "*** All tests ok ***"
ecaiyanlinux67355802020-05-11 12:53:23 +0200159echo "********************"