From 7c992697af16365a800b9c64c76d17ffceead8fa Mon Sep 17 00:00:00 2001 From: Hubert Deng Date: Thu, 11 Apr 2024 13:12:19 -0700 Subject: [PATCH] Use python for e2e tests (#2953) * bump e2e action commit sha --- .github/workflows/test.yml | 2 +- _integration-test/run.sh | 152 ------------------------------------- test.sh | 12 --- 3 files changed, 1 insertion(+), 165 deletions(-) delete mode 100755 _integration-test/run.sh delete mode 100755 test.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2b8f70..5dc896f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: sudo chmod +x "/usr/local/lib/docker/cli-plugins/docker-compose" - name: End to end tests - uses: getsentry/action-self-hosted-e2e-tests@03010bd2963edc1f47b6e5e03167a4bc1433ea36 + uses: getsentry/action-self-hosted-e2e-tests@main with: project_name: self-hosted diff --git a/_integration-test/run.sh b/_integration-test/run.sh deleted file mode 100755 index 482665d..0000000 --- a/_integration-test/run.sh +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env bash -set -ex - -echo "${_group}Setting up variables and helpers ..." -export SENTRY_TEST_HOST="${SENTRY_TEST_HOST:-http://localhost:9000}" -TEST_USER='test@example.com' -TEST_PASS='test123TEST' -COOKIE_FILE=$(mktemp) - -trap_with_arg cleanup ERR INT TERM EXIT -echo "${_endgroup}" - -echo "${_group}Starting Sentry for tests ..." -# Disable beacon for e2e tests -echo 'SENTRY_BEACON=False' >>$SENTRY_CONFIG_PY -$dc up -d -timeout 90 bash -c 'until $(curl -Isf -o /dev/null $SENTRY_TEST_HOST); do printf '.'; sleep 0.5; done' -# DC exec here is faster, tests run on the slower side and using exec would provide a boost -echo y | $dc exec web sentry createuser --force-update --superuser --email $TEST_USER --password $TEST_PASS -printf "Waiting for Sentry to be up" -echo "" -echo "${_endgroup}" - -echo "${_group}Running tests ..." -get_csrf_token() { awk '$6 == "sc" { print $7 }' $COOKIE_FILE; } -sentry_api_request() { curl -s -H 'Accept: application/json; charset=utf-8' -H "Referer: $SENTRY_TEST_HOST" -H 'Content-Type: application/json' -H "X-CSRFToken: $(get_csrf_token)" -b "$COOKIE_FILE" -c "$COOKIE_FILE" "$SENTRY_TEST_HOST/api/0/$1" ${@:2}; } - -login() { - INITIAL_AUTH_REDIRECT=$(curl -sL -o /dev/null $SENTRY_TEST_HOST -w %{url_effective}) - if [ "$INITIAL_AUTH_REDIRECT" != "$SENTRY_TEST_HOST/auth/login/sentry/" ]; then - echo "Initial /auth/login/ redirect failed, exiting..." - echo "$INITIAL_AUTH_REDIRECT" - exit 1 - fi - - CSRF_TOKEN_FOR_LOGIN=$(curl $SENTRY_TEST_HOST -sL -c "$COOKIE_FILE" | awk -F "['\"]" ' - /csrfmiddlewaretoken/ { - print $4 "=" $6; - exit; - }') - - curl -sL --data-urlencode 'op=login' --data-urlencode "username=$TEST_USER" --data-urlencode "password=$TEST_PASS" --data-urlencode "$CSRF_TOKEN_FOR_LOGIN" "$SENTRY_TEST_HOST/auth/login/sentry/" -H "Referer: $SENTRY_TEST_HOST/auth/login/sentry/" -b "$COOKIE_FILE" -c "$COOKIE_FILE" -} - -LOGIN_RESPONSE=$(login) -declare -a LOGIN_TEST_STRINGS=( - '"isAuthenticated":true' - '"username":"test@example.com"' - '"isSuperuser":true' -) -for i in "${LOGIN_TEST_STRINGS[@]}"; do - echo "Testing '$i'..." - echo "$LOGIN_RESPONSE" | grep "${i}[,}]" >&/dev/null - echo "Pass." -done -echo "${_endgroup}" - -echo "${_group}Running moar tests !!!" -# Set up initial/required settings (InstallWizard request) -export -f sentry_api_request get_csrf_token -sentry_api_request "internal/options/?query=is:required" -X PUT --data '{"mail.use-tls":false,"mail.username":"","mail.port":25,"system.admin-email":"ben@byk.im","mail.password":"","system.url-prefix":"'"$SENTRY_TEST_HOST"'","auth.allow-registration":false,"beacon.anonymous":true}' >/dev/null - -# Hacky way to get around test flakiness for now -sleep 60 -# We ignore the protocol and the host as we already know those -SENTRY_DSN=$(sentry_api_request "projects/sentry/internal/keys/" | awk 'BEGIN { RS=",|:{\n"; FS="\""; } $2 == "public" && $4 ~ "^http" { print $4; exit; }') -DSN_PIECES=($(echo $SENTRY_DSN | sed -ne 's|^https\{0,1\}://\([0-9a-z]\{1,\}\)@[^/]\{1,\}/\([0-9]\{1,\}\)$|\1 \2|p' | tr ' ' '\n')) -SENTRY_KEY=${DSN_PIECES[0]} -PROJECT_ID=${DSN_PIECES[1]} - -TEST_EVENT_ID=$( - export LC_ALL=C - head /dev/urandom | tr -dc "a-f0-9" | head -c 32 -) -# Thanks @untitaker - https://forum.sentry.io/t/how-can-i-post-with-curl-a-sentry-event-which-authentication-credentials/4759/2?u=byk -echo "Creating test event..." -curl -sf --data '{"event_id": "'"$TEST_EVENT_ID"'","level":"error","message":"a failure","extra":{"object":"42"}}' -H 'Content-Type: application/json' -H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=$SENTRY_KEY, sentry_client=test-bash/0.1" "$SENTRY_TEST_HOST/api/$PROJECT_ID/store/" -o /dev/null - -EVENT_PATH="projects/sentry/internal/events/$TEST_EVENT_ID/" -export SENTRY_TEST_HOST COOKIE_FILE EVENT_PATH -printf "Getting the test event back" -timeout 60 bash -c 'until $(sentry_api_request "$EVENT_PATH" -Isf -X GET -o /dev/null); do printf '.'; sleep 0.5; done' -echo " got it!" - -EVENT_RESPONSE=$(sentry_api_request "$EVENT_PATH") -declare -a EVENT_TEST_STRINGS=( - '"eventID":"'"$TEST_EVENT_ID"'"' - '"message":"a failure"' - '"title":"a failure"' - '"object":"42"' -) -for i in "${EVENT_TEST_STRINGS[@]}"; do - echo "Testing '$i'..." - echo "$EVENT_RESPONSE" | grep "${i}[,}]" >&/dev/null - echo "Pass." -done -echo "${_endgroup}" - -echo "${_group}Ensure cleanup crons are working ..." -$dc ps -a | tee debug.log | grep -E -e '\-cleanup\s+running\s+' -e '\-cleanup[_-].+\s+Up\s+' -# to debug https://github.com/getsentry/self-hosted/issues/1171 -echo '------------------------------------------' -cat debug.log -echo '------------------------------------------' -echo "${_endgroup}" - -echo "${_group}Test custom CAs work ..." -source _integration-test/custom-ca-roots/setup.sh -$dcr --no-deps web python3 /etc/sentry/test-custom-ca-roots.py -source _integration-test/custom-ca-roots/teardown.sh -echo "${_endgroup}" - -echo "${_group}Test that profiling work ..." -echo "Sending a test profile..." -PROFILE_FIXTURE_PATH="$(git rev-parse --show-toplevel)/_integration-test/fixtures/envelope-with-profile" -curl -sf --data-binary @$PROFILE_FIXTURE_PATH -H 'Content-Type: application/x-sentry-envelope' -H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=$SENTRY_KEY, sentry_client=test-bash/0.1" "$SENTRY_TEST_HOST/api/$PROJECT_ID/envelope/" - -printf "Getting the test profile back" -PROFILE_ID="$(jq -r -n --slurpfile profile $PROFILE_FIXTURE_PATH '$profile[4].event_id')" -PROFILE_PATH="projects/sentry/sentry/profiling/raw_profiles/$PROFILE_ID/" -timeout 60 bash -c 'until sentry_api_request "$PROFILE_PATH" -X GET -o /dev/null; do printf '.'; sleep 0.5; done' -echo " got it!" -echo "${_endgroup}" - -echo "${_group}Test we can extract spans from an event..." -echo "Sending a test span..." -SPAN_FIXTURE_PATH="$(git rev-parse --show-toplevel)/_integration-test/fixtures/envelope-with-transaction" -curl -sf --data-binary @$PROFILE_FIXTURE_PATH -H 'Content-Type: application/x-sentry-envelope' -H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=$SENTRY_KEY, sentry_client=test-bash/0.1" "$SENTRY_TEST_HOST/api/$PROJECT_ID/envelope/" - -printf "Getting a span back" -TRACE_ID="$(jq -r -n --slurpfile span $SPAN_FIXTURE_PATH '$span[2].contexts.trace.trace_id')" -SPAN_PATH="organizations/sentry/events/" -SPAN_QUERY_PARAMS="-G --data-urlencode dataset=spansIndexed --data-urlencode field=id --data-urlencode project=1 --data-urlencode query=trace:$TRACE_ID --data-urlencode statsPeriod=1h" -sleep 10 -sentry_api_request $SPAN_PATH -X GET $SPAN_QUERY_PARAMS | jq .data[] -e -echo " got it!" -echo "${_endgroup}" - -# Table formatting based on https://stackoverflow.com/a/39144364 -COMPOSE_PS_OUTPUT=$(docker compose ps --format json | jq -r \ - '.[] | - # we only care about running services. geoipupdate and fixture-custom-ca-roots always exits, so we ignore it - select(.State != "running" and .Service != "geoipupdate" and .Service != "fixture-custom-ca-roots") | - # Filter to only show the service name and state - with_entries(select(.key | in({"Service":1, "State":1}))) - ') - -if [[ "$COMPOSE_PS_OUTPUT" ]]; then - echo "Services failed, oh no!" - echo "$COMPOSE_PS_OUTPUT" | jq -rs '["Service","State"], ["-------","-----"], (.[]|[.Service, .State]) | @tsv' - exit 1 -fi diff --git a/test.sh b/test.sh deleted file mode 100755 index c7fbd3a..0000000 --- a/test.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -e - -export MINIMIZE_DOWNTIME=0 -export REPORT_SELF_HOSTED_ISSUES=1 - -# This file runs in https://github.com/getsentry/sentry/blob/fe4795f5eae9e0d7c33e0ecb736c9d1369535eca/docker/cloudbuild.yaml#L59 -source install/_lib.sh -source install/detect-platform.sh -source install/dc-detect-version.sh -source install/error-handling.sh -source _integration-test/run.sh