2018-10-28 21:27:49 +03:00
#!/usr/bin/env bash
set -euo pipefail
### Functions
stop_services( ) {
2019-08-26 08:31:27 +03:00
kill -s INT $HGE_PIDS || true
2019-04-08 10:22:38 +03:00
kill $WH_PID || true
2019-08-26 08:31:27 +03:00
kill -s INT $WHC_PID || true
2019-04-08 10:22:38 +03:00
}
time_elapsed( ) {
printf "(%02d:%02d)" $[ SECONDS/60] $[ SECONDS%60]
}
fail_if_port_busy( ) {
local PORT = $1
if nc -z localhost $PORT ; then
echo " Port $PORT is busy. Exiting "
exit 1
fi
2018-10-28 21:27:49 +03:00
}
wait_for_port( ) {
local PORT = $1
echo " waiting for $PORT "
2019-12-13 00:46:33 +03:00
for _ in $( seq 1 60) ;
2018-10-28 21:27:49 +03:00
do
nc -z localhost $PORT && echo " port $PORT is ready " && return
echo -n .
2019-02-14 12:37:47 +03:00
sleep 0.25
2018-10-28 21:27:49 +03:00
done
echo " Failed waiting for $PORT " && exit 1
}
init_jwt( ) {
CUR_DIR = " $PWD "
mkdir -p " $OUTPUT_FOLDER /ssl "
cd " $OUTPUT_FOLDER /ssl "
openssl genrsa -out jwt_private.key 2048
openssl rsa -pubout -in jwt_private.key -out jwt_public.key
cd " $CUR_DIR "
}
init_ssl( ) {
CUR_DIR = " $PWD "
mkdir -p " $OUTPUT_FOLDER /ssl "
cd " $OUTPUT_FOLDER /ssl "
CNF_TEMPLATE = ' [ req]
req_extensions = v3_req
distinguished_name = req_distinguished_name
[ req_distinguished_name]
[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[ alt_names]
DNS.1 = localhost
IP.1 = 127.0.0.1'
echo " $CNF_TEMPLATE " > webhook-req.cnf
openssl genrsa -out ca-key.pem 2048
openssl req -x509 -new -nodes -key ca-key.pem -days 10 -out ca.pem -subj "/CN=webhook-ca"
openssl genrsa -out webhook-key.pem 2048
openssl req -new -key webhook-key.pem -out webhook.csr -subj "/CN=hge-webhook" -config webhook-req.cnf
openssl x509 -req -in webhook.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out webhook.pem -days 10 -extensions v3_req -extfile webhook-req.cnf
cp ca.pem /etc/ssl/certs/webhook.crt
update-ca-certificates
cd " $CUR_DIR "
}
2019-04-08 10:22:38 +03:00
combine_all_hpc_reports( ) {
combined_file = " ${ OUTPUT_FOLDER } /graphql-engine.tix "
combined_file_intermediate = " ${ OUTPUT_FOLDER } /hpc/graphql-engine-combined-intermediate.tix "
rm -f " $combined_file "
IFS = : tix_files_arr = ( $TIX_FILES )
unset IFS
2020-01-18 01:07:15 +03:00
for tix_file in " ${ tix_files_arr [@] } " ; do
if ! [ -f " $tix_file " ] ; then
2019-04-08 10:22:38 +03:00
continue
fi
2020-01-18 01:07:15 +03:00
if [ -f " $combined_file " ] ; then
# Unset GHCRTS as hpc combine fails if GCHRTS=-N2 is present
( unset GHCRTS
set -x
hpc combine " $combined_file " " $tix_file " --union --output= " $combined_file_intermediate "
set +x
mv " $combined_file_intermediate " " $combined_file "
rm " $tix_file "
) || true
2019-04-08 10:22:38 +03:00
else
mv " $tix_file " " $combined_file " || true
fi
done
}
2020-01-18 01:07:15 +03:00
generate_coverage_report( ) {
combine_all_hpc_reports
( shopt -s failglob
unset GHCRTS
cd ~/graphql-engine/server
mix_dirs = ( " $MIX_FILES_FOLDER " /*)
# This is the bash syntax to prepend `--hpcdir=` to each element of an array. Yeah, I don’ t like
# it, either.
hpcdir_args = ( " ${ mix_dirs [@]/#/--hpcdir= } " )
hpc_args = ( " ${ hpcdir_args [@] } " --reset-hpcdirs " $OUTPUT_FOLDER /graphql-engine.tix " )
hpc report " ${ hpc_args [@] } "
mkdir -p " $OUTPUT_FOLDER /coverage "
hpc markup " ${ hpc_args [@] } " --destdir= " $OUTPUT_FOLDER /coverage " )
}
2019-04-08 10:22:38 +03:00
kill_hge_servers( ) {
2019-08-26 08:31:27 +03:00
kill -s INT $HGE_PIDS || true
2019-04-08 10:22:38 +03:00
wait $HGE_PIDS || true
HGE_PIDS = ""
2018-10-28 21:27:49 +03:00
}
2019-04-08 10:22:38 +03:00
run_hge_with_args( ) {
i = $(( TIX_FILE_INDEX++))
export HPCTIXFILE = " ${ OUTPUT_FOLDER } /hpc/graphql-engine- ${ i } - ${ TEST_TYPE } .tix "
rm -f " $HPCTIXFILE "
TIX_FILES = " $TIX_FILES : $HPCTIXFILE "
set -x
" $GRAPHQL_ENGINE " " $@ " 2>& 1 > " $OUTPUT_FOLDER /graphql-engine- ${ i } - ${ TEST_TYPE } .log " & HGE_PIDS = " $HGE_PIDS $! "
set +x
2019-02-28 16:53:03 +03:00
}
2019-04-08 10:22:38 +03:00
start_multiple_hge_servers( ) {
run_hge_with_args --database-url " $HASURA_GRAPHQL_DATABASE_URL " serve " $@ "
if [ -n ${ HASURA_GRAPHQL_DATABASE_URL_2 :- } ] ; then
run_hge_with_args --database-url " $HASURA_GRAPHQL_DATABASE_URL_2 " serve --server-port 8081 " $@ "
wait_for_port 8081
fi
wait_for_port 8080
}
2018-10-28 21:27:49 +03:00
if [ -z " ${ HASURA_GRAPHQL_DATABASE_URL :- } " ] ; then
echo "Env var HASURA_GRAPHQL_DATABASE_URL is not set"
exit 1
fi
2019-04-08 10:22:38 +03:00
if [ -z " ${ HASURA_GRAPHQL_DATABASE_URL_2 :- } " ] ; then
echo "Env var HASURA_GRAPHQL_DATABASE_URL_2 is not set"
exit 1
fi
2018-10-28 21:27:49 +03:00
CIRCLECI_FOLDER = " ${ BASH_SOURCE [0]%/* } "
cd $CIRCLECI_FOLDER
CIRCLECI_FOLDER = " $PWD "
2019-02-14 12:37:47 +03:00
if ! $CIRCLECI_FOLDER /test-server-flags.sh ; then
2019-01-18 17:20:41 +03:00
echo "Testing GraphQL server flags failed"
exit 1
fi
2019-02-14 12:37:47 +03:00
if ! $CIRCLECI_FOLDER /test-deprecated-server-flags.sh ; then
echo "Testing GraphQL deprecated server flags failed"
exit 1
fi
2018-10-28 21:27:49 +03:00
PYTEST_ROOT = " $CIRCLECI_FOLDER /../server/tests-py "
OUTPUT_FOLDER = ${ OUTPUT_FOLDER :- " $CIRCLECI_FOLDER /test-server-output " }
mkdir -p " $OUTPUT_FOLDER "
2019-04-08 10:22:38 +03:00
TEST_TYPE = "no-auth"
HPCTIXFILE = ""
TIX_FILE_INDEX = "1"
TIX_FILES = ""
2018-10-28 21:27:49 +03:00
cd $PYTEST_ROOT
RUN_WEBHOOK_TESTS = true
2019-04-08 10:22:38 +03:00
for port in 8080 8081 9876 5592
do
fail_if_port_busy $port
done
2018-10-28 21:27:49 +03:00
echo -e " \nINFO: GraphQL Executable : $GRAPHQL_ENGINE "
echo -e " INFO: Logs Folder : $OUTPUT_FOLDER \n "
pip3 install -r requirements.txt
2019-04-08 10:22:38 +03:00
mkdir -p " $OUTPUT_FOLDER /hpc "
2018-10-28 21:27:49 +03:00
export EVENT_WEBHOOK_HEADER = "MyEnvValue"
export HGE_URL = "http://localhost:8080"
2019-04-08 10:22:38 +03:00
export HGE_URL_2 = ""
if [ -n ${ HASURA_GRAPHQL_DATABASE_URL_2 :- } ] ; then
HGE_URL_2 = "http://localhost:8081"
fi
2018-11-14 10:13:01 +03:00
export WEBHOOK_FROM_ENV = "http://127.0.0.1:5592"
2019-03-01 14:45:04 +03:00
export HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES = true
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
HGE_PIDS = ""
2018-10-28 21:27:49 +03:00
WH_PID = ""
2019-04-08 10:22:38 +03:00
WHC_PID = ""
2019-03-12 08:46:27 +03:00
HS_PID = ""
2018-10-28 21:27:49 +03:00
trap stop_services ERR
trap stop_services INT
2019-04-08 10:22:38 +03:00
run_pytest_parallel( ) {
trap stop_services ERR
if [ -n ${ HASURA_GRAPHQL_DATABASE_URL_2 :- } ] ; then
set -x
pytest -vv --hge-urls " $HGE_URL " " ${ HGE_URL_2 :- } " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " " ${ HASURA_GRAPHQL_DATABASE_URL_2 :- } " -n 2 --dist= loadfile " $@ "
set +x
else
set -x
pytest -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " -n 1 " $@ "
set +x
fi
}
2018-10-28 21:27:49 +03:00
2019-11-18 21:45:54 +03:00
echo -e " \n $( time_elapsed) : <########## RUN GRAPHQL-ENGINE HASKELL TESTS ###########################################>\n "
" ${ GRAPHQL_ENGINE_TESTS : ? } " postgres
2019-10-21 19:01:05 +03:00
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITHOUT ADMIN SECRET ###########################################>\n "
TEST_TYPE = "no-auth"
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
start_multiple_hge_servers
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
run_pytest_parallel
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2018-10-28 21:27:49 +03:00
2019-02-14 12:37:47 +03:00
##########
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET #####################################>\n "
TEST_TYPE = "admin-secret"
2019-02-14 08:58:38 +03:00
2019-02-14 12:37:47 +03:00
export HASURA_GRAPHQL_ADMIN_SECRET = " HGE $RANDOM $RANDOM "
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
start_multiple_hge_servers
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
run_pytest_parallel --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET "
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2018-10-28 21:27:49 +03:00
2019-02-14 12:37:47 +03:00
##########
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET AND JWT #####################################>\n "
TEST_TYPE = "jwt"
2018-10-28 21:27:49 +03:00
init_jwt
export HASURA_GRAPHQL_JWT_SECRET = " $( jq -n --arg key " $( cat $OUTPUT_FOLDER /ssl/jwt_public.key) " '{ type: "RS512", key: $key }' ) "
2019-04-08 10:22:38 +03:00
start_multiple_hge_servers
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
run_pytest_parallel --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-jwt-key-file= " $OUTPUT_FOLDER /ssl/jwt_private.key " --hge-jwt-conf= " $HASURA_GRAPHQL_JWT_SECRET "
2019-02-05 15:04:16 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-02-05 15:04:16 +03:00
unset HASURA_GRAPHQL_JWT_SECRET
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET AND JWT (in stringified mode) #####################################>\n "
TEST_TYPE = "jwt-stringified"
2019-02-05 15:04:16 +03:00
export HASURA_GRAPHQL_JWT_SECRET = " $( jq -n --arg key " $( cat $OUTPUT_FOLDER /ssl/jwt_public.key) " '{ type: "RS512", key: $key , claims_format: "stringified_json"}' ) "
2019-04-08 10:22:38 +03:00
run_hge_with_args serve
wait_for_port 8080
2019-02-05 15:04:16 +03:00
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-jwt-key-file= " $OUTPUT_FOLDER /ssl/jwt_private.key " --hge-jwt-conf= " $HASURA_GRAPHQL_JWT_SECRET " test_jwt.py
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2018-10-28 21:27:49 +03:00
unset HASURA_GRAPHQL_JWT_SECRET
2019-07-11 12:58:39 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET AND JWT (with audience check - string) #####################################>\n "
TEST_TYPE = "jwt-audience-check-single-string"
export HASURA_GRAPHQL_JWT_SECRET = " $( jq -n --arg key " $( cat $OUTPUT_FOLDER /ssl/jwt_public.key) " '{ type: "RS512", key: $key , audience: "myapp-1234"}' ) "
run_hge_with_args serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-jwt-key-file= " $OUTPUT_FOLDER /ssl/jwt_private.key " --hge-jwt-conf= " $HASURA_GRAPHQL_JWT_SECRET " test_jwt.py
kill_hge_servers
unset HASURA_GRAPHQL_JWT_SECRET
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET AND JWT (with audience check - list of strings) #################################>\n "
TEST_TYPE = "jwt-audience-check-list-string"
export HASURA_GRAPHQL_JWT_SECRET = " $( jq -n --arg key " $( cat $OUTPUT_FOLDER /ssl/jwt_public.key) " '{ type: "RS512", key: $key , audience: ["myapp-1234", "myapp-9876"]}' ) "
run_hge_with_args serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-jwt-key-file= " $OUTPUT_FOLDER /ssl/jwt_private.key " --hge-jwt-conf= " $HASURA_GRAPHQL_JWT_SECRET " test_jwt.py
kill_hge_servers
unset HASURA_GRAPHQL_JWT_SECRET
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET AND JWT (with issuer check) #####################################>\n "
TEST_TYPE = "jwt-issuer-check"
export HASURA_GRAPHQL_JWT_SECRET = " $( jq -n --arg key " $( cat $OUTPUT_FOLDER /ssl/jwt_public.key) " '{ type: "RS512", key: $key , issuer: "https://hasura.com"}' ) "
run_hge_with_args serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-jwt-key-file= " $OUTPUT_FOLDER /ssl/jwt_private.key " --hge-jwt-conf= " $HASURA_GRAPHQL_JWT_SECRET " test_jwt.py
kill_hge_servers
unset HASURA_GRAPHQL_JWT_SECRET
2019-02-14 08:58:38 +03:00
# test with CORS modes
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH CORS DOMAINS ########>\n "
2019-02-14 08:58:38 +03:00
export HASURA_GRAPHQL_CORS_DOMAIN = "http://*.localhost, http://localhost:3000, https://*.foo.bar.com"
2019-04-08 10:22:38 +03:00
TEST_TYPE = "cors-domains"
2019-02-14 08:58:38 +03:00
2019-04-08 10:22:38 +03:00
run_hge_with_args serve
2019-02-14 08:58:38 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-cors test_cors.py
2019-02-14 08:58:38 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-02-28 16:53:03 +03:00
2019-02-14 08:58:38 +03:00
unset HASURA_GRAPHQL_CORS_DOMAIN
2019-03-04 10:46:53 +03:00
# test websocket transport with initial cookie header
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsped) : <########## TEST GRAPHQL-ENGINE WITH COOKIE IN WEBSOCKET INIT ########>\n "
TEST_TYPE = "ws-init-cookie-read-cors-enabled"
2019-03-04 10:46:53 +03:00
export HASURA_GRAPHQL_AUTH_HOOK = "http://localhost:9876/auth"
export HASURA_GRAPHQL_AUTH_HOOK_MODE = "POST"
python3 test_cookie_webhook.py > " $OUTPUT_FOLDER /cookie_webhook.log " 2>& 1 & WHC_PID = $!
wait_for_port 9876
2019-04-08 10:22:38 +03:00
run_hge_with_args serve
2019-03-04 10:46:53 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
echo " $( time_elapsed) : testcase 1: read cookie, cors enabled "
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-ws-init-cookie= read test_websocket_init_cookie.py
2019-03-04 10:46:53 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-03-04 10:46:53 +03:00
2019-04-08 10:22:38 +03:00
echo " $( time_elapsed) : testcase 2: no read cookie, cors disabled "
TEST_TYPE = "ws-init-cookie-noread"
run_hge_with_args serve --disable-cors
2019-03-04 10:46:53 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-ws-init-cookie= noread test_websocket_init_cookie.py
2019-03-04 10:46:53 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-03-04 10:46:53 +03:00
2019-04-08 10:22:38 +03:00
echo " $( time_elapsed) : testcase 3: read cookie, cors disabled and ws-read-cookie "
TEST_TYPE = "ws-init-cookie-read-cors-disabled"
2019-03-04 10:46:53 +03:00
export HASURA_GRAPHQL_WS_READ_COOKIE = "true"
2019-04-08 10:22:38 +03:00
run_hge_with_args serve --disable-cors
2019-03-04 10:46:53 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-ws-init-cookie= read test_websocket_init_cookie.py
2019-03-04 10:46:53 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
kill $WHC_PID
2019-03-04 10:46:53 +03:00
unset HASURA_GRAPHQL_WS_READ_COOKIE
unset HASURA_GRAPHQL_AUTH_HOOK
unset HASURA_GRAPHQL_AUTH_HOOK_MODE
sleep 4
2019-02-28 16:53:03 +03:00
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH GRAPHQL DISABLED ########>\n "
TEST_TYPE = "ws-graphql-api-disabled"
2019-02-28 16:53:03 +03:00
export HASURA_GRAPHQL_ENABLED_APIS = "metadata"
2019-04-08 10:22:38 +03:00
run_hge_with_args serve
2019-02-28 16:53:03 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-graphql-disabled test_apis_disabled.py
2019-02-28 16:53:03 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-02-28 16:53:03 +03:00
unset HASURA_GRAPHQL_ENABLED_APIS
2019-04-08 10:22:38 +03:00
run_hge_with_args serve --enabled-apis metadata
2019-02-28 16:53:03 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-graphql-disabled test_apis_disabled.py
2019-02-28 16:53:03 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-02-28 16:53:03 +03:00
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH METADATA DISABLED ########>\n "
TEST_TYPE = "ws-metadata-api-disabled"
2019-02-28 16:53:03 +03:00
export HASURA_GRAPHQL_ENABLED_APIS = "graphql"
2019-04-08 10:22:38 +03:00
run_hge_with_args serve
2019-02-28 16:53:03 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-metadata-disabled test_apis_disabled.py
2019-02-28 16:53:03 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-02-28 16:53:03 +03:00
unset HASURA_GRAPHQL_ENABLED_APIS
2019-04-08 10:22:38 +03:00
run_hge_with_args serve --enabled-apis graphql
2019-02-28 16:53:03 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-metadata-disabled test_apis_disabled.py
2019-02-28 16:53:03 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-02-14 08:58:38 +03:00
2019-10-16 17:33:34 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE QUERY CACHING #####################################>\n "
TEST_TYPE = "query-caching"
# use only one capability to disable cache striping
run_hge_with_args +RTS -N1 -RTS serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " test_graphql_queries.py::TestGraphQLQueryCaching
kill_hge_servers
2019-07-11 08:37:06 +03:00
# verbose logging tests
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH QUERY LOG ########>\n "
TEST_TYPE = "query-logs"
export HASURA_GRAPHQL_ENABLED_LOG_TYPES = " startup,http-log,webhook-log,websocket-log,query-log"
#run_hge_with_args serve
# we are doing this instead of calling run_hge_with_args, because we want to save in a custom log file
i = $(( TIX_FILE_INDEX++))
export HPCTIXFILE = " ${ OUTPUT_FOLDER } /hpc/graphql-engine- ${ i } - ${ TEST_TYPE } .tix "
rm -f " $HPCTIXFILE "
TIX_FILES = " $TIX_FILES : $HPCTIXFILE "
set -x
export LOGGING_TEST_LOGFILE_PATH = " $OUTPUT_FOLDER /graphql-engine-verbose-logging.log "
" $GRAPHQL_ENGINE " serve 2>& 1 > " $LOGGING_TEST_LOGFILE_PATH " & HGE_PIDS = " $HGE_PIDS $! "
set +x
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-logging test_logging.py
unset HASURA_GRAPHQL_ENABLED_LOG_TYPES
kill_hge_servers
# end verbose logging tests
2019-03-04 10:46:53 +03:00
2019-02-14 08:58:38 +03:00
# webhook tests
2018-10-28 21:27:49 +03:00
if [ $EUID != 0 ] ; then
echo -e "SKIPPING webhook based tests, as \nroot permission is required for running webhook tests (inorder to trust certificate authority)."
RUN_WEBHOOK_TESTS = false
fi
if [ " $RUN_WEBHOOK_TESTS " = = "true" ] ; then
2019-04-08 10:22:38 +03:00
TEST_TYPE = "post-webhook"
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET & WEBHOOK (GET) #########################>\n "
2018-10-28 21:27:49 +03:00
export HASURA_GRAPHQL_AUTH_HOOK = "https://localhost:9090/"
init_ssl
2019-04-08 10:22:38 +03:00
start_multiple_hge_servers
2018-10-28 21:27:49 +03:00
python3 webhook.py 9090 " $OUTPUT_FOLDER /ssl/webhook-key.pem " " $OUTPUT_FOLDER /ssl/webhook.pem " > " $OUTPUT_FOLDER /webhook.log " 2>& 1 & WH_PID = $!
wait_for_port 9090
2019-04-08 10:22:38 +03:00
run_pytest_parallel --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-webhook= " $HASURA_GRAPHQL_AUTH_HOOK "
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2018-12-03 14:19:08 +03:00
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET & WEBHOOK (POST) #########################>\n "
TEST_TYPE = "get-webhook"
export HASURA_GRAPHQL_AUTH_HOOK_MODE = "POST"
2018-12-03 14:19:08 +03:00
2019-04-08 10:22:38 +03:00
start_multiple_hge_servers
2018-12-03 14:19:08 +03:00
2019-04-08 10:22:38 +03:00
run_pytest_parallel --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-webhook= " $HASURA_GRAPHQL_AUTH_HOOK "
2018-12-03 14:19:08 +03:00
2018-10-28 21:27:49 +03:00
rm /etc/ssl/certs/webhook.crt
update-ca-certificates
2019-04-08 10:22:38 +03:00
kill_hge_servers
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN SECRET & HTTPS INSECURE WEBHOOK (GET) ########>\n "
TEST_TYPE = "insecure-webhook"
export HASURA_GRAPHQL_AUTH_HOOK_MODE = "GET"
2018-12-03 14:19:08 +03:00
2019-04-08 10:22:38 +03:00
run_hge_with_args serve
2018-12-03 14:19:08 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-webhook= " $HASURA_GRAPHQL_AUTH_HOOK " --test-webhook-insecure test_webhook_insecure.py
2018-12-03 14:19:08 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2018-12-03 14:19:08 +03:00
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ADMIN_SECRET & HTTPS INSECURE WEBHOOK (POST) ########>\n "
TEST_TYPE = "insecure-webhook-with-admin-secret"
export HASURA_GRAPHQL_AUTH_HOOK_MODE = "POST"
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
run_hge_with_args serve
2018-10-28 21:27:49 +03:00
wait_for_port 8080
2019-04-08 10:22:38 +03:00
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --hge-webhook= " $HASURA_GRAPHQL_AUTH_HOOK " --test-webhook-insecure test_webhook_insecure.py
2018-10-28 21:27:49 +03:00
2019-04-08 10:22:38 +03:00
kill_hge_servers
2018-10-28 21:27:49 +03:00
kill $WH_PID
2019-02-14 08:58:38 +03:00
2018-10-28 21:27:49 +03:00
fi
2019-05-16 09:13:25 +03:00
# allowlist queries test
unset HASURA_GRAPHQL_AUTH_HOOK
unset HASURA_GRAPHQL_AUTH_HOOK_MODE
unset HASURA_GRAPHQL_JWT_SECRET
unset HASURA_GRAPHQL_ENABLE_ALLOWLIST
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH ALLOWLIST QUERIES ########> \n "
export HASURA_GRAPHQL_ENABLE_ALLOWLIST = true
TEST_TYPE = "allowlist-queries"
run_hge_with_args serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-allowlist-queries test_allowlist_queries.py
kill_hge_servers
unset HASURA_GRAPHQL_ENABLE_ALLOWLIST
run_hge_with_args serve --enable-allowlist
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-allowlist-queries test_allowlist_queries.py
kill_hge_servers
# end allowlist queries test
2019-12-03 23:56:59 +03:00
# jwk test
unset HASURA_GRAPHQL_AUTH_HOOK
unset HASURA_GRAPHQL_AUTH_HOOK_MODE
unset HASURA_GRAPHQL_JWT_SECRET
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH JWK URL ########> \n "
TEST_TYPE = "jwk-url"
# start the JWK server
python3 jwk_server.py > " $OUTPUT_FOLDER /jwk_server.log " 2>& 1 & JWKS_PID = $!
wait_for_port 5001
cache_control_jwk_url = '{"type": "RS256", "jwk_url": "http://localhost:5001/jwk-cache-control"}'
expires_jwk_url = '{"type": "RS256", "jwk_url": "http://localhost:5001/jwk-expires"}'
2020-02-05 10:07:31 +03:00
cc_nomaxage_jwk_url = '{"type": "RS256", "jwk_url": "http://localhost:5001/jwk-cache-control?nomaxage"}'
cc_nocache_jwk_url = '{"type": "RS256", "jwk_url": "http://localhost:5001/jwk-cache-control?nocache"}'
2019-12-03 23:56:59 +03:00
# start HGE with cache control JWK URL
export HASURA_GRAPHQL_JWT_SECRET = $cache_control_jwk_url
run_hge_with_args serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-jwk-url test_jwk.py -k 'test_cache_control_header'
kill_hge_servers
unset HASURA_GRAPHQL_JWT_SECRET
run_hge_with_args serve --jwt-secret " $cache_control_jwk_url "
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-jwk-url test_jwk.py -k 'test_cache_control_header'
kill_hge_servers
# start HGE with expires JWK URL
export HASURA_GRAPHQL_JWT_SECRET = $expires_jwk_url
run_hge_with_args serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-jwk-url test_jwk.py -k 'test_expires_header'
kill_hge_servers
unset HASURA_GRAPHQL_JWT_SECRET
run_hge_with_args serve --jwt-secret " $expires_jwk_url "
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-jwk-url test_jwk.py -k 'test_expires_header'
kill_hge_servers
2020-02-05 10:07:31 +03:00
# start HGE with nomaxage JWK URL
export HASURA_GRAPHQL_JWT_SECRET = $cc_nomaxage_jwk_url
run_hge_with_args serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-jwk-url test_jwk.py -k 'test_cache_control_header'
kill_hge_servers
unset HASURA_GRAPHQL_JWT_SECRET
# start HGE with nocache JWK URL
export HASURA_GRAPHQL_JWT_SECRET = $cc_nocache_jwk_url
run_hge_with_args serve
wait_for_port 8080
pytest -n 1 -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --hge-key= " $HASURA_GRAPHQL_ADMIN_SECRET " --test-jwk-url test_jwk.py -k 'test_cache_control_header'
kill_hge_servers
unset HASURA_GRAPHQL_JWT_SECRET
2019-12-03 23:56:59 +03:00
kill $JWKS_PID
# end jwk url test
2019-03-12 08:46:27 +03:00
# horizontal scale test
unset HASURA_GRAPHQL_AUTH_HOOK
unset HASURA_GRAPHQL_AUTH_HOOK_MODE
unset HASURA_GRAPHQL_ADMIN_SECRET
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## TEST GRAPHQL-ENGINE WITH HORIZONTAL SCALING ########>\n "
TEST_TYPE = "horizontal-scaling"
2019-03-12 08:46:27 +03:00
HASURA_HS_TEST_DB = 'postgres://postgres:postgres@localhost:6543/hs_hge_test'
2019-04-08 10:22:38 +03:00
if ! psql " $HASURA_GRAPHQL_DATABASE_URL " -c "SELECT 1 FROM pg_database WHERE datname = 'hs_hge_test'" | grep -q -F '(1 row)'
then
psql " $HASURA_GRAPHQL_DATABASE_URL " -c 'CREATE DATABASE hs_hge_test;'
fi
pgUserInfo = $( python3 -c '
import os
from urllib.parse import urlparse
uri = urlparse( os.environ[ "HASURA_GRAPHQL_DATABASE_URL" ] )
if uri.password:
print( "password=" +uri.password+" user=" +uri.username)
else :
print( "user=" +uri.username) ' )
pgDbInfo = $( psql " $HASURA_GRAPHQL_DATABASE_URL " -c "SELECT concat(' host=',inet_server_addr(),' port=', inet_server_port(),' dbname=',current_database())" | sed -n '3 p' )
2019-03-12 08:46:27 +03:00
# create pgbouncer user
2019-04-08 10:22:38 +03:00
id pgbouncer || useradd pgbouncer
2019-03-12 08:46:27 +03:00
cd $CIRCLECI_FOLDER
2019-04-08 10:22:38 +03:00
mkdir -p pgbouncer
2019-03-12 08:46:27 +03:00
chown -R pgbouncer:pgbouncer pgbouncer
2019-04-08 10:22:38 +03:00
echo ' [ databases]
hs_hge_test = '"$pgDbInfo" "$pgUserInfo"'
[ pgbouncer]
listen_port = 6543
listen_addr = 127.0.0.1
logfile = pgbouncer/pgbouncer.log
pidfile = pgbouncer/pgbouncer.pid
auth_type = md5
auth_file = pgbouncer/users.txt
admin_users = postgres' > pgbouncer/pgbouncer.ini
2019-03-12 08:46:27 +03:00
# start pgbouncer
pgbouncer -u pgbouncer -d pgbouncer/pgbouncer.ini
cd $PYTEST_ROOT
2019-04-08 10:22:38 +03:00
sleep 2
2019-03-12 08:46:27 +03:00
# start 1st server
2019-04-08 10:22:38 +03:00
run_hge_with_args --database-url " $HASURA_HS_TEST_DB " serve
2019-03-12 08:46:27 +03:00
wait_for_port 8080
# start 2nd server
2019-04-08 10:22:38 +03:00
run_hge_with_args --database-url " $HASURA_HS_TEST_DB " serve \
--server-port 8081
2019-03-12 08:46:27 +03:00
wait_for_port 8081
# run test
2019-04-08 10:22:38 +03:00
pytest -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --test-hge-scale-url= "http://localhost:8081" test_horizontal_scale.py
2019-03-12 08:46:27 +03:00
# Shutdown pgbouncer
psql "postgres://postgres:postgres@localhost:6543/pgbouncer" -c "SHUTDOWN;" || true
cd $CIRCLECI_FOLDER
# start pgbouncer again
pgbouncer -u pgbouncer -d pgbouncer/pgbouncer.ini
cd $PYTEST_ROOT
2019-04-08 10:22:38 +03:00
# sleep for 20 seconds
sleep 20
2019-03-12 08:46:27 +03:00
# run test
2019-04-08 10:22:38 +03:00
pytest -vv --hge-urls " $HGE_URL " --pg-urls " $HASURA_GRAPHQL_DATABASE_URL " --test-hge-scale-url= "http://localhost:8081" test_horizontal_scale.py
2019-03-12 08:46:27 +03:00
# Shutdown pgbouncer
psql "postgres://postgres:postgres@localhost:6543/pgbouncer" -c "SHUTDOWN;" || true
2019-04-08 10:22:38 +03:00
kill_hge_servers
2019-03-12 08:46:27 +03:00
psql " $HASURA_GRAPHQL_DATABASE_URL " -c "drop database hs_hge_test;"
sleep 4
unset HASURA_HS_TEST_DB
# end horizontal scale test
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## COMBINE ALL HPC REPORTS ########>\n "
2020-01-18 01:07:15 +03:00
generate_coverage_report || true
2019-04-08 10:22:38 +03:00
echo -e " \n $( time_elapsed) : <########## DONE ########>\n "