|
main() { |
|
local mode=$1; shift |
|
local httpbin=$1; shift |
|
local result |
|
|
|
for test in ${all_tests[*]}; do |
|
if ! result=$($test $httpbin); then |
|
complain "$test: $result" |
|
continue |
|
fi |
|
|
|
printf "%-32s\t%-32s\t%s\n" $test "$mode" "$result" |
|
done |
|
} |
|
|
|
#curl() { |
|
# echo >&2 "$test: curl $*" |
|
# command curl -v "$@" 2> >(sed "s/^/$test: /" >/dev/tty) |
|
#} |
|
|
|
all_tests=() |
|
|
|
complain() { |
|
if tty -s <&2; then |
|
tput >&2 setaf 1 |
|
echo >&2 "$@" |
|
tput >&2 sgr 0 |
|
else |
|
echo >&2 "$@" |
|
fi |
|
} |
|
|
|
#all_tests+=(test-no-cookie-visibility) |
|
test-no-cookie-visibility() { |
|
local result=$(curl -s $1/cookies | jq -c .cookies.build) |
|
case "$result" in |
|
null) echo invisible;; |
|
'"one"') echo visible;; |
|
*) echo "$result"; return 1;; |
|
esac |
|
} |
|
|
|
all_tests+=(test-known-cookie-visibility) |
|
test-known-cookie-visibility() { |
|
local result=$(curl -s -b build=one $1/cookies | jq -c .cookies.build) |
|
case "$result" in |
|
null) echo invisible;; |
|
'"one"') echo visible;; |
|
*) echo "$result"; return 1;; |
|
esac |
|
} |
|
|
|
all_tests+=(test-unknown-cookie-visibility) |
|
test-unknown-cookie-visibility() { |
|
local result=$(curl -s -b build=two $1/cookies | jq -c .cookies.build) |
|
case "$result" in |
|
null) echo invisible;; |
|
'"one"') echo reset;; |
|
'"two"') echo visible;; |
|
*) echo "$result"; return 1;; |
|
esac |
|
} |
|
|
|
all_tests+=(test-no-cookie-proxy-assertiveness) |
|
test-no-cookie-proxy-assertiveness() { |
|
local result=$(curl -sI $1/get | grep -m1 ^Set-Cookie:) |
|
case "$result" in |
|
"Set-Cookie: build=one;"*|\ |
|
"Set-Cookie: build=1f6f913c14e23c49;"*) |
|
echo assertive;; |
|
"") echo non assertive;; |
|
*) echo "$result"; return 1;; |
|
esac |
|
} |
|
|
|
all_tests+=(test-known-cookie-proxy-assertiveness) |
|
test-known-cookie-proxy-assertiveness() { |
|
local result=$(curl -s -b build=one $1/cookies | grep -m1 ^Set-Cookie:) |
|
case "$result" in |
|
"Set-Cookie: build=one;"*|\ |
|
"Set-Cookie: build=1f6f913c14e23c49;"*) |
|
echo assertive;; |
|
"") echo non assertive;; |
|
*) echo "$result"; return 1;; |
|
esac |
|
} |
|
|
|
all_tests+=(test-unknown-cookie-proxy-assertiveness) |
|
test-unknown-cookie-proxy-assertiveness() { |
|
local result=$(curl -s -b build=two $1/cookies | grep -m1 ^Set-Cookie:) |
|
case "$result" in |
|
"Set-Cookie: build=one;"*|\ |
|
"Set-Cookie: build=1f6f913c14e23c49;"*) |
|
echo assertive;; |
|
"") echo non assertive;; |
|
*) echo "$result"; return 1;; |
|
esac |
|
} |
|
|
|
all_tests+=(test-set-cookie) |
|
test-set-cookie() { |
|
local result=$(curl -sI $1/cookies/set/build/four | grep -m1 ^Set-Cookie:) |
|
case "$result" in |
|
"Set-Cookie: build=one;"*|\ |
|
"Set-Cookie: build=1f6f913c14e23c49;"*) |
|
echo proxy value;; |
|
"Set-Cookie: build=four;"*) |
|
echo server value;; |
|
"Set-Cookie: build=one~four;"*|\ |
|
"Set-Cookie: build=1f6f913c14e23c49~four;"*) |
|
echo combined value;; |
|
*) echo "$result"; return 1;; |
|
esac |
|
} |
|
|
|
all_tests+=(test-reset-cookie) |
|
test-reset-cookie() { |
|
local result=$(curl -sI $1/cookies/delete?build | grep -m1 ^Set-Cookie:) |
|
case "$result" in |
|
"Set-Cookie: build=one;"*|\ |
|
"Set-Cookie: build=1f6f913c14e23c49;"*) |
|
echo proxy value;; |
|
"Set-Cookie: build=; Expires=Thu, 01-Jan-1970 00:00:00 GMT;"*) |
|
echo server value;; |
|
"Set-Cookie: build=one~; Expires=Thu, 01-Jan-1970 00:00:00 GMT;"*|\ |
|
"Set-Cookie: build=1f6f913c14e23c49~; Expires=Thu, 01-Jan-1970 00:00:00 GMT;"*) |
|
echo combined value;; |
|
*) echo "$result"; return 1;; |
|
esac |
|
} |
|
|
|
main "$@" |
The address in haproxy.cfg.in should point to an httpbin container.