blob: 44e8526aa48aae7ae3e870b8c7c3905970ac9cdf [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 callback receiver container
21
22# callbackreciver port
ecaiyanlinux113bf092020-08-01 14:05:17 +000023# export PORT=8090
24if [ $# -ne 1 ]; then
25 echo "Usage: ./basic_test.sh nonsecure|secure"
26 exit 1
27fi
28if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then
29 echo "Usage: ./basic_test.sh nonsecure|secure"
30 exit 1
31fi
32
33if [ $1 == "nonsecure" ]; then
34 #Default http port for the simulator
35 PORT=8090
36 # Set http protocol
37 HTTPX="http"
38else
39 #Default https port for the simulator
40 PORT=8091
41 # Set https protocol
42 HTTPX="https"
43fi
BjornMagnussonXA80a92002020-03-19 14:31:06 +010044
45# source function to do curl and check result
46. ../common/do_curl_function.sh
47
48echo "=== CR hello world ==="
49RESULT="OK"
50do_curl GET / 200
51
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010052echo "=== Reset ==="
53RESULT="*"
54do_curl POST /reset 200
BjornMagnussonXA80a92002020-03-19 14:31:06 +010055
56echo "=== Get counter - callbacks ==="
57RESULT="0"
58do_curl GET /counter/received_callbacks 200
59
60echo "=== Get counter - fetched events ==="
61RESULT="0"
62do_curl GET /counter/fetched_callbacks 200
63
64echo "=== Get counter - current events ==="
65RESULT="0"
66do_curl GET /counter/current_messages 200
67
BjornMagnussonXA663566c2021-11-08 10:25:07 +010068echo "=== Get counter - remote hosts ==="
69RESULT="*"
70do_curl GET /counter/remote_hosts 200
71
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010072echo "=== Send a request non json ==="
73RESULT="*"
74#create payload
75echo "DATA" > .tmp.json
76do_curl POST '/callbacks/test' 200 .tmp.json
BjornMagnussonXA80a92002020-03-19 14:31:06 +010077
78echo "=== Send a request ==="
79RESULT="*"
80#create payload
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010081echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
BjornMagnussonXA80a92002020-03-19 14:31:06 +010082do_curl POST '/callbacks/test' 200 .tmp.json
83
84
85echo "=== Fetch an event, wrong id==="
86RESULT="*"
87do_curl GET '/get-event/wrongid' 204
88
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010089# Test counters for all ids
BjornMagnussonXA80a92002020-03-19 14:31:06 +010090echo "=== Get counter - callbacks ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010091RESULT="2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +010092do_curl GET /counter/received_callbacks 200
93
94echo "=== Get counter - fetched events ==="
95RESULT="0"
96do_curl GET /counter/fetched_callbacks 200
97
98echo "=== Get counter - current events ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +010099RESULT="2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100100do_curl GET /counter/current_messages 200
101
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100102# Test counter for one id
103echo "=== Get counter - callbacks ==="
104RESULT="2"
105do_curl GET /counter/received_callbacks?id=test 200
106
107echo "=== Get counter - fetched events ==="
108RESULT="0"
109do_curl GET /counter/fetched_callbacks?id=test 200
110
111echo "=== Get counter - current events ==="
112RESULT="2"
113do_curl GET /counter/current_messages?id=test 200
114
115# Test counter for dummy id
116echo "=== Get counter - callbacks ==="
117RESULT="0"
118do_curl GET /counter/received_callbacks?id=dummy 200
119
120echo "=== Get counter - fetched events ==="
121RESULT="0"
122do_curl GET /counter/fetched_callbacks?id=dummy 200
123
124echo "=== Get counter - current events ==="
125RESULT="0"
126do_curl GET /counter/current_messages?id=dummy 200
127
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100128
129echo "=== Fetch an event ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100130RESULT="json:{}"
131do_curl GET '/get-event/test' 200
132
133echo "=== Fetch an event ==="
134RESULT="json:{\"DATA-MSG\":\"msg\"}"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100135do_curl GET '/get-event/test' 200
136
137echo "=== Fetch an event again ==="
138RESULT="*"
139do_curl GET '/get-event/test' 204
140
141echo "=== Get counter - callbacks ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100142RESULT="2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100143do_curl GET /counter/received_callbacks 200
144
145echo "=== Get counter - fetched events ==="
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100146RESULT="2"
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100147do_curl GET /counter/fetched_callbacks 200
148
149echo "=== Get counter - current events ==="
150RESULT="0"
151do_curl GET /counter/current_messages 200
152
BjornMagnussonXA49f0e5a2020-11-08 22:41:39 +0100153# Test counter for one id
154echo "=== Get counter - callbacks ==="
155RESULT="2"
156do_curl GET /counter/received_callbacks?id=test 200
157
158echo "=== Get counter - fetched events ==="
159RESULT="2"
160do_curl GET /counter/fetched_callbacks?id=test 200
161
162echo "=== Get counter - current events ==="
163RESULT="0"
164do_curl GET /counter/current_messages?id=test 200
165
166echo "=== Send a request ==="
167RESULT="*"
168#create payload
169echo "{\"DATA-MSG\":\"msg\"}" > .tmp.json
170do_curl POST '/callbacks/test' 200 .tmp.json
171
172echo "=== Send a request ==="
173RESULT="*"
174#create payload
175echo "{\"DATA-MSG2\":\"msg2\"}" > .tmp.json
176do_curl POST '/callbacks/test' 200 .tmp.json
177
178echo "=== Send a request ==="
179RESULT="*"
180#create payload
181echo "{\"DATA-MSG3\":\"msg3\"}" > .tmp.json
182do_curl POST '/callbacks/test1' 200 .tmp.json
183
184echo "=== Get counter - callbacks ==="
185RESULT="5"
186do_curl GET /counter/received_callbacks 200
187
188echo "=== Get counter - fetched events ==="
189RESULT="2"
190do_curl GET /counter/fetched_callbacks 200
191
192echo "=== Get counter - current events ==="
193RESULT="3"
194do_curl GET /counter/current_messages 200
195
196# Test counter for one id, test1
197echo "=== Get counter - callbacks ==="
198RESULT="1"
199do_curl GET /counter/received_callbacks?id=test1 200
200
201echo "=== Get counter - fetched events ==="
202RESULT="0"
203do_curl GET /counter/fetched_callbacks?id=test1 200
204
205echo "=== Get counter - current events ==="
206RESULT="1"
207do_curl GET /counter/current_messages?id=test1 200
208
209echo "=== Fetch all events ==="
210RESULT="json:[{\"DATA-MSG2\":\"msg2\"},{\"DATA-MSG\":\"msg\"}]"
211do_curl GET '/get-all-events/test' 200
212
213echo "=== Get counter - callbacks ==="
214RESULT="5"
215do_curl GET /counter/received_callbacks 200
216
217echo "=== Get counter - fetched events ==="
218RESULT="4"
219do_curl GET /counter/fetched_callbacks 200
220
221echo "=== Get counter - current events ==="
222RESULT="1"
223do_curl GET /counter/current_messages 200
224
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100225echo "=== CR reset ==="
226RESULT="OK"
227do_curl GET /reset 200
228
229echo "=== Get counter - callbacks ==="
230RESULT="0"
231do_curl GET /counter/received_callbacks 200
232
233echo "=== Get counter - fetched events ==="
234RESULT="0"
235do_curl GET /counter/fetched_callbacks 200
236
237echo "=== Get counter - current events ==="
238RESULT="0"
239do_curl GET /counter/current_messages 200
240
241
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100242# Check delay
243
244echo "=== Set delay 10 sec==="
245RESULT="*"
246do_curl POST /forcedelay?delay=10 200
247
248TSECONDS=$SECONDS
249echo "=== Send a request, dealyed ==="
250RESULT="*"
251#create payload
252echo "{\"DATA-MSG\":\"msg-del1\"}" > .tmp.json
253do_curl POST '/callbacks/test' 200 .tmp.json
254
255if [ $(($SECONDS-$TSECONDS)) -lt 10 ]; then
256 echo " Delay failed $(($SECONDS-$TSECONDS))"
257 echo " Exiting...."
258 exit 1
259else
260 echo " Delay OK $(($SECONDS-$TSECONDS))"
261fi
262
263
264echo "=== Fetch an event ==="
265RESULT="json:{\"DATA-MSG\":\"msg-del1\"}"
266do_curl GET '/get-event/test' 200
267
BjornMagnussonXA80a92002020-03-19 14:31:06 +0100268echo "********************"
269echo "*** All tests ok ***"
270echo "********************"