@@ -5,7 +5,7 @@ set -euo pipefail
55function message {
66 echo " "
77 echo " ---------------------------------------------------------------"
8- echo $1
8+ echo " $1 "
99 echo " ---------------------------------------------------------------"
1010}
1111
@@ -14,11 +14,11 @@ RED=$(echo -en '\033[01;31m')
1414GREEN=$( echo -en ' \033[01;32m' )
1515
1616function failed {
17- echo ${RED} ✗$1 ${RESTORE}
17+ echo " ${RED} ✗${1} ${RESTORE} "
1818}
1919
2020function passed {
21- echo ${GREEN} ✓$1 ${RESTORE}
21+ echo " ${GREEN} ✓${1} ${RESTORE} "
2222}
2323
2424wait_for_ready () {
@@ -52,16 +52,16 @@ cleanup() {
5252
5353trap cleanup EXIT
5454
55- if ! [ -x " $( command -v jq) " ] ; then
55+ if ! command -v jq > /dev/null 2>&1 ; then
5656 message " JQ not installed. Installing..."
5757 sudo apt -y install jq
5858fi
5959
6060message " Check if we're in Github Actions or local run "
61- if [ -n " ${GITHUB_ACTIONS:- } " ]; then
61+ if [[ -n " ${GITHUB_ACTIONS:- } " ] ]; then
6262 echo " Github Actions. Image should already be built."
6363 docker images
64- if [ -z " $( docker images -q mendhak/http-https-echo:testing 2> /dev/null) " ]; then
64+ if [[ -z " $( docker images -q mendhak/http-https-echo:testing 2> /dev/null) " ] ]; then
6565 echo " Docker image mendhak/http-https-echo:testing not found. Exiting."
6666 exit 1
6767 fi
@@ -85,10 +85,10 @@ wait_for_ready
8585
8686message " Make http(s) request, and test the path, method, header and status code. "
8787REQUEST=$( 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' ]; 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
9292 passed " HTTPS request passed."
9393else
9494 failed " HTTPS request failed."
9797fi
9898REQUEST_WITH_STATUS_CODE=$( curl -s -k -o /dev/null -w " %{http_code}" -H " x-set-response-status-code: 404" https://localhost:8443/hello-world)
9999REQUEST_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)
100- if [ " $REQUEST_WITH_STATUS_CODE " = " 404" ]; then
100+ if [[ " $REQUEST_WITH_STATUS_CODE " == " 404" ] ]; then
101101 passed " HTTPS status code header passed."
102102else
103103 failed " HTTPS status code header failed."
107107
108108REQUEST_WITH_STATUS_CODE=$( curl -s -k -o /dev/null -w " %{http_code}" https://localhost:8443/status/test? x-set-response-status-code=419)
109109REQUEST_WITH_STATUS_CODE_V=$( curl -v -k -o /dev/null -w " %{http_code}" https://localhost:8443/hello-world? x-set-response-status-code=419)
110- if [ " $REQUEST_WITH_STATUS_CODE " = " 419" ]; then
110+ if [[ " $REQUEST_WITH_STATUS_CODE " == " 419" ] ]; then
111111 passed " HTTPS status code querystring passed."
112112else
113113 failed " HTTPS status code querystring failed."
162162fi
163163
164164REQUEST=$( curl -s -X PUT -H " Arbitrary:Header" -d aaa=bbb http://localhost:8080/hello-world)
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
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
168168 passed " HTTP request with arbitrary header passed."
169169else
170170 failed " HTTP request with arbitrary header failed."
174174
175175message " Make JSON request, and test that json is in the output. "
176176REQUEST=$( curl -s -X POST -H " Content-Type: application/json" -d ' {"a":"b"}' http://localhost:8080/)
177- if [ " $( echo " $REQUEST " | jq -r ' .json.a' ) " == ' b' ]; then
177+ if [[ " $( echo " $REQUEST " | jq -r ' .json.a' ) " == ' b' ] ]; then
178178 passed " JSON test passed."
179179else
180180 failed " JSON test failed."
185185
186186message " Make JSON request with gzip Content-Encoding, and test that json is in the output. "
187187REQUEST=$( echo -n ' {"a":"b"}' | gzip | curl -s -X POST -H " Content-Encoding: gzip" -H " Content-Type: application/json" --data-binary @- http://localhost:8080/)
188- if [ " $( echo " $REQUEST " | jq -r ' .json.a' ) " == ' b' ]; then
188+ if [[ " $( echo " $REQUEST " | jq -r ' .json.a' ) " == ' b' ] ]; then
189189 passed " JSON test passed."
190190else
191191 failed " JSON test failed."
194194fi
195195
196196REQUEST=$( curl -s -X POST -H " Content-Type: application/json" -d ' not-json' http://localhost:8080)
197- if [ " $( echo " $REQUEST " | jq -r ' .json' ) " == ' null' ]; then
197+ if [[ " $( echo " $REQUEST " | jq -r ' .json' ) " == ' null' ] ]; then
198198 passed " JSON with Invalid Body test passed."
199199else
200200 failed " JSON with Invalid Body test failed."
@@ -214,7 +214,7 @@ message " Make request with a header within limit."
214214LARGE_HEADER_VALUE=$( head -c 600 < /dev/urandom | base64 | tr -d ' \n' )
215215REQUEST=$( curl -s -k -H " Large-Header: $LARGE_HEADER_VALUE " https://localhost:8443/)
216216
217- 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
218218 passed " Large header test passed."
219219else
220220 failed " Large header test failed."
@@ -244,9 +244,9 @@ wait_for_ready
244244
245245message " Make http(s) request, and test the path, method and header. "
246246REQUEST=$( curl -s -k -X PUT -H " Arbitrary:Header" -d aaa=bbb https://localhost:8443/hello-world)
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
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
250250 passed " HTTPS request passed."
251251else
252252 failed " HTTPS request failed."
255255fi
256256
257257REQUEST=$( curl -s -X PUT -H " Arbitrary:Header" -d aaa=bbb http://localhost:8080/hello-world)
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
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
261261 passed " HTTP request passed."
262262else
263263 failed " HTTP request failed."
@@ -275,12 +275,12 @@ docker run -d --rm -e ECHO_BACK_TO_CLIENT=false --name http-echo-tests -p 8080:8
275275wait_for_ready
276276
277277REQUEST=$( curl -s -k http://localhost:8080/a/b/c)
278- if [[ -z ${ REQUEST} ]]
278+ if [[ -z " $ REQUEST" ]]
279279then
280280 passed " Response is empty."
281281else
282282 failed " Expected empty response, but got a non-empty response."
283- echo $REQUEST
283+ echo " $REQUEST "
284284 exit 1
285285fi
286286
@@ -310,9 +310,9 @@ docker run -d --rm -e JWT_HEADER=Authentication --name http-echo-tests -p 8080:8
310310wait_for_ready
311311
312312REQUEST=$( curl -s -k -H " Authentication: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" https://localhost:8443/ )
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
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
316316 passed " JWT request passed."
317317else
318318 failed " JWT request failed."
@@ -332,8 +332,8 @@ wait_for_ready "/ping"
332332curl -s -k -X POST -d " banana" https://localhost:8443/ping > /dev/null
333333
334334# There should be 3 lines, the "listening on...", the /ping ready test, and the /ping POST test.
335- if [ $( docker logs http-echo-tests | wc -l) == 3 ] && \
336- ! [ $( docker logs http-echo-tests | grep banana ) ]
335+ if [[ " $( docker logs http-echo-tests | wc -l) " == 3 ] ] && \
336+ ! docker logs http-echo-tests | grep -q banana
337337then
338338 passed " LOG_IGNORE_PATH ignored the /ping path"
339339else
@@ -353,8 +353,8 @@ wait_for_ready "/health"
353353curl -s -k -X POST -d " banana" https://localhost:8443/metrics > /dev/null
354354
355355# There should be 3 lines, the "listening on...", the /health ready test, and the /metrics POST test.
356- if [ $( docker logs http-echo-tests | wc -l) == 3 ] && \
357- ! [ $( docker logs http-echo-tests | grep banana ) ]
356+ if [[ " $( docker logs http-echo-tests | wc -l) " == 3 ] ] && \
357+ ! docker logs http-echo-tests | grep -q banana
358358then
359359 passed " LOG_IGNORE_PATH ignored the /metrics path"
360360else
366366# Test a positive case where the path is not ignored
367367curl -s -k -X POST -d " strawberry" https://localhost:8443/veryvisible > /dev/null
368368
369- if [[ $( docker logs http-echo-tests | grep strawberry ) ]]
369+ if docker logs http-echo-tests | grep -q strawberry
370370then
371371 passed " LOG_IGNORE_PATH didn't ignore the /veryvisible path"
372372else
@@ -387,8 +387,8 @@ wait_for_ready "/hello"
387387curl -s -k -X POST -d " banana" https://localhost:8443/ > /dev/null
388388
389389# There should be 3 lines, the "listening on", the "/hello" ready test, and the POST banana test.
390- if [ $( docker logs http-echo-tests | wc -l) == 3 ] && \
391- ! [ $( docker logs http-echo-tests | grep banana ) ]
390+ if [[ " $( docker logs http-echo-tests | wc -l) " == 3 ] ] && \
391+ ! docker logs http-echo-tests | grep -q banana
392392then
393393 passed " LOG_IGNORE_PATH ignored all paths"
394394else
@@ -407,7 +407,7 @@ docker run -d --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8
407407wait_for_ready " /healthy"
408408
409409curl -s -k -X GET https://localhost:8443/strawberry > /dev/null
410- if [ $( docker logs http-echo-tests | grep -c " GET /strawberry HTTP/1.1" ) -eq 0 ]
410+ if [[ " $( docker logs http-echo-tests | grep -c " GET /strawberry HTTP/1.1" ) " -eq 0 ] ]
411411then
412412 passed " DISABLE_REQUEST_LOGS disabled Express HTTP logging"
413413else
@@ -449,8 +449,8 @@ wait_for_ready
449449curl -s -k -X POST -d " tiramisu" https://localhost:8443/ > /dev/null
450450
451451# There will be 4 lines, the Listening on, the / ready test and response, the POST test and response
452- if [ $( docker logs http-echo-tests | wc -l) == 5 ] && \
453- [ $( docker logs http-echo-tests | grep tiramisu ) ]
452+ if [[ " $( docker logs http-echo-tests | wc -l) " == 5 ] ] && \
453+ docker logs http-echo-tests | grep -q tiramisu
454454then
455455 passed " LOG_WITHOUT_NEWLINE logged output in single line"
456456else
@@ -469,7 +469,7 @@ docker run -d --name http-echo-tests --rm mendhak/http-https-echo:testing
469469
470470WHOAMI=$( docker exec http-echo-tests whoami)
471471
472- if [ " $WHOAMI " == " node" ]
472+ if [[ " $WHOAMI " == " node" ] ]
473473then
474474 passed " Running as non root user"
475475else
@@ -491,7 +491,7 @@ curl -s http://localhost:8080 > /dev/null
491491
492492WHOAMI=" $( docker exec http-echo-tests id -u) "
493493
494- if [ " $WHOAMI " == " $CONTAINER_USER " ]
494+ if [[ " $WHOAMI " == " $CONTAINER_USER " ] ]
495495then
496496 passed " Running as $CONTAINER_USER user"
497497else
@@ -513,7 +513,7 @@ wait_for_ready
513513
514514COMMON_NAME=" $( curl -sk --cert fullchain.pem --key testpk.pem https://localhost:8443/ | jq -r ' .clientCertificate.subject.CN' ) "
515515SAN=" $( curl -sk --cert fullchain.pem --key testpk.pem https://localhost:8443/ | jq -r ' .clientCertificate.subjectaltname' ) "
516- if [ " $COMMON_NAME " == " client.example.net" ] && [ " $SAN " == " DNS:client.example.net" ]
516+ if [[ " $COMMON_NAME " == " client.example.net" && " $SAN " == " DNS:client.example.net" ] ]
517517then
518518 passed " Client certificate details are present in the output"
519519else
523523
524524message " Check if certificate is not passed, then client certificate details are empty"
525525CLIENT_CERT=" $( curl -sk https://localhost:8443/ | jq -r ' .clientCertificate' ) "
526- if [ " $CLIENT_CERT " == " {}" ]
526+ if [[ " $CLIENT_CERT " == " {}" ] ]
527527then
528528 passed " Client certificate details are not present in the response"
529529else
533533
534534message " Check that HTTP server does not have any client certificate property"
535535CLIENT_CERT=$( curl -sk --cert cert.pem --key testpk.pem http://localhost:8080/ | jq ' has("clientCertificate")' )
536- if [ " $CLIENT_CERT " == " false" ]
536+ if [[ " $CLIENT_CERT " == " false" ] ]
537537then
538538 passed " Client certificate details are not present in regular HTTP server"
539539else
@@ -567,7 +567,7 @@ wait_for_ready
567567
568568REQUEST_WITH_STATUS_CODE=" $( curl -s --cacert " $( pwd) /server_fullchain.pem" -o /dev/null -w " %{http_code}" \
569569 --resolve " ${cert_common_name} :8443:127.0.0.1" " https://${cert_common_name} :8443/hello-world" ) "
570- if [ " ${REQUEST_WITH_STATUS_CODE} " = 200 ]
570+ if [[ " ${REQUEST_WITH_STATUS_CODE} " == 200 ] ]
571571then
572572 passed " Server certificate and private key are loaded from configured custom location"
573573else
@@ -585,7 +585,7 @@ wait_for_ready
585585
586586RESPONSE_BODY=" $( curl -sk https://localhost:8443/ | jq -r ' .env.ECHO_INCLUDE_ENV_VARS' ) "
587587
588- if [ " $RESPONSE_BODY " == " 1" ]
588+ if [[ " $RESPONSE_BODY " == " 1" ] ]
589589then
590590 passed " Environment variables present in the output"
591591else
@@ -603,7 +603,7 @@ wait_for_ready
603603
604604RESPONSE_BODY_ENV_CHECK=" $( curl -sk https://localhost:8443/ | jq ' has("env")' ) "
605605
606- if [ " $RESPONSE_BODY_ENV_CHECK " == " false" ]
606+ if [[ " $RESPONSE_BODY_ENV_CHECK " == " false" ] ]
607607then
608608 passed " Environment variables not present in the output by default"
609609else
@@ -677,7 +677,7 @@ wait_for_removed
677677
678678message " Start container with a custom response body from a file "
679679echo " <h1>Hello World</h1>" > test.html
680- docker run -d --rm -v ${PWD} /test.html:/app/test.html --name http-echo-tests -p 8080:8080 -e OVERRIDE_RESPONSE_BODY_FILE_PATH=/test.html -t mendhak/http-https-echo:testing
680+ docker run -d --rm -v " ${PWD} /test.html:/app/test.html" --name http-echo-tests -p 8080:8080 -e OVERRIDE_RESPONSE_BODY_FILE_PATH=/test.html -t mendhak/http-https-echo:testing
681681wait_for_ready
682682
683683RESPONSE_BODY=$( curl -s http://localhost:8080)
@@ -713,7 +713,7 @@ console.log(sign('my-value','mysecretkey123'));")
713713
714714
715715RESPONSE=$( curl -s http://localhost:8080/ -H " Cookie: mysigned=s:${SIGNED_COOKIE} " )
716- if [ " $( echo " $RESPONSE " | jq -r ' .signedCookies.mysigned' ) " == ' my-value' ]; then
716+ if [[ " $( echo " $RESPONSE " | jq -r ' .signedCookies.mysigned' ) " == ' my-value' ] ]; then
717717 passed " Signed cookie test passed."
718718else
719719 failed " Signed cookie test failed."
@@ -732,8 +732,8 @@ wait_for_ready
732732
733733
734734RESPONSE=$( curl -s http://localhost:8080/ -H " Cookie: foo=bar; baz=qux" )
735- if [ " $( echo " $RESPONSE " | jq -r ' .cookies.foo' ) " == ' bar' ] && \
736- [ " $( echo " $RESPONSE " | jq -r ' .cookies.baz' ) " == ' qux' ]; then
735+ if [[ " $( echo " $RESPONSE " | jq -r ' .cookies.foo' ) " == ' bar' ] ] && \
736+ [[ " $( echo " $RESPONSE " | jq -r ' .cookies.baz' ) " == ' qux' ] ]; then
737737 passed " Cookies returned in response test passed."
738738else
739739 failed " Cookies returned in response test failed."
0 commit comments