File tree Expand file tree Collapse file tree
charts/router-probe-backend Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5555 access_log /dev/stdout json_event;
5656 error_log /dev/stderr;
5757
58+ absolute_redirect off;
59+
5860 location / {
5961 return 404;
6062 }
6466 }
6567
6668 location = /__probe__/redirect {
67- return 301 $scheme://$host /redirected;
69+ return 301 /__probe__ /redirected;
6870 }
6971
7072 location = /__probe__/redirected {
Original file line number Diff line number Diff line change @@ -93,18 +93,50 @@ function expect {
9393 >&2 echo " Status Code for $RESOURCE :"
9494 >&2 echo " Expected: $EXPECTED_STATUS "
9595 >&2 echo " Actual: $ACTUAL_STATUS "
96+ return 1
9697 fi
9798
9899 cat " $TMPFILE "
99100}
100101
102+ function expect_redirect_to_location {
103+ # Args:
104+ # $1: HTTP Method
105+ # $2: Resource path to curl
106+ # $3: Redirect Location Header Expected in response
107+ local METHOD=" $1 "
108+ local RESOURCE=" $2 "
109+ local EXPECTED_LOCATION=" $3 "
110+ local ACTUAL_LOCATION
111+
112+ >&2 echo -n " Testing ${METHOD} ${RESOURCE} redirects to ${EXPECTED_LOCATION} ... "
113+ ACTUAL_LOCATION=$(
114+ curl --request " ${METHOD} " --verbose " http://127.0.0.1:80${RESOURCE} " 2>&1 | \
115+ grep -i ' < location:' | \
116+ tr -d ' \r' | \
117+ sed -E ' s/.*[Ll]ocation: //'
118+ )
119+
120+ if [ " $ACTUAL_LOCATION " == " $EXPECTED_LOCATION " ]; then
121+ >&2 echo " OK"
122+ else
123+ >&2 echo " ERROR"
124+ >&2 echo " Redirect Location for $RESOURCE :"
125+ >&2 echo " Expected: [$EXPECTED_LOCATION ]"
126+ >&2 echo " Actual: [$ACTUAL_LOCATION ]"
127+ return 1
128+ fi
129+ }
130+
131+
101132echo " ============================================="
102133echo " Executing Tests:"
103134echo " ============================================="
104135{
105136 expect " GET" " /" " 404"
106137 expect " GET" " /__probe__/ok" " 200"
107138 expect " GET" " /__probe__/redirect" " 301"
139+ expect_redirect_to_location " GET" " /__probe__/redirect" " /__probe__/redirected"
108140 expect " GET" " /__probe__/not-found" " 404"
109141 expect " GET" " /__probe__/internal-server-error" " 500"
110142 expect " GET" " /__probe__/get" " 200"
You can’t perform that action at this time.
0 commit comments