test(identity): add isolated browser mail fixture
This commit is contained in:
1 parent
86f562f5b6
commit
24638d46d2
20 files changed
+885
-20
No files matched your search
+10
-2
@@ -16,6 +16,7 @@ CORE_FILE := $(ROOT)/deploy/docker/docker-compose.yml
|
||||
ML_FILE := $(ROOT)/deploy/docker/docker-compose.ml.yml
|
||||
MONITORING_FILE := $(ROOT)/deploy/docker/docker-compose.monitoring.yml
|
||||
E2E_FILE := $(ROOT)/deploy/docker/docker-compose.e2e.yml
|
||||
E2E_MAIL_FILE := $(ROOT)/deploy/docker/docker-compose.e2e-mail.yml
|
||||
RELEASE_FILE := $(ROOT)/deploy/docker/docker-compose.release.yml
|
||||
ML_RELEASE_FILE := $(ROOT)/deploy/docker/docker-compose.ml.release.yml
|
||||
RELEASE_SCRIPT := $(ROOT)/deploy/scripts/release_manifest.py
|
||||
@@ -37,7 +38,7 @@ RELEASE_MANIFEST_ARG = $(if $(strip $(RELEASE_MANIFEST)),--manifest "$(RELEASE_M
|
||||
LINCODEX_RELEASE_TAG ?= $(shell PYTHONDONTWRITEBYTECODE=1 python3 "$(RELEASE_SCRIPT)" tag)
|
||||
PLAYWRIGHT_VERSION := $(shell sed -n 's/^ *"@playwright\/test": "\([^"]*\)",\{0,1\}$$/\1/p' "$(ROOT)/frontend/package.json")
|
||||
|
||||
.PHONY: help config build up down logs monitoring-config monitoring-up monitoring-down monitoring-logs ml-config ml-build ml-up ml-down ml-logs check check-workflows check-release check-perimeter perimeter-test smoke test-e2e release-build release-smoke release-e2e release-manifest release-manifest-verify release-manifest-check release-up release-down release-clean
|
||||
.PHONY: help config build up down logs monitoring-config monitoring-up monitoring-down monitoring-logs ml-config ml-build ml-up ml-down ml-logs check check-workflows check-release check-perimeter check-e2e-mail perimeter-test smoke test-e2e test-e2e-registration release-build release-smoke release-e2e release-manifest release-manifest-verify release-manifest-check release-up release-down release-clean
|
||||
|
||||
help: ## Show deployment commands
|
||||
@awk 'BEGIN {FS = ":.*## "} /^[a-zA-Z0-9_-]+:.*## / {printf "%-24s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
@@ -52,6 +53,7 @@ config: ## Render all Compose files with safe example values
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" LINCODEX_RELEASE_TAG=000000000000 IDENTITY_KEY_SECRET="$(CHECK_IDENTITY_KEY_SECRET)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" -f "$(RELEASE_FILE)" config --quiet
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" LINCODEX_RELEASE_TAG=000000000000 IDENTITY_KEY_SECRET="$(CHECK_IDENTITY_KEY_SECRET)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(ML_PROJECT)" -f "$(ML_FILE)" -f "$(ML_RELEASE_FILE)" config --quiet
|
||||
APP_PROJECT=lincodex-e2e-config APP_NETWORK=lincodex-e2e-config_default PLAYWRIGHT_VERSION="$(PLAYWRIGHT_VERSION)" E2E_UID=1000 E2E_GID=1000 E2E_SPEC_DIR="$(ROOT)/frontend/e2e" E2E_ARTIFACTS_DIR="$(ROOT)/frontend/test-results/e2e" IDENTITY_KEY_SECRET="$(CHECK_IDENTITY_KEY_SECRET)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p lincodex-e2e-config -f "$(CORE_FILE)" -f "$(E2E_FILE)" --profile e2e config --quiet
|
||||
APP_PROJECT=lincodex-e2e-mail-config APP_NETWORK=lincodex-e2e-mail-config_default PLAYWRIGHT_VERSION="$(PLAYWRIGHT_VERSION)" E2E_UID=1000 E2E_GID=1000 E2E_SPEC_DIR="$(ROOT)/frontend/e2e" E2E_ARTIFACTS_DIR="$(ROOT)/frontend/test-results/e2e" IDENTITY_KEY_SECRET="$(CHECK_IDENTITY_KEY_SECRET)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p lincodex-e2e-mail-config -f "$(CORE_FILE)" -f "$(E2E_FILE)" -f "$(E2E_MAIL_FILE)" --profile e2e config --quiet
|
||||
|
||||
build: ## Build local frontend and backend images
|
||||
APP_PROJECT="$(APP_PROJECT)" IDENTITY_KEY_SECRET="$(CHECK_IDENTITY_KEY_SECRET)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" build
|
||||
@@ -114,7 +116,7 @@ edge-render: ## Render the edge nginx config from deploy/edge/edge.env into depl
|
||||
edge-config: ## Render the edge templates and check the nginx config with nginx -t in a container
|
||||
@DOCKER="$(DOCKER)" EDGE_NGINX_IMAGE="$(EDGE_NGINX_IMAGE)" bash "$(EDGE_DIR)/scripts/check.sh" "$(EDGE_ENV)"
|
||||
|
||||
check: config check-workflows check-release check-perimeter ## Validate Compose files, CI workflow aggregates, release tooling, and the public perimeter without starting services
|
||||
check: config check-workflows check-release check-perimeter check-e2e-mail ## Validate Compose files, CI workflow aggregates, release tooling, and network boundaries without starting services
|
||||
|
||||
check-workflows: ## Check that each workflow aggregate job requires every other job
|
||||
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s "$(ROOT)/scripts" -p 'test_workflow_aggregate.py'
|
||||
@@ -125,6 +127,9 @@ check-release: ## Test the release manifest tooling, its secret scan, and the Go
|
||||
check-perimeter: ## Check published ports, the app Nginx paths, limits, and the trusted proxy chain from the files
|
||||
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s "$(ROOT)/deploy/scripts" -p 'test_perimeter.py'
|
||||
|
||||
check-e2e-mail: ## Check that the mail fixture stays inside the explicit local E2E network
|
||||
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s "$(ROOT)/deploy/scripts" -p 'test_e2e_mail.py'
|
||||
|
||||
perimeter-test: ## Start throwaway Nginx containers and test denied paths, limits, headers, and forwarded headers over HTTP
|
||||
LINCODEX_PERIMETER_LIVE=1 DOCKER="$(DOCKER)" PERIMETER_NGINX_IMAGE="$(EDGE_NGINX_IMAGE)" PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -v -s "$(ROOT)/deploy/scripts" -p 'test_perimeter.py'
|
||||
|
||||
@@ -134,6 +139,9 @@ smoke: ## Start an isolated stack and check infrastructure health routes
|
||||
test-e2e: ## Run the Playwright suite against an isolated throwaway stack
|
||||
@bash scripts/e2e.sh
|
||||
|
||||
test-e2e-registration: ## Run browser registration tests with the local authenticated mail fixture
|
||||
@bash scripts/e2e.sh --mail-fixture
|
||||
|
||||
release-build: ## Build release images with every base image pinned to its resolved digest
|
||||
@$(RELEASE) build --pull "$(RELEASE_PULL)"
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ Configuration for running the application with Docker Compose and Nginx.
|
||||
- `edge/` holds the public edge proxy: nginx and tunnel templates, certbot renewal hook, systemd drop-ins, and the scripts that render and check them. `make -C deploy edge-config` renders the nginx configuration and runs `nginx -t` in a container; see the [edge proxy runbook](../docs/en/DEPLOY.md#edge-proxy-https-and-tunnel).
|
||||
- `make -C deploy check-perimeter` checks the published ports, denied paths, limits, and the trusted peer of Nginx from the files; `make -C deploy perimeter-test` checks the same over HTTP on throwaway Nginx containers; see [Public perimeter and client address](../docs/en/DEPLOY.md#public-perimeter-and-client-address).
|
||||
|
||||
Dockerfiles live in service directories and `.env.example` at the repository root. From the root, `make -C deploy config` checks Compose and `make -C deploy up` starts the core stack after `.env` is prepared. Start monitoring separately with `make -C deploy monitoring-up`. `make -C deploy test-e2e` runs the Playwright suite against a throwaway stack under a unique project name and removes it afterwards; see [TESTING.md](../docs/en/TESTING.md#browser-e2e-suite).
|
||||
Dockerfiles live in service directories and `.env.example` at the repository root. From the root, `make -C deploy config` checks Compose and `make -C deploy up` starts the core stack after `.env` is prepared. Start monitoring separately with `make -C deploy monitoring-up`. `make -C deploy test-e2e` runs the Playwright suite against a throwaway stack under a unique project name and removes it afterwards; `make -C deploy test-e2e-registration` enables a local Resend-compatible inbox only for registration browser tests. See [TESTING.md](../docs/en/TESTING.md#browser-e2e-suite) for details.
|
||||
|
||||
`make -C deploy release-build`, `release-smoke`, and `release-manifest` build the release images with pinned base image digests, check them, and write the manifest to `deploy/release/<tag>/`, which Git ignores; `make -C deploy release-manifest-verify` compares running containers with the manifest, and `make -C deploy release-clean` removes the release images. See the [release manifest](../docs/en/DEPLOY.md#release-manifest).
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
- `edge/` содержит публичный edge proxy: шаблоны nginx и туннеля, hook продления certbot, drop-in systemd и скрипты, которые их отрисовывают и проверяют. `make -C deploy edge-config` отрисовывает конфигурацию nginx и выполняет `nginx -t` в контейнере; см. [runbook edge proxy](../docs/ru/DEPLOY.md#edge-proxy-https-и-туннель).
|
||||
- `make -C deploy check-perimeter` проверяет по файлам опубликованные порты, запрещенные пути, лимиты и доверенного пира Nginx; `make -C deploy perimeter-test` проверяет то же по HTTP на одноразовых контейнерах Nginx; см. [Публичный периметр и адрес клиента](../docs/ru/DEPLOY.md#публичный-периметр-и-адрес-клиента).
|
||||
|
||||
Dockerfile лежат в каталогах сервисов, `.env.example` - в корне репозитория. Из корня: `make -C deploy config` проверяет Compose, `make -C deploy up` запускает основной стек после подготовки `.env`. Мониторинг включается отдельно через `make -C deploy monitoring-up`. `make -C deploy test-e2e` запускает набор Playwright на одноразовом стеке с уникальным именем проекта и удаляет его после прогона; см. [TESTING.md](../docs/ru/TESTING.md#браузерный-e2e-набор).
|
||||
Dockerfile лежат в каталогах сервисов, `.env.example` - в корне репозитория. Из корня: `make -C deploy config` проверяет Compose, `make -C deploy up` запускает основной стек после подготовки `.env`. Мониторинг включается отдельно через `make -C deploy monitoring-up`. `make -C deploy test-e2e` запускает набор Playwright на одноразовом стеке с уникальным именем проекта и удаляет его после прогона; `make -C deploy test-e2e-registration` включает локальный Resend-compatible inbox только для браузерных тестов регистрации. Подробности см. в [TESTING.md](../docs/ru/TESTING.md#браузерный-e2e-набор).
|
||||
|
||||
`make -C deploy release-build`, `release-smoke` и `release-manifest` собирают образы выпуска с закрепленными digest базовых образов, проверяют их и пишут манифест в `deploy/release/<tag>/` (игнорируется Git); `make -C deploy release-manifest-verify` сверяет запущенные контейнеры с манифестом, а `make -C deploy release-clean` удаляет образы выпуска. См. [манифест выпуска](../docs/ru/DEPLOY.md#манифест-выпуска).
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# Local registration-mail overlay. It is selected only by the explicit
|
||||
# registration E2E runner, never by default or release E2E.
|
||||
services:
|
||||
backend:
|
||||
build:
|
||||
context: ../../backend
|
||||
dockerfile: Dockerfile.e2e
|
||||
environment:
|
||||
EMAIL_PROVIDER: resend
|
||||
EMAIL_ACCOUNT: e2e
|
||||
EMAIL_FROM: no-reply@example.com
|
||||
RESEND_API_KEY: re_fixture_key
|
||||
depends_on:
|
||||
mail-fixture:
|
||||
condition: service_healthy
|
||||
|
||||
playwright:
|
||||
environment:
|
||||
# The runner shares the frontend network namespace, so it can reach
|
||||
# the fixture without publishing a host port.
|
||||
E2E_MAILBOX_URL: http://mail-fixture:8025/__e2e/inbox
|
||||
E2E_MAILBOX_TOKEN: local-e2e-mailbox-token
|
||||
E2E_MAIL_FIXTURE: "1"
|
||||
|
||||
mail-fixture:
|
||||
build:
|
||||
context: ../../backend
|
||||
dockerfile: Dockerfile.mail-fixture
|
||||
expose:
|
||||
- "8025"
|
||||
read_only: true
|
||||
cap_drop: [ALL]
|
||||
security_opt: ["no-new-privileges:true"]
|
||||
healthcheck:
|
||||
test: ["CMD", "/mail-fixture", "healthcheck"]
|
||||
interval: 2s
|
||||
timeout: 3s
|
||||
retries: 15
|
||||
start_period: 2s
|
||||
stop_grace_period: 5s
|
||||
networks:
|
||||
- default
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 1m
|
||||
max-file: "2"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.25"
|
||||
memory: 128M
|
||||
|
||||
networks:
|
||||
default:
|
||||
# The fixture and browser can talk on the throwaway app network, but no
|
||||
# E2E container needs outbound access to a real provider.
|
||||
internal: true
|
||||
+99
-7
@@ -2,7 +2,8 @@
|
||||
# Runs the Playwright suite against an isolated, throwaway Compose stand.
|
||||
#
|
||||
# Each run gets a unique project name, a generated env file with random
|
||||
# secrets and EMAIL_PROVIDER=disabled, no host port, and fresh volumes. The
|
||||
# secrets, no host port, and fresh volumes. Ordinary mode uses disabled mail;
|
||||
# --mail-fixture selects the separate local Resend-compatible receiver. The
|
||||
# stand, its volumes, and its locally built images are removed on every exit.
|
||||
# Artifacts of the last run stay in frontend/test-results/e2e.
|
||||
#
|
||||
@@ -14,20 +15,49 @@
|
||||
# keep those images, and record passing evidence for the
|
||||
# release manifest. Specs must be the committed frontend/e2e.
|
||||
# Only make -C deploy release-e2e sets it.
|
||||
# Invocation:
|
||||
# e2e.sh ordinary browser suite with mail disabled
|
||||
# e2e.sh --mail-fixture local registration suite with a bounded internal
|
||||
# receiver and no outbound network
|
||||
set -euo pipefail
|
||||
|
||||
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
|
||||
source "$root/deploy/scripts/e2e_user.sh"
|
||||
compose_file="$root/deploy/docker/docker-compose.yml"
|
||||
e2e_file="$root/deploy/docker/docker-compose.e2e.yml"
|
||||
mail_file="$root/deploy/docker/docker-compose.e2e-mail.yml"
|
||||
release_file="$root/deploy/docker/docker-compose.release.yml"
|
||||
release_script="$root/deploy/scripts/release_manifest.py"
|
||||
release_tag="${LINCODEX_RELEASE_TAG:-}"
|
||||
mail_fixture=0
|
||||
if [[ "$#" -gt 1 ]]; then
|
||||
printf '%s\n' 'Usage: e2e.sh [--mail-fixture]' >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$#" -eq 1 ]]; then
|
||||
if [[ "$1" != '--mail-fixture' ]]; then
|
||||
printf '%s\n' 'Usage: e2e.sh [--mail-fixture]' >&2
|
||||
exit 2
|
||||
fi
|
||||
mail_fixture=1
|
||||
fi
|
||||
email_provider=disabled
|
||||
if ((mail_fixture)); then
|
||||
email_provider=resend
|
||||
fi
|
||||
compose_files=(-f "$compose_file" -f "$e2e_file")
|
||||
up_args=(--build)
|
||||
if [[ -n "$release_tag" ]]; then
|
||||
if ((mail_fixture)); then
|
||||
printf '%s\n' 'The local mail fixture cannot be used for release E2E.' >&2
|
||||
exit 2
|
||||
fi
|
||||
compose_files+=(-f "$release_file")
|
||||
up_args=(--no-build --pull never)
|
||||
fi
|
||||
if ((mail_fixture)); then
|
||||
compose_files+=(-f "$mail_file")
|
||||
fi
|
||||
frontend_dir="$root/frontend"
|
||||
artifacts_dir="$frontend_dir/test-results/e2e"
|
||||
spec_dir="${E2E_SPEC_DIR:-$frontend_dir/e2e}"
|
||||
@@ -66,6 +96,14 @@ fi
|
||||
for dockerfile in "$root/backend/Dockerfile" "$root/frontend/Dockerfile"; do
|
||||
[[ -f "$dockerfile" ]] || fail "Missing required build file $dockerfile."
|
||||
done
|
||||
if ((mail_fixture)); then
|
||||
for dockerfile in "$root/backend/Dockerfile.e2e" "$root/backend/Dockerfile.mail-fixture"; do
|
||||
[[ -f "$dockerfile" ]] || fail "Missing required build file $dockerfile."
|
||||
done
|
||||
fi
|
||||
playwright_user=$(e2e_playwright_user \
|
||||
"$(docker info --format '{{json .SecurityOptions}}')" "$(id -u)" "$(id -g)")
|
||||
IFS=: read -r playwright_uid playwright_gid <<<"$playwright_user"
|
||||
|
||||
# Compose runs with a cleared environment: shell variables such as
|
||||
# EMAIL_PROVIDER, RESEND_API_KEY, or COMPOSE_FILE must not leak into the
|
||||
@@ -82,7 +120,7 @@ compose() {
|
||||
APP_PROJECT="$project" APP_NETWORK="$network" APP_STORAGE_NETWORK="$storage_network" \
|
||||
APP_SUBNET=172.29.82.0/24 APP_FRONTEND_IP=172.29.82.10 \
|
||||
PLAYWRIGHT_VERSION="$declared" E2E_CI="${CI:-}" \
|
||||
E2E_UID="$(id -u)" E2E_GID="$(id -g)" \
|
||||
E2E_UID="$playwright_uid" E2E_GID="$playwright_gid" \
|
||||
E2E_SPEC_DIR="$spec_dir" E2E_ARTIFACTS_DIR="$artifacts_dir" LINCODEX_RELEASE_TAG="$release_tag" \
|
||||
docker compose \
|
||||
--env-file "$env_file" \
|
||||
@@ -132,8 +170,8 @@ trap 'exit 143' TERM
|
||||
mkdir -p "$artifacts_dir"
|
||||
rm -f "$artifacts_dir/stand.log"
|
||||
|
||||
# Throwaway configuration with synthetic secrets. The backend sends no mail,
|
||||
# and APP_PUBLIC_URL is the origin the browser uses inside the stand.
|
||||
# Throwaway configuration with synthetic secrets. The ordinary suite disables
|
||||
# mail; registration E2E sends only to the Compose-internal fixture.
|
||||
env_file=$(mktemp "${TMPDIR:-/tmp}/lincodex-e2e-env.XXXXXX")
|
||||
chmod 600 "$env_file"
|
||||
cat >"$env_file" <<EOF
|
||||
@@ -145,7 +183,7 @@ SEAWEEDFS_ACCESS_KEY=e2e-$suffix
|
||||
SEAWEEDFS_SECRET_KEY=$(random_secret)
|
||||
SEAWEEDFS_BUCKET=lincodex
|
||||
KAFKA_CLUSTER_ID=$(head -c 16 /dev/urandom | base64 | tr '+/' '-_' | tr -d '=\n')
|
||||
EMAIL_PROVIDER=disabled
|
||||
EMAIL_PROVIDER=$email_provider
|
||||
EMAIL_FROM=no-reply@example.com
|
||||
EMAIL_TIMEOUT=10s
|
||||
APP_PUBLIC_URL=http://localhost:8080
|
||||
@@ -176,12 +214,66 @@ done
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ((mail_fixture)); then
|
||||
# Exercise the real Compose DNS path and inbox before browser tests. This
|
||||
# sends only one synthetic message and verifies idempotent replay.
|
||||
if ! compose run --rm --no-deps -T playwright node -e '
|
||||
const fail = () => { console.error("Local mail fixture transport check failed."); process.exit(1); };
|
||||
try {
|
||||
const recipient = "fixture-smoke@example.invalid";
|
||||
const body = JSON.stringify({
|
||||
from: "no-reply@example.com",
|
||||
to: [recipient],
|
||||
subject: "Local fixture check",
|
||||
text: "Synthetic message for the local E2E fixture.",
|
||||
});
|
||||
const headers = {
|
||||
Authorization: "Bearer re_fixture_key",
|
||||
"Content-Type": "application/json",
|
||||
"Idempotency-Key": "registration-fixture-smoke",
|
||||
};
|
||||
const send = () => fetch("http://mail-fixture:8025/emails", {
|
||||
method: "POST", headers, body,
|
||||
});
|
||||
const firstResponse = await send();
|
||||
if (!firstResponse.ok) fail();
|
||||
const first = await firstResponse.json();
|
||||
if (typeof first.id !== "string" || first.id.length === 0) fail();
|
||||
const replayResponse = await send();
|
||||
if (!replayResponse.ok) fail();
|
||||
const replay = await replayResponse.json();
|
||||
if (replay.id !== first.id) fail();
|
||||
const inboxURL = new URL(process.env.E2E_MAILBOX_URL);
|
||||
inboxURL.searchParams.set("to", recipient);
|
||||
const inboxResponse = await fetch(inboxURL, {
|
||||
headers: { Authorization: `Bearer ${process.env.E2E_MAILBOX_TOKEN}` },
|
||||
});
|
||||
if (!inboxResponse.ok) fail();
|
||||
const inbox = await inboxResponse.json();
|
||||
if (!Array.isArray(inbox.messages) || inbox.messages.length !== 1) fail();
|
||||
if (inbox.messages[0].id !== first.id || inbox.messages[0].to[0] !== recipient) fail();
|
||||
console.log("Local mail fixture accepted, deduplicated, and returned one synthetic inbox message.");
|
||||
} catch {
|
||||
fail();
|
||||
}
|
||||
'; then
|
||||
printf '%s\n' 'The local mail fixture transport check failed.' >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
playwright_command=(node node_modules/@playwright/test/cli.js test)
|
||||
if ((mail_fixture)); then
|
||||
# Confirmation links contain one-time tokens. Do not save traces with inbox
|
||||
# responses or token-bearing navigation URLs.
|
||||
playwright_command+=(--trace off)
|
||||
fi
|
||||
set +e
|
||||
compose run --rm --no-deps -T playwright
|
||||
compose run --rm --no-deps -T playwright "${playwright_command[@]}"
|
||||
status=$?
|
||||
set -e
|
||||
if ((status != 0)); then
|
||||
printf 'Playwright failed with exit code %s; traces and screenshots are in %s/results.\n' \
|
||||
printf 'Playwright failed with exit code %s; browser artifacts are in %s/results.\n' \
|
||||
"$status" "$artifacts_dir" >&2
|
||||
elif [[ -n "$release_tag" ]]; then
|
||||
# The suite passed; bind the result to the image IDs that ran.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Rootless Docker maps container root to the owner of a host bind mount. A
|
||||
# non-root container UID instead maps to a subordinate host UID and cannot
|
||||
# write the owner's artifact directory. In rootful Docker, match the host UID.
|
||||
e2e_playwright_user() {
|
||||
local security_options=$1
|
||||
local host_uid=$2
|
||||
local host_gid=$3
|
||||
|
||||
if [[ "$security_options" == *'"name=rootless"'* ]]; then
|
||||
printf '0:0\n'
|
||||
return
|
||||
fi
|
||||
printf '%s:%s\n' "$host_uid" "$host_gid"
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
"""Boundary checks for the Compose-only registration mail fixture."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
DEPLOY = ROOT / "deploy"
|
||||
DOCKER = os.environ.get("DOCKER", "docker")
|
||||
FIXTURE_TOKEN = "local-e2e-mailbox-token"
|
||||
|
||||
|
||||
class E2EUserSelectionTest(unittest.TestCase):
|
||||
def test_playwright_user_matches_docker_mode(self):
|
||||
helper = DEPLOY / "scripts" / "e2e_user.sh"
|
||||
cases = (
|
||||
('["name=seccomp", "name=rootless"]', "1000", "100", "0:0"),
|
||||
('["name=seccomp"]', "1000", "100", "1000:100"),
|
||||
)
|
||||
for security_options, uid, gid, expected in cases:
|
||||
with self.subTest(security_options=security_options):
|
||||
result = subprocess.run(
|
||||
[
|
||||
"bash",
|
||||
"-c",
|
||||
'source "$1"; e2e_playwright_user "$2" "$3" "$4"',
|
||||
"e2e-user-test",
|
||||
str(helper),
|
||||
security_options,
|
||||
uid,
|
||||
gid,
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(result.stdout.strip(), expected)
|
||||
|
||||
|
||||
def render_compose(file_names, project, extra_env=None):
|
||||
environment = {
|
||||
"PATH": os.environ.get("PATH", ""),
|
||||
"HOME": os.environ.get("HOME", ""),
|
||||
"APP_PROJECT": project,
|
||||
"APP_NETWORK": f"{project}_default",
|
||||
"APP_STORAGE_NETWORK": f"{project}_storage",
|
||||
"APP_SUBNET": "172.29.82.0/24",
|
||||
"APP_FRONTEND_IP": "172.29.82.10",
|
||||
"PLAYWRIGHT_VERSION": "1.0.0",
|
||||
"E2E_UID": "1000",
|
||||
"E2E_GID": "1000",
|
||||
"E2E_SPEC_DIR": str(ROOT / "frontend" / "e2e"),
|
||||
"E2E_ARTIFACTS_DIR": str(ROOT / "frontend" / "test-results" / "e2e"),
|
||||
"IDENTITY_KEY_SECRET": "render-only-identity-key-secret",
|
||||
}
|
||||
environment.update(extra_env or {})
|
||||
command = [DOCKER, "compose", "--env-file", str(ROOT / ".env.example"), "-p", project]
|
||||
for file_name in file_names:
|
||||
command.extend(["-f", str(DEPLOY / "docker" / file_name)])
|
||||
result = subprocess.run(
|
||||
command + ["--profile", "e2e", "config", "--format", "json"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env=environment,
|
||||
check=False,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise AssertionError(f"docker compose config failed: {result.stderr}")
|
||||
return json.loads(result.stdout)
|
||||
|
||||
|
||||
class ComposeMailFixtureTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if shutil.which(DOCKER) is None:
|
||||
raise unittest.SkipTest("docker CLI is not available")
|
||||
cls.ordinary = render_compose(
|
||||
["docker-compose.yml", "docker-compose.e2e.yml"], "e2e-mail-ordinary"
|
||||
)
|
||||
cls.fixture = render_compose(
|
||||
["docker-compose.yml", "docker-compose.e2e.yml", "docker-compose.e2e-mail.yml"],
|
||||
"e2e-mail-registration",
|
||||
)
|
||||
cls.release = render_compose(
|
||||
["docker-compose.yml", "docker-compose.e2e.yml", "docker-compose.release.yml"],
|
||||
"e2e-mail-release",
|
||||
{"LINCODEX_RELEASE_TAG": "000000000000"},
|
||||
)
|
||||
|
||||
def test_ordinary_and_release_e2e_keep_the_production_build_and_disabled_mail(self):
|
||||
for rendered in (self.ordinary, self.release):
|
||||
with self.subTest(project=rendered["name"]):
|
||||
self.assertNotIn("mail-fixture", rendered["services"])
|
||||
backend = rendered["services"]["backend"]
|
||||
self.assertEqual(backend["build"]["dockerfile"], "Dockerfile")
|
||||
self.assertEqual(backend["environment"]["EMAIL_PROVIDER"], "disabled")
|
||||
self.assertNotIn("RESEND_ENDPOINT", backend["environment"])
|
||||
self.assertNotIn(
|
||||
"E2E_MAIL_FIXTURE",
|
||||
rendered["services"]["playwright"].get("environment", {}),
|
||||
)
|
||||
|
||||
def test_fixture_uses_an_e2e_build_and_fixed_synthetic_credentials(self):
|
||||
services = self.fixture["services"]
|
||||
backend = services["backend"]
|
||||
self.assertEqual(backend["build"]["dockerfile"], "Dockerfile.e2e")
|
||||
self.assertEqual(backend["environment"]["EMAIL_PROVIDER"], "resend")
|
||||
self.assertEqual(backend["environment"]["RESEND_API_KEY"], "re_fixture_key")
|
||||
self.assertNotIn("RESEND_ENDPOINT", backend["environment"])
|
||||
self.assertEqual(
|
||||
services["playwright"]["environment"]["E2E_MAILBOX_URL"],
|
||||
"http://mail-fixture:8025/__e2e/inbox",
|
||||
)
|
||||
self.assertEqual(services["playwright"]["environment"]["E2E_MAILBOX_TOKEN"], FIXTURE_TOKEN)
|
||||
self.assertEqual(services["playwright"]["environment"]["E2E_MAIL_FIXTURE"], "1")
|
||||
self.assertNotIn("E2E_MAIL_FIXTURE", services["frontend"].get("environment", {}))
|
||||
|
||||
def test_fixture_has_no_host_port_storage_network_or_outbound_route(self):
|
||||
services = self.fixture["services"]
|
||||
fixture = services["mail-fixture"]
|
||||
self.assertEqual(fixture["build"]["dockerfile"], "Dockerfile.mail-fixture")
|
||||
self.assertFalse(fixture.get("ports"))
|
||||
self.assertFalse(services["frontend"].get("ports"))
|
||||
self.assertFalse(services["backend"].get("ports"))
|
||||
self.assertEqual(set(fixture["networks"]), {"default"})
|
||||
self.assertTrue(self.fixture["networks"]["default"]["internal"])
|
||||
self.assertNotIn("storage", fixture["networks"])
|
||||
self.assertTrue(fixture["read_only"])
|
||||
self.assertEqual(fixture["cap_drop"], ["ALL"])
|
||||
self.assertIn("no-new-privileges:true", fixture["security_opt"])
|
||||
self.assertEqual(fixture["deploy"]["resources"]["limits"]["memory"], str(128 * 1024 * 1024))
|
||||
|
||||
|
||||
class E2ERunnerModeTest(unittest.TestCase):
|
||||
def test_release_tag_cannot_enable_the_local_mail_fixture(self):
|
||||
environment = {"PATH": os.environ.get("PATH", ""), "LINCODEX_RELEASE_TAG": "000000000000"}
|
||||
result = subprocess.run(
|
||||
["bash", str(DEPLOY / "scripts" / "e2e.sh"), "--mail-fixture"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env=environment,
|
||||
check=False,
|
||||
)
|
||||
self.assertEqual(result.returncode, 2)
|
||||
self.assertIn("cannot be used for release E2E", result.stderr)
|
||||
self.assertNotIn("mail-fixture", result.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user