Repository navigation
Expand file tree
/
Copy pathsmoke-test-release.sh
More file actions
executable file
·126 lines (102 loc) · 4.48 KB
/
Copy pathsmoke-test-release.sh
File metadata and controls
executable file
·126 lines (102 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env sh
set -eu
if [ "$#" -ne 1 ]; then
printf '%s\n' "Usage: $0 /path/to/basicrum-real-user-monitoring.zip" >&2
exit 1
fi
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
REPOSITORY_ROOT=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
COMPOSE_FILE="$REPOSITORY_ROOT/docker/release-smoke.yml"
ARCHIVE_INPUT=$1
if [ ! -f "$ARCHIVE_INPUT" ]; then
printf '%s\n' "Release archive does not exist: $ARCHIVE_INPUT" >&2
exit 1
fi
for required_command in curl docker; do
if ! command -v "$required_command" >/dev/null 2>&1; then
printf '%s\n' "Required command is not installed: $required_command" >&2
exit 1
fi
done
ARCHIVE_DIR=$(CDPATH= cd -- "$(dirname -- "$ARCHIVE_INPUT")" && pwd)
export BASICRUM_RELEASE_ZIP="$ARCHIVE_DIR/$(basename -- "$ARCHIVE_INPUT")"
COMPOSE_PROJECT_NAME="basicrum_release_smoke_$$"
export COMPOSE_PROJECT_NAME
TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/basicrum-smoke.XXXXXX")
FRONTEND_RESPONSE="$TEMP_DIR/frontend.html"
ADMIN_RESPONSE="$TEMP_DIR/admin.html"
COOKIE_JAR="$TEMP_DIR/cookies.txt"
compose() {
docker compose -f "$COMPOSE_FILE" "$@"
}
cleanup() {
compose down --volumes --remove-orphans >/dev/null 2>&1 || true
rm -rf "$TEMP_DIR"
}
trap cleanup EXIT HUP INT TERM
assert_clean_response() {
if grep -Eiq '(Fatal error|Uncaught [A-Za-z]+Error|Warning: .+ on line)' "$1"; then
printf '%s\n' "PHP warning or fatal error found in $2 response." >&2
exit 1
fi
}
sh "$SCRIPT_DIR/verify-release.sh" "$BASICRUM_RELEASE_ZIP"
compose up -d db wordpress
ATTEMPT=0
while ! compose exec -T wordpress test -f /var/www/html/wp-includes/version.php; do
ATTEMPT=$((ATTEMPT + 1))
if [ "$ATTEMPT" -ge 30 ]; then
printf '%s\n' 'WordPress files were not initialized in time.' >&2
exit 1
fi
sleep 2
done
PUBLISHED_ADDRESS=$(compose port wordpress 80)
PUBLISHED_PORT=${PUBLISHED_ADDRESS##*:}
SITE_URL="http://127.0.0.1:$PUBLISHED_PORT"
compose run --rm wpcli wp core install \
--url="$SITE_URL" \
--title='Basicrum Release Smoke Test' \
--admin_user=admin \
--admin_password=basicrum-smoke-password \
--admin_email=admin@example.test \
--skip-email
compose run --rm wpcli wp plugin install /artifacts/basicrum-real-user-monitoring.zip --activate
compose run --rm wpcli wp option update basicrum_settings '{"enabled":"1","development_mode":"0","beacon_url":"https://example.test/beacon","brum_site_id":"550e8400-e29b-41d4-a716-446655440000","track_admins":"0","consent_enabled":"0","strip_query_string":"0","wait_after_onload":"0","delay_ms":0,"script_position":"footer","use_unminified_loaders":"0"}' --format=json
curl -fsS "$SITE_URL/" -o "$FRONTEND_RESPONSE"
assert_clean_response "$FRONTEND_RESPONSE" frontend
if ! grep -Fq 'basicrum-loader-js' "$FRONTEND_RESPONSE"; then
printf '%s\n' 'The enabled plugin did not render the Basicrum loader on the frontend.' >&2
exit 1
fi
compose run --rm wpcli wp option update basicrum_settings '{"enabled":"1","development_mode":"0","beacon_url":"https://example.test/beacon","brum_site_id":"550e8400-e29b-41d4-a716-446655440000","track_admins":"0","consent_enabled":"1","strip_query_string":"0","wait_after_onload":"0","delay_ms":0,"script_position":"footer","use_unminified_loaders":"0"}' --format=json
curl -fsS "$SITE_URL/" -o "$FRONTEND_RESPONSE"
assert_clean_response "$FRONTEND_RESPONSE" 'consent-controlled frontend'
if grep -Fq 'basicrum-consent-api-js' "$FRONTEND_RESPONSE"; then
printf '%s\n' 'Consent-controlled loading unexpectedly rendered the retired consent API.' >&2
exit 1
fi
if ! grep -Fq 'consent-boomerang-loader-v1-15.min.js' "$FRONTEND_RESPONSE"; then
printf '%s\n' 'Consent-controlled loading did not render the consent loader.' >&2
exit 1
fi
curl -fsS -c "$COOKIE_JAR" "$SITE_URL/wp-login.php" >/dev/null
curl -fsS -L \
-b "$COOKIE_JAR" \
-c "$COOKIE_JAR" \
--data-urlencode 'log=admin' \
--data-urlencode 'pwd=basicrum-smoke-password' \
--data-urlencode "redirect_to=$SITE_URL/wp-admin/admin.php?page=basicrum" \
--data-urlencode 'testcookie=1' \
"$SITE_URL/wp-login.php" >/dev/null
curl -fsS -b "$COOKIE_JAR" "$SITE_URL/wp-admin/admin.php?page=basicrum" -o "$ADMIN_RESPONSE"
assert_clean_response "$ADMIN_RESPONSE" admin
if ! grep -Fq 'Basicrum Settings' "$ADMIN_RESPONSE"; then
printf '%s\n' 'The Basicrum administration page did not render after activation.' >&2
exit 1
fi
if compose logs wordpress | grep -Eiq '(PHP Fatal error|Uncaught [A-Za-z]+Error|PHP Warning:)'; then
printf '%s\n' 'The WordPress container logged a PHP warning or fatal error.' >&2
exit 1
fi
printf '%s\n' "Release smoke test passed: $BASICRUM_RELEASE_ZIP"