mirror of
https://github.com/truespar/sentio.git
synced 2026-11-17 16:17:37 +00:00
These were verified by hand while chasing the spam-scoring bug. Spot checks rot, so they are assertions now: 19 checks, up from 13. - GTUBE must score above 10. rspamd answered every request while scoring every message -0.1, and nothing looked wrong; this is the assertion that catches that class of fault. - EICAR must be rejected in-band, which is the one scanner verdict Sentio enforces itself. - The webhook signature is recomputed over the raw delivered bytes. A re-serialised body would verify even if the scheme were wrong, so the check captures the request with its own listener. - STARTTLS then AUTH, including that AUTH is absent before the upgrade - credentials must never be solicited in cleartext. Skipped, not failed, when no certificate is mounted; the skip path was tested by removing the cert. - The rate limiter and DNSBL cache must be writing to the KV store. Also adds FRESHCLAM_CHECKS=24 so signatures refresh hourly rather than daily; the image default of 1 can leave the scanner a day behind.
103 lines
4.4 KiB
Bash
103 lines
4.4 KiB
Bash
# Shared configuration and helpers for the Sentio e2e scripts.
|
|
# Sourced, not executed.
|
|
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
|
|
# ── Fixtures ────────────────────────────────────────────────────────────────
|
|
# Both domains sit under .test, which RFC 6761 reserves as never globally
|
|
# resolvable. Combined with delivery.relay this makes it impossible for a
|
|
# misconfigured run to put mail on the public internet.
|
|
SEND_DOMAIN="${SEND_DOMAIN:-sender.test}"
|
|
RECV_DOMAIN="${RECV_DOMAIN:-inbound.test}"
|
|
DKIM_SELECTOR="${DKIM_SELECTOR:-e2e}"
|
|
|
|
API_BASE="${SENTIO_API:-http://localhost:8080}"
|
|
API_KEY="${SENTIO_API_KEY:-sentio_bootstrap_admin_CHANGE_ME}"
|
|
TENANT_ID="${SENTIO_TENANT:-00000000-0000-0000-0000-000000000001}"
|
|
MAILPIT_URL="${MAILPIT_URL:-http://localhost:8025}"
|
|
|
|
# ── docker / compose ────────────────────────────────────────────────────────
|
|
# The docker group membership only takes effect after re-login, so fall back to
|
|
# sudo when the socket is not directly usable.
|
|
if docker info >/dev/null 2>&1; then
|
|
DOCKER_BIN=(docker)
|
|
elif sudo -n docker info >/dev/null 2>&1; then
|
|
DOCKER_BIN=(sudo -n docker)
|
|
else
|
|
echo "error: cannot talk to the docker daemon (tried docker and sudo docker)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Passing -f disables auto-loading of docker-compose.override.yml, so include it
|
|
# explicitly when present or per-machine port remaps silently disappear.
|
|
_compose_files=(-f "$REPO_ROOT/docker-compose.yml" -f "$REPO_ROOT/docker-compose.test.yml")
|
|
[ -f "$REPO_ROOT/docker-compose.override.yml" ] && \
|
|
_compose_files+=(-f "$REPO_ROOT/docker-compose.override.yml")
|
|
|
|
dc() { "${DOCKER_BIN[@]}" compose "${_compose_files[@]}" "$@"; }
|
|
|
|
# Ask the daemon which host port maps to container :25 rather than assuming.
|
|
smtp_port() {
|
|
local hp
|
|
hp="$(dc port sentio 25 2>/dev/null | tail -1)"
|
|
[ -n "$hp" ] && echo "${hp##*:}" || echo 25
|
|
}
|
|
submission_port() {
|
|
local hp
|
|
hp="$(dc port sentio 587 2>/dev/null | tail -1)"
|
|
[ -n "$hp" ] && echo "${hp##*:}" || echo 587
|
|
}
|
|
|
|
# ── HTTP ────────────────────────────────────────────────────────────────────
|
|
api() {
|
|
local method="$1" path="$2"; shift 2
|
|
curl -sS -m 20 -X "$method" \
|
|
-H "Authorization: Bearer $API_KEY" \
|
|
-H 'Content-Type: application/json' \
|
|
"$@" "$API_BASE$path"
|
|
}
|
|
|
|
jqf() { python3 -c "import json,sys;d=json.load(sys.stdin);print($1)" 2>/dev/null; }
|
|
|
|
# ── Output ──────────────────────────────────────────────────────────────────
|
|
_pass=0; _fail=0; _skip=0
|
|
# stderr, so helpers can log while their stdout is captured by the caller.
|
|
info() { printf '\033[36m··\033[0m %s\n' "$*" >&2; }
|
|
pass() { _pass=$((_pass+1)); printf '\033[32mok\033[0m %s\n' "$*"; }
|
|
fail() { _fail=$((_fail+1)); printf '\033[31mFAIL\033[0m %s\n' "$*" >&2; }
|
|
# Not every check can run everywhere - TLS needs a certificate mounted. A skip
|
|
# says so out loud rather than quietly passing.
|
|
skip() { _skip=$((_skip+1)); printf '\033[33m--\033[0m %s\n' "$*"; }
|
|
summary() {
|
|
echo
|
|
local tail=""
|
|
[ "$_skip" -gt 0 ] && tail=", $_skip skipped"
|
|
if [ "$_fail" -eq 0 ]; then
|
|
printf '\033[32m%d passed, 0 failed%s\033[0m\n' "$_pass" "$tail"; return 0
|
|
fi
|
|
printf '\033[31m%d passed, %d failed%s\033[0m\n' "$_pass" "$_fail" "$tail"; return 1
|
|
}
|
|
|
|
# Poll until `cmd` succeeds or the deadline passes.
|
|
wait_for() {
|
|
local desc="$1" timeout="$2"; shift 2
|
|
local deadline=$(( SECONDS + timeout ))
|
|
while [ "$SECONDS" -lt "$deadline" ]; do
|
|
if "$@" >/dev/null 2>&1; then return 0; fi
|
|
sleep 1
|
|
done
|
|
echo "timed out after ${timeout}s waiting for: $desc" >&2
|
|
return 1
|
|
}
|
|
|
|
# Run a redis-cli command inside the stack.
|
|
redis_cli() { dc exec -T redis redis-cli "$@" 2>/dev/null | tr -d '\r'; }
|
|
|
|
# Host address the sentio container can reach us on, for webhook capture.
|
|
docker_gateway() {
|
|
"${DOCKER_BIN[@]}" network inspect sentio-oss_sentio_net \
|
|
--format '{{range .IPAM.Config}}{{.Gateway}}{{end}}' 2>/dev/null
|
|
}
|