File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616FAIL=0
1717TMP_HEADERS=$( mktemp)
1818TMP_BODY=$( mktemp)
19- RESPONSE_TRUSTED=0
2019
2120cleanup () {
2221 rm -f " $TMP_HEADERS " " $TMP_BODY "
@@ -48,39 +47,19 @@ request() {
4847 -X " $METHOD " " $API$URL " )
4948 fi
5049
51- mark_response_trusted
52-
5350 echo " $STATUS "
5451}
5552
5653request_health () {
5754 STATUS=$( curl -L -s -D " $TMP_HEADERS " -o " $TMP_BODY " -w " %{http_code}" " $BASE_URL /health" )
58- mark_response_trusted
5955 echo " $STATUS "
6056}
6157
62- mark_response_trusted () {
63- RESPONSE_TRUSTED=0
64-
65- if grep -qi " ^server: nginx" " $TMP_HEADERS " ; then
66- RESPONSE_TRUSTED=1
67- return 0
68- fi
69-
70- # Accept any valid JSON payload even when server header is rewritten by CDN/proxy.
71- if jq -e . " $TMP_BODY " > /dev/null 2>&1 ; then
72- RESPONSE_TRUSTED=1
73- return 0
74- fi
75-
76- return 1
77- }
78-
7958validate_api_response () {
8059 ENDPOINT=$1
8160
82- if [ " $RESPONSE_TRUSTED " -ne 1 ] ; then
83- echo " Invalid response source for $ENDPOINT : expected 'server: nginx' header or JSON body "
61+ if ! jq -e . " $TMP_BODY " > /dev/null 2>&1 ; then
62+ echo " Invalid JSON response for $ENDPOINT "
8463 return 1
8564 fi
8665
You can’t perform that action at this time.
0 commit comments