first commit
This commit is contained in:
commit
6d3ea3e2a6
43 files changed
+8204
No files matched your search
Executable
+172
@@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env bash
|
||||
# End-to-end test of the Meow v2 Rust stack (meowsrv + meow CLI).
|
||||
# Rust equivalent of meowcli/test.sh, with output assertions.
|
||||
#
|
||||
# Usage:
|
||||
# tests/e2e.sh # two servers, in-memory storage
|
||||
# E2E_STORAGE=redis://127.0.0.1:6379/15 tests/e2e.sh # Redis backend (db 15 is used)
|
||||
# E2E_RELEASE=1 tests/e2e.sh # release build
|
||||
# E2E_KEEP=1 tests/e2e.sh # keep tests/work for inspection
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
WORK="$ROOT/tests/work"
|
||||
PORT1="${E2E_PORT1:-18080}"
|
||||
PORT2="${E2E_PORT2:-18081}"
|
||||
S1="http://127.0.0.1:$PORT1"
|
||||
S2="http://127.0.0.1:$PORT2"
|
||||
STORAGE="${E2E_STORAGE:-memory}"
|
||||
|
||||
green() { printf '\033[32m%s\033[0m\n' "$*"; }
|
||||
red() { printf '\033[31m%s\033[0m\n' "$*"; }
|
||||
step() { green "## $*"; }
|
||||
|
||||
PIDS=()
|
||||
cleanup() {
|
||||
for p in "${PIDS[@]:-}"; do [ -n "$p" ] && kill "$p" 2>/dev/null || true; done
|
||||
wait 2>/dev/null || true
|
||||
[ "${E2E_KEEP:-0}" = 1 ] || rm -rf "$WORK"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
trap 'red "FAILED at line $LINENO"' ERR
|
||||
|
||||
# ── build ──
|
||||
step "BUILD"
|
||||
PROFILE=debug
|
||||
if [ "${E2E_RELEASE:-0}" = 1 ]; then
|
||||
(cd "$ROOT" && cargo build --release --bin meow --bin meowsrv); PROFILE=release
|
||||
else
|
||||
(cd "$ROOT" && cargo build --bin meow --bin meowsrv)
|
||||
fi
|
||||
MEOW_BIN="$ROOT/target/$PROFILE/meow"
|
||||
SRV_BIN="$ROOT/target/$PROFILE/meowsrv"
|
||||
|
||||
rm -rf "$WORK" && mkdir -p "$WORK" && cd "$WORK"
|
||||
|
||||
# ── servers ──
|
||||
step "SERVERS ($STORAGE)"
|
||||
start_server() { # port name
|
||||
MEOWSRV_LOG=warn "$SRV_BIN" --listen "127.0.0.1:$1" --name "$2" \
|
||||
--storage "$STORAGE" --key-file "$WORK/$2.key" >"$WORK/$2.log" 2>&1 &
|
||||
PIDS+=($!)
|
||||
}
|
||||
start_server "$PORT1" srv1
|
||||
start_server "$PORT2" srv2
|
||||
for url in "$S1" "$S2"; do
|
||||
for _ in $(seq 50); do curl -fs "$url/healthz" >/dev/null 2>&1 && break; sleep 0.1; done
|
||||
curl -fs "$url/healthz" >/dev/null || { red "server $url did not start"; cat "$WORK"/*.log; exit 1; }
|
||||
done
|
||||
|
||||
export MEOW_PASSWORD="e2e-password"
|
||||
export MEOW_INSECURE_FAST_KDF=true # weak KDF: tests only
|
||||
meow() { local id="$1"; shift; "$MEOW_BIN" -i "$WORK/$id.mwid2" --downloads "$WORK/dl-$id" "$@"; }
|
||||
|
||||
# expect <description> <needle> <command...>: run, show output, check it contains needle
|
||||
expect() {
|
||||
local desc="$1" needle="$2"; shift 2
|
||||
local out
|
||||
out="$("$@")"
|
||||
[ -n "$out" ] && printf '%s\n' "$out" | sed 's/^/ /'
|
||||
if ! grep -qF -- "$needle" <<<"$out"; then
|
||||
red "expected '$needle' ($desc)"; exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# ── identities ──
|
||||
step "IDENTITIES"
|
||||
for who in bob alice remote; do meow "$who" identity create "$who" --force; done
|
||||
expect "wrong password rejected" "cannot open identity" \
|
||||
bash -c "'$MEOW_BIN' -i '$WORK/bob.mwid2' -p wrong identity show 2>&1 || true"
|
||||
|
||||
step "SERVER ADD"
|
||||
for who in bob alice remote; do
|
||||
meow "$who" server add "$S1" >/dev/null
|
||||
meow "$who" server add "$S2" >/dev/null
|
||||
done
|
||||
expect "bob has 2 servers" "srv2" meow bob server list
|
||||
|
||||
# ── file invitation ──
|
||||
step "FILE INVITATION (4 steps)"
|
||||
expect "step 1" "bob-alice.mwiv2" meow bob invitation create alice --servers "$S1,$S2" --message "hello alice"
|
||||
expect "check" "hello alice" meow alice invitation check bob-alice.mwiv2
|
||||
expect "step 2" "alice-bob.mwiv2" meow alice invitation answer bob-alice.mwiv2 --servers "$S1,$S2"
|
||||
expect "alice pending" "AnswerSent" meow alice contact list
|
||||
expect "step 3" "bob-alice-step3.mwiv2" meow bob invitation accept alice-bob.mwiv2
|
||||
expect "bob can already send" "sent to alice" meow bob send alice "sent before finalize"
|
||||
expect "step 4" "contact bob is active" meow alice invitation finalize bob-alice-step3.mwiv2
|
||||
expect "bob receives the ack" "contact alice is active" meow bob
|
||||
expect "bob: alice active" "Active" meow bob contact list
|
||||
SN_BOB="$(meow bob contact show alice | grep 'safety number')"
|
||||
SN_ALICE="$(meow alice contact show bob | grep 'safety number')"
|
||||
[ "$SN_BOB" = "$SN_ALICE" ] || { red "safety numbers differ"; exit 1; }
|
||||
echo " $SN_BOB (identical on both sides)"
|
||||
|
||||
# ── messaging ──
|
||||
step "MESSAGING"
|
||||
expect "early message delivered" "[bob] sent before finalize" meow alice
|
||||
meow bob send alice hello >/dev/null
|
||||
expect "receive" "[bob] hello" meow alice
|
||||
[ -z "$(meow alice)" ] || { red "unexpected extra messages"; exit 1; }
|
||||
printf 'meow meow\n' >meow01.ascii
|
||||
head -c 200000 /dev/urandom >blob.bin
|
||||
meow bob send-file alice meow01.ascii >/dev/null
|
||||
expect "text file" "file saved to" meow alice
|
||||
cmp meow01.ascii "$WORK/dl-alice/meow01.ascii"
|
||||
meow bob send-file alice blob.bin >/dev/null
|
||||
expect "binary file" "blob.bin" meow alice
|
||||
cmp blob.bin "$WORK/dl-alice/blob.bin"
|
||||
meow bob send alice msg1 >/dev/null; meow bob send alice msg2 >/dev/null; meow bob send alice msg3 >/dev/null
|
||||
OUT="$(meow alice)"; printf '%s\n' "$OUT" | sed 's/^/ /'
|
||||
[ "$(grep -c '^\[bob\] msg' <<<"$OUT")" = 3 ] || { red "expected 3 messages"; exit 1; }
|
||||
expect "reply" "sent to bob" meow alice send bob "hi bob"
|
||||
expect "bob reads reply" "[alice] hi bob" meow bob
|
||||
|
||||
# ── server invitation ──
|
||||
step "SERVER INVITATION (4 steps)"
|
||||
URL="$(meow bob server-invitation create remote --servers "$S1,$S2" --message "via server" --invitation-password s3cret)"
|
||||
echo " invitation URL: $URL"
|
||||
expect "wrong invitation password" "bad password" \
|
||||
bash -c "'$MEOW_BIN' -i '$WORK/remote.mwid2' server-invitation get '$URL' --invitation-password nope 2>&1 || true"
|
||||
expect "step 2" "answered invitation from bob" meow remote server-invitation get "$URL" --invitation-password s3cret
|
||||
expect "step 3 (auto)" "invitation accepted by remote" meow bob
|
||||
expect "step 4 (auto)" "contact bob is active" meow remote
|
||||
expect "ack" "contact remote is active" meow bob
|
||||
meow remote send bob "hello from remote" >/dev/null
|
||||
expect "remote -> bob" "[remote] hello from remote" meow bob
|
||||
|
||||
# ── long poll ──
|
||||
step "LONG POLL"
|
||||
meow alice longpoll --wait 20 --exit >"$WORK/lp1.out" &
|
||||
LP=$!
|
||||
sleep 1
|
||||
meow bob send alice "longpoll?" >/dev/null
|
||||
START=$(date +%s)
|
||||
wait "$LP"
|
||||
ELAPSED=$(( $(date +%s) - START ))
|
||||
sed 's/^/ /' "$WORK/lp1.out"
|
||||
grep -qF "[bob] longpoll?" "$WORK/lp1.out" || { red "long poll did not get the message"; exit 1; }
|
||||
[ "$ELAPSED" -lt 10 ] || { red "long poll took ${ELAPSED}s"; exit 1; }
|
||||
|
||||
step "LONG POLL (offline messages)"
|
||||
for i in 1 2 3; do meow bob send alice "longpoll$i?" >/dev/null; done
|
||||
OUT="$(meow alice longpoll --wait 5 --exit)"; printf '%s\n' "$OUT" | sed 's/^/ /'
|
||||
[ "$(grep -c 'longpoll[123]?' <<<"$OUT")" = 3 ] || { red "expected 3 offline messages"; exit 1; }
|
||||
|
||||
step "MIXED"
|
||||
meow bob send alice "ba1?" >/dev/null
|
||||
meow alice send bob "ab1?" >/dev/null
|
||||
meow bob send alice "ba2?" >/dev/null
|
||||
meow alice send bob "ab2?" >/dev/null
|
||||
expect "alice" "[bob] ba2?" meow alice longpoll --wait 5 --exit
|
||||
expect "bob" "[alice] ab2?" meow bob longpoll --wait 5 --exit
|
||||
|
||||
# ── resilience: one server down ──
|
||||
step "ONE SERVER DOWN"
|
||||
kill "${PIDS[1]}"; wait "${PIDS[1]}" 2>/dev/null || true; PIDS[1]=""
|
||||
expect "send with one server down" "(1 server(s))" meow bob send alice "still here"
|
||||
expect "receive with one server down" "[bob] still here" meow alice 2>/dev/null
|
||||
|
||||
step "HISTORY"
|
||||
expect "history" "[alice] hi bob" meow bob history alice
|
||||
|
||||
green "ALL E2E TESTS PASSED"
|
||||
Reference in new issue
Block a user