selfprivacy-tests/query-all-services.sh

96 lines
1.9 KiB
Bash
Executable File

#! /usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s inherit_errexit
: "${DOMAIN:?specify domain name}"
readonly AUTH_HEADER="Authorization: Bearer ${API_TOKEN:?not set error}"
readonly QUERY='query AllServices {
services {
allServices {
id
isEnabled
status
}
}
}'
# shellcheck disable=SC2116
# shellcheck disable=SC2086
REQUEST=$(cat << EOF
{
"query": "$(echo $QUERY)",
"variables": null,
"operationName": "AllServices"
}
EOF
)
readonly REQUEST
# TODO fix jitsi "isEnabled" expected response value
EXPECTED_RESPONSE=$(cat << EOF
{
"data": {
"services": {
"allServices": [
{
"id": "bitwarden",
"isEnabled": true,
"status": "ACTIVE"
},
{
"id": "gitea",
"isEnabled": true,
"status": "ACTIVE"
},
{
"id": "email",
"isEnabled": true,
"status": "ACTIVE"
},
{
"id": "nextcloud",
"isEnabled": true,
"status": "ACTIVE"
},
{
"id": "pleroma",
"isEnabled": true,
"status": "ACTIVE"
},
{
"id": "ocserv",
"isEnabled": true,
"status": "ACTIVE"
},
{
"id": "jitsi",
"isEnabled": false,
"status": "ACTIVE"
}
]
}
}
}
EOF
)
readonly EXPECTED_RESPONSE
received_response="$(curl --show-error -s "https://api.$DOMAIN/graphql" \
--compressed \
-H 'Content-Type: application/json' \
--data-raw "$REQUEST" -k -H "$AUTH_HEADER" | jq --sort-keys)"
jq <<<"$received_response"
if diff -w -u --color <(printf "%s\n" "$EXPECTED_RESPONSE") <(printf "%s\n" "$received_response") 2>/dev/null
then
echo -e "\e[1;32mOK"
else
echo -e "\e[1;31mFAIL: response does not match!"
jd -color <(printf "%s" "$EXPECTED_RESPONSE") <(printf "%s" "$received_response")
exit 1
fi