Support external email in test deployments
Some checks are pending
Quality / full-local-gates (push) Waiting to run

This commit is contained in:
SimpleTest 2026-07-21 23:17:28 +03:00
parent b218bb9cee
commit 88a6373693
4 changed files with 81 additions and 11 deletions

View File

@ -37,6 +37,8 @@ deployment_environment=$(read_env_value DEPLOYMENT_ENV 2>/dev/null || printf dev
database_mode=$(read_env_value DATABASE_MODE 2>/dev/null || printf container)
app_topology=$(read_env_value APP_TOPOLOGY 2>/dev/null || printf split)
public_edge_enabled=$(read_env_value PUBLIC_EDGE_ENABLED 2>/dev/null || printf false)
email_delivery_provider=$(read_env_value EMAIL_DELIVERY_PROVIDER 2>/dev/null || printf smtp)
smtp_relay=$(read_env_value SMTP_RELAY 2>/dev/null || true)
project=$(read_env_value COMPOSE_PROJECT_NAME 2>/dev/null || printf who_need_help)
[[ "$deployment_target" == compose ]] || {
@ -101,7 +103,8 @@ if [[ "$public_edge_enabled" == true ]]; then
compose+=(--file "$ROOT/compose.public-app.yaml")
fi
if [[ "$deployment_environment" == production ]]; then
if [[ "$deployment_environment" == production ||
"$email_delivery_provider" != smtp || "$smtp_relay" != mailpit ]]; then
compose+=(--file "$ROOT/compose.production.yaml")
fi

View File

@ -187,6 +187,31 @@ PRODUCTION_CODEX_SESSION_ID=00000000-0000-0000-0000-000000000001 \
./scripts/validate-production-env.sh "$api_production_env" help.test >/dev/null
grep -Fx 'EMAIL_DELIVERY_PROVIDER=unisender_go' "$api_production_env" >/dev/null
grep -Fx 'UNISENDER_GO_SKIP_UNSUBSCRIBE=false' "$api_production_env" >/dev/null
api_test_env="$scan_dir/.env.test.unisender-go"
cp "$test_env" "$api_test_env"
chmod 600 "$api_test_env"
sed -i \
-e 's/^EMAIL_DELIVERY_PROVIDER=.*/EMAIL_DELIVERY_PROVIDER=unisender_go/' \
-e 's/^UNISENDER_GO_API_KEY=.*/UNISENDER_GO_API_KEY=quality-test-unisender-go-api-key/' \
"$api_test_env"
./scripts/validate-test-env.sh "$api_test_env" test.help.test >/dev/null
if ./scripts/compose.sh "$api_test_env" config --services | grep -Fx mailpit >/dev/null; then
echo "External test email configuration unexpectedly starts Mailpit." >&2
exit 1
fi
cp "$api_test_env" "$test_checkout/.env"
cp "$api_production_env" "$production_checkout/.env"
chmod 600 "$test_checkout/.env" "$production_checkout/.env"
./scripts/validate-deployment-isolation.sh \
"$test_checkout" "$production_checkout" >/dev/null
sed -i \
's/^UNISENDER_GO_API_KEY=.*/UNISENDER_GO_API_KEY=quality-unisender-go-api-key/' \
"$test_checkout/.env"
if ./scripts/validate-deployment-isolation.sh \
"$test_checkout" "$production_checkout" >/dev/null 2>&1; then
echo "Deployment isolation accepted a shared UniSender Go API key." >&2
exit 1
fi
api_override_env="$scan_dir/.env.production.unisender-go-skip-unsubscribe"
PRODUCTION_EMAIL_DELIVERY_PROVIDER=unisender_go \
PRODUCTION_UNISENDER_GO_API_KEY=quality-unisender-go-api-key \

View File

@ -94,11 +94,21 @@ if [[ -n "$test_google_id" || -n "$production_google_id" ]]; then
}
fi
[[ "$(read_env "$test_env" EMAIL_DELIVERY_PROVIDER)" == smtp &&
"$(read_env "$test_env" SMTP_RELAY)" == mailpit ]] || {
echo "Test email must be isolated in Mailpit." >&2
exit 1
}
test_email_provider=$(read_env "$test_env" EMAIL_DELIVERY_PROVIDER)
production_email_provider=$(read_env "$production_env" EMAIL_DELIVERY_PROVIDER)
if [[ "$test_email_provider" == unisender_go &&
"$production_email_provider" == unisender_go ]]; then
require_different UNISENDER_GO_API_KEY
fi
if [[ "$test_email_provider" == smtp &&
"$(read_env "$test_env" SMTP_RELAY)" != mailpit &&
"$production_email_provider" == smtp &&
"$(read_env "$test_env" SMTP_RELAY)" == "$(read_env "$production_env" SMTP_RELAY)" ]]; then
require_different SMTP_USERNAME
require_different SMTP_PASSWORD
fi
[[ "$(read_env "$production_env" EMAIL_DELIVERY_PROVIDER)" != smtp ||
"$(read_env "$production_env" SMTP_RELAY)" != mailpit ]] || {
echo "Production email must not target test Mailpit." >&2

View File

@ -77,11 +77,43 @@ require_value() {
echo "The test DATABASE_URL must target its own Compose database." >&2
exit 1
}
[[ "$(require_value EMAIL_DELIVERY_PROVIDER)" == smtp &&
"$(require_value SMTP_RELAY)" == mailpit ]] || {
echo "The test checkout must deliver email only to its Mailpit service." >&2
exit 1
}
email_delivery_provider=$(require_value EMAIL_DELIVERY_PROVIDER)
case "$email_delivery_provider" in
smtp)
smtp_relay=$(require_value SMTP_RELAY)
if [[ "$smtp_relay" != mailpit ]]; then
require_value SMTP_PORT >/dev/null
smtp_auth=$(require_value SMTP_AUTH)
smtp_username=$(read_value SMTP_USERNAME 2>/dev/null || true)
smtp_password=$(read_value SMTP_PASSWORD 2>/dev/null || true)
[[ "$smtp_auth" != always || (-n "$smtp_username" && -n "$smtp_password") ]] || {
echo "External test SMTP requires SMTP_USERNAME and SMTP_PASSWORD when SMTP_AUTH=always." >&2
exit 1
}
[[ (-z "$smtp_username" && -z "$smtp_password") ||
(-n "$smtp_username" && -n "$smtp_password") ]] || {
echo "SMTP_USERNAME and SMTP_PASSWORD must be configured together." >&2
exit 1
}
fi
;;
unisender_go)
require_value UNISENDER_GO_API_KEY >/dev/null
unisender_base_url=$(require_value UNISENDER_GO_BASE_URL)
[[ "$unisender_base_url" == https://* ]] || {
echo "UNISENDER_GO_BASE_URL must use HTTPS." >&2
exit 1
}
;;
*)
echo "EMAIL_DELIVERY_PROVIDER must be smtp or unisender_go." >&2
exit 1
;;
esac
require_value EMAIL_FROM_ADDRESS >/dev/null
[[ "$(require_value PHX_HOST)" == "$expected_domain" &&
"$(require_value WNH_BASE_URL)" == "https://$expected_domain" ]] || {
echo "The test public origin does not match EXPECTED_DOMAIN." >&2