Skip to content

Commit 538a498

Browse files
committed
Quote variables
1 parent 00d9ed7 commit 538a498

1 file changed

Lines changed: 47 additions & 59 deletions

File tree

‎tests.sh‎

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -85,44 +85,41 @@ wait_for_ready
8585

8686
message " Make http(s) request, and test the path, method, header and status code. "
8787
REQUEST=$(curl -s -k -X PUT -H "Arbitrary:Header" -d aaa=bbb 'https://localhost:8443/hello-world?ccc=ddd&myquery=98765')
88-
if [ $(echo $REQUEST | jq -r '.path') == '/hello-world' ] && \
89-
[ $(echo $REQUEST | jq -r '.method') == 'PUT' ] && \
90-
[ $(echo $REQUEST | jq -r '.query.myquery') == '98765' ] && \
91-
[ $(echo $REQUEST | jq -r '.headers.arbitrary') == 'Header' ]
92-
then
88+
if [ "$(echo "$REQUEST" | jq -r '.path')" == '/hello-world' ] && \
89+
[ "$(echo "$REQUEST" | jq -r '.method')" == 'PUT' ] && \
90+
[ "$(echo "$REQUEST" | jq -r '.query.myquery')" == '98765' ] && \
91+
[ "$(echo "$REQUEST" | jq -r '.headers.arbitrary')" == 'Header' ]; then
9392
passed "HTTPS request passed."
9493
else
9594
failed "HTTPS request failed."
96-
echo $REQUEST | jq
95+
echo "$REQUEST" | jq
9796
exit 1
9897
fi
9998
REQUEST_WITH_STATUS_CODE=$(curl -s -k -o /dev/null -w "%{http_code}" -H "x-set-response-status-code: 404" https://localhost:8443/hello-world)
10099
REQUEST_WITH_STATUS_CODE_V=$(curl -v -k -o /dev/null -w "%{http_code}" -H "x-set-response-status-code: 404" https://localhost:8443/hello-world)
101-
if [ $(echo $REQUEST_WITH_STATUS_CODE == '404') ]
102-
then
100+
if [ "$REQUEST_WITH_STATUS_CODE" = "404" ]; then
103101
passed "HTTPS status code header passed."
104102
else
105103
failed "HTTPS status code header failed."
106-
echo $REQUEST_WITH_STATUS_CODE_V
104+
echo "$REQUEST_WITH_STATUS_CODE_V"
107105
exit 1
108106
fi
109107

110108
REQUEST_WITH_STATUS_CODE=$(curl -s -k -o /dev/null -w "%{http_code}" https://localhost:8443/status/test?x-set-response-status-code=419)
111109
REQUEST_WITH_STATUS_CODE_V=$(curl -v -k -o /dev/null -w "%{http_code}" https://localhost:8443/hello-world?x-set-response-status-code=419)
112-
if [ $(echo $REQUEST_WITH_STATUS_CODE == '419') ]
113-
then
110+
if [ "$REQUEST_WITH_STATUS_CODE" = "419" ]; then
114111
passed "HTTPS status code querystring passed."
115112
else
116113
failed "HTTPS status code querystring failed."
117-
echo $REQUEST_WITH_STATUS_CODE_V
114+
echo "$REQUEST_WITH_STATUS_CODE_V"
118115
exit 1
119116
fi
120117

121118
REQUEST_WITH_CONTENT_TYPE_HEADER=$(curl -o /dev/null -k -Ss -w "%{content_type}" -H "x-set-response-content-type: aaaa/bbbb" https://localhost:8443/)
122119
if [[ "$REQUEST_WITH_CONTENT_TYPE_HEADER" == *"aaaa/bbbb"* ]]; then
123120
passed "Request with custom response type header, passed"
124121
else
125-
echo $REQUEST_WITH_CONTENT_TYPE_HEADER
122+
echo "$REQUEST_WITH_CONTENT_TYPE_HEADER"
126123
failed "Request with custom response type header, failed."
127124
exit 1
128125
fi
@@ -131,7 +128,7 @@ REQUEST_WITH_CONTENT_TYPE_PARAMETER=$(curl -o /dev/null -k -Ss -w "%{content_typ
131128
if [[ "$REQUEST_WITH_CONTENT_TYPE_PARAMETER" == *"jellyfish/cabbage"* ]]; then
132129
passed "Request with custom response type parameter, passed"
133130
else
134-
echo $REQUEST_WITH_CONTENT_TYPE_PARAMETER
131+
echo "$REQUEST_WITH_CONTENT_TYPE_PARAMETER"
135132
failed "Request with custom response type parameter, failed."
136133
exit 1
137134
fi
@@ -142,7 +139,7 @@ if [[ $(echo "$REQUEST_WITH_SLEEP_MS>5" | bc -l) == 1 ]]; then
142139
passed "Request header with response delay passed"
143140
else
144141
failed "Request header with response delay failed"
145-
echo $REQUEST_WITH_SLEEP_MS
142+
echo "$REQUEST_WITH_SLEEP_MS"
146143
exit 1
147144
fi
148145

@@ -151,7 +148,7 @@ if [[ $(echo "$REQUEST_WITH_SLEEP_MS>4" | bc -l) == 1 ]]; then
151148
passed "Request query with response delay passed"
152149
else
153150
failed "Request query with response delay failed"
154-
echo $REQUEST_WITH_SLEEP_MS
151+
echo "$REQUEST_WITH_SLEEP_MS"
155152
exit 1
156153
fi
157154

@@ -160,51 +157,48 @@ if [[ $(echo "$REQUEST_WITH_INVALID_SLEEP_MS<2" | bc -l) == 1 ]]; then
160157
passed "Request with invalid response delay passed"
161158
else
162159
failed "Request with invalid response delay failed"
163-
echo $REQUEST_WITH_INVALID_SLEEP_MS
160+
echo "$REQUEST_WITH_INVALID_SLEEP_MS"
164161
exit 1
165162
fi
166163

167164
REQUEST=$(curl -s -X PUT -H "Arbitrary:Header" -d aaa=bbb http://localhost:8080/hello-world)
168-
if [ $(echo $REQUEST | jq -r '.path') == '/hello-world' ] && \
169-
[ $(echo $REQUEST | jq -r '.method') == 'PUT' ] && \
170-
[ $(echo $REQUEST | jq -r '.headers.arbitrary') == 'Header' ]
171-
then
165+
if [ "$(echo "$REQUEST" | jq -r '.path')" == '/hello-world' ] && \
166+
[ "$(echo "$REQUEST" | jq -r '.method')" == 'PUT' ] && \
167+
[ "$(echo "$REQUEST" | jq -r '.headers.arbitrary')" == 'Header' ]; then
172168
passed "HTTP request with arbitrary header passed."
173169
else
174170
failed "HTTP request with arbitrary header failed."
175-
echo $REQUEST | jq
171+
echo "$REQUEST" | jq
176172
exit 1
177173
fi
178174

179175
message " Make JSON request, and test that json is in the output. "
180176
REQUEST=$(curl -s -X POST -H "Content-Type: application/json" -d '{"a":"b"}' http://localhost:8080/)
181-
if [ $(echo $REQUEST | jq -r '.json.a') == 'b' ]
182-
then
177+
if [ "$(echo "$REQUEST" | jq -r '.json.a')" == 'b' ]; then
183178
passed "JSON test passed."
184179
else
185180
failed "JSON test failed."
186-
echo $REQUEST | jq
181+
echo "$REQUEST" | jq
187182
exit 1
188183
fi
189184

190185

191186
message " Make JSON request with gzip Content-Encoding, and test that json is in the output. "
192187
REQUEST=$(echo -n '{"a":"b"}' | gzip | curl -s -X POST -H "Content-Encoding: gzip" -H "Content-Type: application/json" --data-binary @- http://localhost:8080/)
193-
if [ $(echo $REQUEST | jq -r '.json.a') == 'b' ]
194-
then
188+
if [ "$(echo "$REQUEST" | jq -r '.json.a')" == 'b' ]; then
195189
passed "JSON test passed."
196190
else
197191
failed "JSON test failed."
198-
echo $REQUEST | jq
192+
echo "$REQUEST" | jq
199193
exit 1
200194
fi
201195

202196
REQUEST=$(curl -s -X POST -H "Content-Type: application/json" -d 'not-json' http://localhost:8080)
203-
if [ $(echo $REQUEST | jq -r '.json') == 'null' ]; then
197+
if [ "$(echo "$REQUEST" | jq -r '.json')" == 'null' ]; then
204198
passed "JSON with Invalid Body test passed."
205199
else
206200
failed "JSON with Invalid Body test failed."
207-
echo $REQUEST | jq
201+
echo "$REQUEST" | jq
208202
exit 1
209203
fi
210204

@@ -220,23 +214,23 @@ message " Make request with a header within limit."
220214
LARGE_HEADER_VALUE=$(head -c 600 </dev/urandom | base64 | tr -d '\n')
221215
REQUEST=$(curl -s -k -H "Large-Header: $LARGE_HEADER_VALUE" https://localhost:8443/)
222216

223-
if [ $(echo $REQUEST | jq -r '.headers."large-header"') == "$LARGE_HEADER_VALUE" ]; then
217+
if [ "$(echo "$REQUEST" | jq -r '.headers."large-header"')" == "$LARGE_HEADER_VALUE" ]; then
224218
passed "Large header test passed."
225219
else
226220
failed "Large header test failed."
227-
echo $REQUEST | jq
221+
echo "$REQUEST" | jq
228222
exit 1
229223
fi
230224

231225
message " Make request with a header exceeding limit."
232226
LARGE_HEADER_VALUE=$(head -c 5000 </dev/urandom | base64 | tr -d '\n')
233227
# Do with curl -v and look for "HTTP/1.1 431 Request Header Fields Too Large" output
234228
REQUEST=$(curl -v -k -H "Large-Header: $LARGE_HEADER_VALUE" https://localhost:8443/ 2>&1)
235-
if echo $REQUEST | grep -q "HTTP/1.1 431 Request Header Fields Too Large"; then
229+
if echo "$REQUEST" | grep -q "HTTP/1.1 431 Request Header Fields Too Large"; then
236230
passed "Large header test resulted in HTTP 431."
237231
else
238232
failed "Large header test failed."
239-
echo $REQUEST
233+
echo "$REQUEST"
240234
exit 1
241235
fi
242236

@@ -250,26 +244,24 @@ wait_for_ready
250244

251245
message " Make http(s) request, and test the path, method and header. "
252246
REQUEST=$(curl -s -k -X PUT -H "Arbitrary:Header" -d aaa=bbb https://localhost:8443/hello-world)
253-
if [ $(echo $REQUEST | jq -r '.path') == '/hello-world' ] && \
254-
[ $(echo $REQUEST | jq -r '.method') == 'PUT' ] && \
255-
[ $(echo $REQUEST | jq -r '.headers.arbitrary') == 'Header' ]
256-
then
247+
if [ "$(echo "$REQUEST" | jq -r '.path')" == '/hello-world' ] && \
248+
[ "$(echo "$REQUEST" | jq -r '.method')" == 'PUT' ] && \
249+
[ "$(echo "$REQUEST" | jq -r '.headers.arbitrary')" == 'Header' ]; then
257250
passed "HTTPS request passed."
258251
else
259252
failed "HTTPS request failed."
260-
echo $REQUEST | jq
253+
echo "$REQUEST" | jq
261254
exit 1
262255
fi
263256

264257
REQUEST=$(curl -s -X PUT -H "Arbitrary:Header" -d aaa=bbb http://localhost:8080/hello-world)
265-
if [ $(echo $REQUEST | jq -r '.path') == '/hello-world' ] && \
266-
[ $(echo $REQUEST | jq -r '.method') == 'PUT' ] && \
267-
[ $(echo $REQUEST | jq -r '.headers.arbitrary') == 'Header' ]
268-
then
258+
if [ "$(echo "$REQUEST" | jq -r '.path')" == '/hello-world' ] && \
259+
[ "$(echo "$REQUEST" | jq -r '.method')" == 'PUT' ] && \
260+
[ "$(echo "$REQUEST" | jq -r '.headers.arbitrary')" == 'Header' ]; then
269261
passed "HTTP request passed."
270262
else
271263
failed "HTTP request failed."
272-
echo $REQUEST | jq
264+
echo "$REQUEST" | jq
273265
exit 1
274266
fi
275267

@@ -300,12 +292,11 @@ message " Start container with response body only "
300292
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
301293
wait_for_ready
302294
RESPONSE=$(curl -s -k -X POST -d 'cauliflower' http://localhost:8080/a/b/c?response_body_only=true)
303-
if [[ ${RESPONSE} == "cauliflower" ]]
304-
then
295+
if [[ "$RESPONSE" == "cauliflower" ]]; then
305296
passed "Response body only received."
306297
else
307298
failed "Expected response body only."
308-
echo $RESPONSE
299+
echo "$RESPONSE"
309300
exit 1
310301
fi
311302

@@ -319,14 +310,13 @@ docker run -d --rm -e JWT_HEADER=Authentication --name http-echo-tests -p 8080:8
319310
wait_for_ready
320311

321312
REQUEST=$(curl -s -k -H "Authentication: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" https://localhost:8443/ )
322-
if [ $(echo $REQUEST | jq -r '.jwt.header.typ') == 'JWT' ] && \
323-
[ $(echo $REQUEST | jq -r '.jwt.header.alg') == 'HS256' ] && \
324-
[ $(echo $REQUEST | jq -r '.jwt.payload.sub') == '1234567890' ]
325-
then
313+
if [ "$(echo "$REQUEST" | jq -r '.jwt.header.typ')" == 'JWT' ] && \
314+
[ "$(echo "$REQUEST" | jq -r '.jwt.header.alg')" == 'HS256' ] && \
315+
[ "$(echo "$REQUEST" | jq -r '.jwt.payload.sub')" == '1234567890' ]; then
326316
passed "JWT request passed."
327317
else
328318
failed "JWT request failed."
329-
echo $REQUEST | jq
319+
echo "$REQUEST" | jq
330320
exit 1
331321
fi
332322

@@ -723,12 +713,11 @@ console.log(sign('my-value','mysecretkey123'));")
723713

724714

725715
RESPONSE=$(curl -s http://localhost:8080/ -H "Cookie: mysigned=s:${SIGNED_COOKIE}")
726-
if [ $(echo $RESPONSE | jq -r '.signedCookies.mysigned') == 'my-value' ]
727-
then
716+
if [ "$(echo "$RESPONSE" | jq -r '.signedCookies.mysigned')" == 'my-value' ]; then
728717
passed "Signed cookie test passed."
729718
else
730719
failed "Signed cookie test failed."
731-
echo $RESPONSE | jq
720+
echo "$RESPONSE" | jq
732721
exit 1
733722
fi
734723

@@ -743,13 +732,12 @@ wait_for_ready
743732

744733

745734
RESPONSE=$(curl -s http://localhost:8080/ -H "Cookie: foo=bar; baz=qux")
746-
if [ $(echo $RESPONSE | jq -r '.cookies.foo') == 'bar' ] && \
747-
[ $(echo $RESPONSE | jq -r '.cookies.baz') == 'qux' ]
748-
then
735+
if [ "$(echo "$RESPONSE" | jq -r '.cookies.foo')" == 'bar' ] && \
736+
[ "$(echo "$RESPONSE" | jq -r '.cookies.baz')" == 'qux' ]; then
749737
passed "Cookies returned in response test passed."
750738
else
751739
failed "Cookies returned in response test failed."
752-
echo $RESPONSE | jq
740+
echo "$RESPONSE" | jq
753741
exit 1
754742
fi
755743

0 commit comments

Comments
 (0)