2019-01-18 17:20:41 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
CIRCLECI_FOLDER="${BASH_SOURCE[0]%/*}"
|
|
|
|
cd $CIRCLECI_FOLDER
|
|
|
|
CIRCLECI_FOLDER="$PWD"
|
|
|
|
|
|
|
|
SERVER_ROOT="$CIRCLECI_FOLDER/../server"
|
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
i=1
|
|
|
|
echoInfo() {
|
2022-01-11 14:21:49 +03:00
|
|
|
echo -e "\033[36m$i. $*\033[0m"
|
|
|
|
i=$((i + 1))
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fail_if_port_busy() {
|
2022-01-11 14:21:49 +03:00
|
|
|
local PORT=$1
|
|
|
|
if nc -z localhost $PORT; then
|
|
|
|
echo "Port $PORT is busy. Exiting"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wait_for_port() {
|
2022-01-11 14:21:49 +03:00
|
|
|
local PORT=$1
|
|
|
|
echo "waiting for $PORT"
|
|
|
|
for _ in $(seq 1 60); do
|
|
|
|
nc -z localhost $PORT && echo "port $PORT is ready" && return
|
|
|
|
echo -n .
|
|
|
|
sleep 0.2
|
|
|
|
done
|
|
|
|
echo "Failed waiting for $PORT" && exit 1
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
test_export_metadata_with_admin_secret() {
|
2022-01-11 14:21:49 +03:00
|
|
|
curl -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query -H "X-Hasura-Admin-Secret: $1" >/dev/null
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|
|
|
|
|
2019-01-18 17:20:41 +03:00
|
|
|
cd $SERVER_ROOT
|
|
|
|
|
2022-01-11 14:21:49 +03:00
|
|
|
if [ -z "${HASURA_GRAPHQL_DATABASE_URL:-}" ]; then
|
2019-01-18 17:20:41 +03:00
|
|
|
echo "Env var HASURA_GRAPHQL_DATABASE_URL is not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
HGE_PID=""
|
|
|
|
|
|
|
|
run_hge_with_flags() {
|
2022-01-11 14:21:49 +03:00
|
|
|
fail_if_port_busy 8080
|
|
|
|
set -x
|
|
|
|
stdbuf -o0 "$GRAPHQL_ENGINE" serve $* >"$OUTPUT_FOLDER/graphql-engine.log" &
|
|
|
|
HGE_PID=$!
|
|
|
|
set +x
|
|
|
|
wait_for_port 8080
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
kill_hge() {
|
2022-01-11 14:21:49 +03:00
|
|
|
kill -s INT $HGE_PID || true
|
|
|
|
wait $HGE_PID || true
|
2019-02-14 12:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
trap kill_hge ERR
|
|
|
|
trap kill_hge INT
|
|
|
|
|
2019-01-18 17:20:41 +03:00
|
|
|
OUTPUT_FOLDER=${OUTPUT_FOLDER:-"$CIRCLECI_FOLDER/test-server-flags-output"}
|
|
|
|
mkdir -p "$OUTPUT_FOLDER"
|
|
|
|
|
2020-06-04 23:20:06 +03:00
|
|
|
########## Test that we didn't compile with +developer by accident
|
2021-07-12 23:06:09 +03:00
|
|
|
echoInfo "Test we didn't compile in the developer-only APIs"
|
2020-06-04 23:20:06 +03:00
|
|
|
|
|
|
|
run_hge_with_flags
|
|
|
|
|
2022-01-11 14:21:49 +03:00
|
|
|
code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/dev/plan_cache)
|
2020-12-21 12:11:37 +03:00
|
|
|
if [ "$code" != "404" ]; then
|
2022-01-11 14:21:49 +03:00
|
|
|
echo "Expected a dev endpoint to return 404, but got: $code"
|
|
|
|
exit 1
|
2020-06-04 23:20:06 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
kill_hge
|
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
########## Test --use-prepared-statements=false and flag --admin-secret
|
|
|
|
|
|
|
|
key="HGE$RANDOM$RANDOM"
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
run_hge_with_flags --use-prepared-statements=false --admin-secret="$key"
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
echoInfo "Test flag --admin-secret=XXXX"
|
|
|
|
grep -F '"admin_secret_set":true' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null
|
|
|
|
test_export_metadata_with_admin_secret "$key"
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
echoInfo "Test flag --use-prepared-statements=false"
|
|
|
|
grep -F '"use_prepared_statements":false' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
kill_hge
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
###### Test --use-prepared-statements=true
|
|
|
|
key="HGE$RANDOM$RANDOM"
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2022-07-27 14:46:19 +03:00
|
|
|
run_hge_with_flags --use-prepared-statements=true --admin-secret="$key"
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
echoInfo "Test --use-prepared-statements=true"
|
2022-07-27 14:46:19 +03:00
|
|
|
kill_hge
|
2019-02-14 12:37:47 +03:00
|
|
|
grep -F '"use_prepared_statements":true' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
|
|
|
|
######### Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd
|
2019-01-18 17:20:41 +03:00
|
|
|
|
|
|
|
export HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd
|
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
fail_if_port_busy 8080
|
2022-01-11 14:21:49 +03:00
|
|
|
timeout 3 stdbuf -o0 "$GRAPHQL_ENGINE" serve >"$OUTPUT_FOLDER/graphql-engine.log" 2>&1 &
|
|
|
|
PID=$!
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
wait $PID || true
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
echoInfo "Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=abcd"
|
2022-01-11 14:21:49 +03:00
|
|
|
grep -F 'Not a valid boolean text' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
######### Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=false and HASURA_GRAPHQL_ADMIN_SECRET=XXXX
|
|
|
|
key="HGE$RANDOM$RANDOM"
|
2019-01-18 17:20:41 +03:00
|
|
|
|
|
|
|
export HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=false
|
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
export HASURA_GRAPHQL_ADMIN_SECRET="$key"
|
|
|
|
|
|
|
|
run_hge_with_flags
|
|
|
|
|
|
|
|
echoInfo "Test flag HASURA_GRAPHQL_ADMIN_SECRET=XXXX"
|
|
|
|
grep -F '"admin_secret_set":true' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
|
|
|
|
test_export_metadata_with_admin_secret "$key"
|
|
|
|
|
|
|
|
echoInfo "Test HASURA_GRAPHQL_USE_PREPARED_STATEMENTS=false"
|
|
|
|
grep -F '"use_prepared_statements":false' "$OUTPUT_FOLDER/graphql-engine.log" >/dev/null || (cat "$OUTPUT_FOLDER/graphql-engine.log" && false)
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
kill_hge
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
unset HASURA_GRAPHQL_ADMIN_SECRET
|
2019-01-18 17:20:41 +03:00
|
|
|
|
2019-02-14 12:37:47 +03:00
|
|
|
unset HASURA_GRAPHQL_USE_PREPARED_STATEMENTS
|