Within the last 30 days the owner page offers it. The node signs a new certificate for the same device key (peer ID and listings stay), saves it, and signs again own listings that would outlive the old certificate. The phrase is used for one request and not kept; another identity's phrase and no-phrase identities are refused. Device.Current gives the certificate to sign with while a renewal happens. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
264 lines
21 KiB
Bash
Executable File
264 lines
21 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# End-to-end test with two real nodes: publish, edit, renew, replicate,
|
|
# encrypted messaging with an address grant, and recovery after a "stolen" machine.
|
|
# The buyer is played by scripts/e2e/buyer.ts, which runs the browser's own
|
|
# crypto code under Node.js. Needs Go, Node.js (22.18+) and `make web-test`
|
|
# once (or `cd web && npm ci`) for the web dependencies. Run: make e2e
|
|
set -u
|
|
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
[ -d "$ROOT/web/node_modules" ] || { echo "web dependencies missing: run 'cd web && npm ci' first"; exit 1; }
|
|
(cd "$ROOT" && go build -o bin/allmende ./cmd/allmende) || exit 1
|
|
BIN=$ROOT/bin/allmende
|
|
mkdir -p "$ROOT/.tmp" # scratch space inside the checkout (git ignores it), not /tmp
|
|
W=$(mktemp -d "${TMPDIR:-$ROOT/.tmp}/allmende-e2e.XXXXXX")
|
|
A=$W/a; B=$W/b
|
|
PIDS=()
|
|
cleanup() {
|
|
for p in "${PIDS[@]}"; do kill "$p" 2>/dev/null; done
|
|
wait 2>/dev/null
|
|
if [ -n "${E2E_KEEP:-}" ]; then echo "kept $W"; else rm -rf "$W"; fi
|
|
}
|
|
trap cleanup EXIT
|
|
ok() { echo "PASS: $*"; }
|
|
bad() { echo "FAIL: $*"; echo "--- node A log"; tail -15 "$W/a.log"; echo "--- node B log"; tail -15 "$W/b.log"; exit 1; }
|
|
wait_for() { # description, timeout, command...
|
|
local what=$1 t=$2; shift 2
|
|
for _ in $(seq 1 $((t*10))); do if "$@" >/dev/null 2>&1; then return 0; fi; sleep 0.1; done
|
|
bad "timed out: $what"
|
|
}
|
|
# check OP WANT COMMAND...: runs COMMAND each time it is polled and compares its output.
|
|
# (Writing test "$(command)" = x inside wait_for would run the command only once.)
|
|
check() {
|
|
local op=$1 want=$2 got; shift 2
|
|
got=$("$@" 2>/dev/null) || return 1
|
|
case $op in
|
|
eq) [ "$got" = "$want" ] ;;
|
|
ge) [ "$got" -ge "$want" ] 2>/dev/null ;;
|
|
esac
|
|
}
|
|
peers() { curl -s http://127.0.0.1:$1/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["peers"])'; }
|
|
DIFF=10
|
|
# --no-default-bootstrap: these nodes must not look up the real bootstrap name in DNS.
|
|
COMMON="--region u1x --no-mdns --no-default-bootstrap --difficulty $DIFF"
|
|
|
|
echo "== init"
|
|
$BIN init --data $A > $W/init-a.txt || bad "init A"
|
|
$BIN init --data $B > $W/init-b.txt || bad "init B"
|
|
grep -q "12 words" $W/init-a.txt && ok "init prints the recovery phrase"
|
|
PHRASE=$(grep -E '^ +[0-9]+\.' $W/init-a.txt | sed -E 's/[0-9]+\.//g' | tr -s ' \n' ' ' | sed 's/^ //; s/ $//')
|
|
[ "$(echo $PHRASE | wc -w)" = 12 ] && ok "captured 12-word phrase" || bad "phrase parse: '$PHRASE'"
|
|
[ ! -e $A/root.key ] && ! grep -rqi "$(echo $PHRASE | cut -d' ' -f1-3)" $A && ok "phrase is not stored in the data dir"
|
|
[ "$(stat -c %a $A/device.key)" = 600 ] && [ "$(stat -c %a $A/admin.token)" = 600 ] && ok "key and token are mode 0600"
|
|
$BIN init --data $A >/dev/null 2>&1 && bad "init must refuse to run twice" || ok "init refuses to overwrite an existing identity"
|
|
|
|
echo "== run two nodes"
|
|
$BIN run --data $A $COMMON --http 127.0.0.1:18101 --listen /ip4/127.0.0.1/tcp/14101 2> $W/a.log &
|
|
PIDS+=($!)
|
|
wait_for "A http" 10 curl -sf http://127.0.0.1:18101/api/v1/status
|
|
PEER=$(curl -s http://127.0.0.1:18101/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["peer_id"])')
|
|
$BIN run --data $B $COMMON --http 127.0.0.1:18102 --listen /ip4/127.0.0.1/tcp/14102 \
|
|
--bootstrap /ip4/127.0.0.1/tcp/14101/p2p/$PEER 2> $W/b.log &
|
|
PIDS+=($!)
|
|
wait_for "B http" 10 curl -sf http://127.0.0.1:18102/api/v1/status
|
|
wait_for "nodes connected" 15 check ge 1 peers 18101
|
|
ok "nodes connected"
|
|
|
|
echo "== publish on A, read on B"
|
|
TOKEN=$(cat $A/admin.token)
|
|
DRAFT='{"kind":"rent","category":"apartment","geohash":"u1xjhx","price":{"amount_cents":95000,"currency":"EUR","period":"month"},"area_m2":48,"rooms_x2":4,"title":"Helle Wohnung","description":"Ruhig."}'
|
|
curl -s -o /dev/null -w "%{http_code}" -X POST -d "$DRAFT" http://127.0.0.1:18101/api/v1/listings | grep -q 401 && ok "publishing without the token is refused"
|
|
RESP=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" -d "$DRAFT" http://127.0.0.1:18101/api/v1/listings)
|
|
ID=$(echo "$RESP" | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])') || bad "create: $RESP"
|
|
ok "published listing $ID"
|
|
count_b() { curl -s "http://127.0.0.1:18102/api/v1/listings?geohash=u1x" | python3 -c 'import json,sys; print(len(json.load(sys.stdin)))'; }
|
|
wait_for "B receives the listing" 15 check eq 1 count_b
|
|
ok "node B has the listing via gossip"
|
|
|
|
echo "== UI-style edit and renew on A (draft built by the UI's own code)"
|
|
RENEW=$ROOT/scripts/e2e/renew.ts
|
|
AUTHOR0=$(curl -s http://127.0.0.1:18101/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["author"])')
|
|
CUR=$(curl -s http://127.0.0.1:18101/api/v1/listings/$AUTHOR0/$ID)
|
|
EDIT=$(echo "$CUR" | node $RENEW "Helle Wohnung, renoviert" 20) || bad "draft from listing"
|
|
PUTR=$(curl -s -X PUT -H "Authorization: Bearer $TOKEN" -d "$EDIT" http://127.0.0.1:18101/api/v1/listings/$ID)
|
|
echo "$PUTR" | python3 -c 'import json,sys; l=json.load(sys.stdin); assert l["title"]=="Helle Wohnung, renoviert" and l["seq"]==2, l' && ok "edit accepted: new version, seq 2" || bad "edit refused: $PUTR"
|
|
RENEWED=$(echo "$PUTR" | node $RENEW "" 30) || bad "renew draft"
|
|
PUTR=$(curl -s -X PUT -H "Authorization: Bearer $TOKEN" -d "$RENEWED" http://127.0.0.1:18101/api/v1/listings/$ID)
|
|
echo "$PUTR" | python3 -c 'import json,sys; l=json.load(sys.stdin); assert l["seq"]==3 and l["expires_at"]-l["created_at"]>29*86400, l' && ok "renew accepted: seq 3, fresh 30-day term" || bad "renew refused: $PUTR"
|
|
seq_on_b() { curl -s http://127.0.0.1:18102/api/v1/listings/$AUTHOR0/$ID | python3 -c 'import json,sys; print(json.load(sys.stdin)["seq"])'; }
|
|
wait_for "B has the renewed version" 15 check eq 3 seq_on_b
|
|
ok "node B serves the renewed version"
|
|
MOVED=$(echo "$PUTR" | node $RENEW "" 30 | python3 -c 'import json,sys; d=json.load(sys.stdin); d["geohash"]="u28xyz"; print(json.dumps(d))')
|
|
curl -s -o /dev/null -w "%{http_code}" -X PUT -H "Authorization: Bearer $TOKEN" -d "$MOVED" http://127.0.0.1:18101/api/v1/listings/$ID | grep -q 400 && ok "moving a listing to another region is refused" || bad "region change was not refused"
|
|
|
|
echo "== messaging: buyer -> B -> A, reply A -> B -> buyer"
|
|
BUYER=$ROOT/scripts/e2e/buyer.ts
|
|
AUTHOR=$(curl -s http://127.0.0.1:18101/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["author"])')
|
|
SECRET=$(node $BUYER send http://127.0.0.1:18102 $AUTHOR $ID) || bad "buyer could not send via B"
|
|
ok "buyer posted an encrypted message to node B"
|
|
# Nobody has called A's API yet: the node itself must notice and tell its owner.
|
|
wait_for "A's terminal announces the new conversation" 30 grep -q 'msg="new conversation"' "$W/a.log"
|
|
grep 'msg="new conversation"' "$W/a.log" | grep -q 'listing="Helle Wohnung, renoviert"' && ok "owner's terminal names the listing" || bad "notice does not name the listing"
|
|
grep 'msg="new conversation"' "$W/a.log" | grep -q "open=http://127.0.0.1:18101/#/mine/$ID/" && ok "and links to the conversation" || bad "notice has no link"
|
|
grep -q "Ist die Wohnung noch frei" "$W/a.log" && bad "the buyer's text was printed to the terminal"
|
|
ok "the notice does not show what the buyer wrote"
|
|
[ "$(grep -c 'msg="new conversation"' "$W/a.log")" = 1 ] || bad "the notice was repeated"
|
|
inbox_a() { curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:18101/api/v1/inbox | python3 -c 'import json,sys; print(len(json.load(sys.stdin)))'; }
|
|
wait_for "A receives the message" 20 check eq 1 inbox_a
|
|
ok "owner's node A decrypted it (via gossip through B)"
|
|
THREAD=$(curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:18101/api/v1/inbox | python3 -c 'import json,sys; print(json.load(sys.stdin)[0]["thread"])')
|
|
curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:18101/api/v1/inbox/$ID/$THREAD | grep -q "Ist die Wohnung noch frei" && ok "owner reads the buyer's text"
|
|
curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:18101/api/v1/inbox | grep -q 401 && ok "inbox needs the admin token"
|
|
curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:18101/api/v1/mine | grep -q 401 && ok "my-listings overview needs the admin token"
|
|
curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:18101/api/v1/mine | python3 -c 'import json,sys; m=json.load(sys.stdin); assert len(m)==1 and m[0]["threads"]==1 and m[0]["needs_reply"]==1, m' && ok "owner overview counts the request that needs a reply"
|
|
curl -s -o /dev/null -w "%{http_code}" -X PUT -H "Authorization: Bearer $TOKEN" -d '{"address":"Musterweg 7, 20095 Hamburg"}' http://127.0.0.1:18101/api/v1/listings/$ID/address | grep -qE "^(200|204)$" && ok "address stored privately on A"
|
|
curl -s http://127.0.0.1:18102/api/v1/listings/$AUTHOR/$ID | grep -q "Musterweg" && bad "address leaked into the public listing"
|
|
ok "address is not part of the public listing"
|
|
curl -s -o /dev/null -w "%{http_code}" -X POST -H "Authorization: Bearer $TOKEN" -d '{"type":"grant","address":"Musterweg 7, 20095 Hamburg","note":"Samstag 10 Uhr","valid_days":7}' http://127.0.0.1:18101/api/v1/inbox/$ID/$THREAD | grep -qE "^(200|201|202)$" || bad "grant reply refused"
|
|
ok "owner sent a signed address grant"
|
|
wait_for "buyer sees the grant via B" 20 bash -c "node $BUYER read http://127.0.0.1:18102 $AUTHOR $ID $SECRET | grep -q 'OK grant Musterweg'"
|
|
ok "buyer's browser code verified and read the grant from B"
|
|
node $BUYER read http://127.0.0.1:18102 $AUTHOR $ID $(node -e 'console.log("77".repeat(32))') | grep -q . && bad "another thread key saw a reply"
|
|
ok "a different thread key sees nothing"
|
|
|
|
echo "== the same through the web UI: a real page for the buyer on B, one for the owner on A"
|
|
UI=$ROOT/scripts/e2e/ui.ts
|
|
node $UI buyer http://127.0.0.1:18102 http://127.0.0.1:18101 $TOKEN $AUTHOR $ID > $W/ui-buyer.txt 2>&1 \
|
|
&& { sed 's/^OK /PASS: UI: /' $W/ui-buyer.txt; } || { cat $W/ui-buyer.txt; bad "the buyer flow through the web UI"; }
|
|
|
|
echo "== abuse reports: the operator's report hides the listing on A; B receives it but does not count a stranger's"
|
|
count() { curl -s "http://127.0.0.1:$1/api/v1/listings$2" | python3 -c 'import json,sys; print(len(json.load(sys.stdin)))'; }
|
|
[ "$(count 18101 '')" = 1 ] && [ "$(count 18102 '')" = 1 ] && ok "both nodes list it before any report" || bad "the listing is missing before the report"
|
|
REPORT="{\"listing\":{\"author\":\"$AUTHOR\",\"id\":\"$ID\"},\"category\":\"scam\",\"note\":\"e2e\"}"
|
|
curl -s -o /dev/null -w "%{http_code}" -X POST -d "$REPORT" http://127.0.0.1:18101/api/v1/reports | grep -q 401 && ok "reporting needs the admin token"
|
|
curl -s -X POST -H "Authorization: Bearer $TOKEN" -d "$REPORT" http://127.0.0.1:18101/api/v1/reports \
|
|
| python3 -c 'import json,sys; s=json.load(sys.stdin); assert s["hidden"] and s["own"]=="scam", s' && ok "A signed the report and hides the listing" || bad "A did not hide it"
|
|
[ "$(count 18101 '')" = 0 ] && [ "$(count 18101 '?hidden=1')" = 1 ] && ok "A leaves it out of search; ?hidden=1 still lists it" || bad "A's search does not hide it"
|
|
curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:18101/api/v1/listings/$AUTHOR/$ID | grep -q 200 && ok "its own link still works" || bad "a hidden listing is not reachable by its link"
|
|
wait_for "B received A's signed report" 20 bash -c "curl -s 'http://127.0.0.1:18102/api/v1/reports?author=$AUTHOR&id=$ID' | grep -q '\"others\":1'"
|
|
ok "B received it through the network"
|
|
[ "$(count 18102 '')" = 1 ] && ok "B does not trust A, so it still shows the listing" || bad "B hid a listing on a stranger's report"
|
|
sleep 1 # a newer report must be dated a second later
|
|
curl -s -X POST -H "Authorization: Bearer $TOKEN" -d "${REPORT/scam/withdrawn}" http://127.0.0.1:18101/api/v1/reports >/dev/null
|
|
[ "$(count 18101 '')" = 1 ] && ok "withdrawing the report shows the listing again" || bad "a withdrawn report still hides it"
|
|
|
|
echo "== renewing the device certificate from the browser, with the phrase"
|
|
status_field() { curl -s http://127.0.0.1:18101/api/v1/status | python3 -c "import json,sys; print(json.load(sys.stdin)[\"$1\"])"; }
|
|
CERT_BEFORE=$(status_field cert_expires_at)
|
|
[ "$(status_field can_renew)" = True ] && ok "status says the certificate can be renewed, and until when ($CERT_BEFORE)" || bad "status does not offer renewal"
|
|
renew_code() { curl -s -o /dev/null -w "%{http_code}" -X PUT ${2:+-H "Authorization: Bearer $2"} -d "{\"phrase\":\"$1\"}" http://127.0.0.1:18101/api/v1/certificate; }
|
|
[ "$(renew_code "$PHRASE")" = 401 ] && ok "renewal without the admin token is refused" || bad "renewal worked without a token"
|
|
PHRASE_B=$(grep -E '^ +[0-9]+\.' $W/init-b.txt | sed -E 's/[0-9]+\.//g' | tr -s ' \n' ' ' | sed 's/^ //; s/ $//')
|
|
[ "$(renew_code "$PHRASE_B" "$TOKEN")" = 409 ] && ok "another identity's phrase is refused" || bad "renewed with the wrong identity's phrase"
|
|
[ "$(renew_code "wrong words here" "$TOKEN")" = 400 ] && ok "a malformed phrase is refused" || bad "a malformed phrase was accepted"
|
|
[ "$(status_field cert_expires_at)" = "$CERT_BEFORE" ] && ok "refused renewals changed nothing" || bad "a refused renewal moved the expiry"
|
|
sleep 1.2 # the new certificate must be dated a second later to expire later
|
|
[ "$(renew_code "$PHRASE" "$TOKEN")" = 200 ] && ok "the owner's phrase renews it" || bad "renewal with the right phrase failed"
|
|
CERT_AFTER=$(status_field cert_expires_at)
|
|
[ "$CERT_AFTER" -gt "$CERT_BEFORE" ] && ok "the certificate now runs until $CERT_AFTER" || bad "expiry did not move: $CERT_BEFORE -> $CERT_AFTER"
|
|
[ "$(status_field peer_id)" = "$PEER" ] && ok "same device key, same peer ID" || bad "renewing changed the peer ID"
|
|
grep -q "\"expires_at\":$CERT_AFTER" $A/device.cert && ok "the new certificate is saved, so a restart keeps it" || bad "device.cert does not hold the renewal"
|
|
grep -rqi "$(echo $PHRASE | cut -d' ' -f1-3)" $A && bad "the phrase was written to the data directory"
|
|
ok "the phrase was not stored"
|
|
[ "$(count 18101 '')" = 1 ] && ok "the owner's listing is untouched" || bad "renewal disturbed the listing"
|
|
|
|
echo "== recover on A (simulate a stolen machine)"
|
|
OLD_DEVICE=$(curl -s http://127.0.0.1:18101/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["device"])')
|
|
kill ${PIDS[0]}; wait ${PIDS[0]} 2>/dev/null
|
|
echo "$PHRASE" | $BIN recover --data $A --difficulty $DIFF > $W/recover.txt 2>&1 || { cat $W/recover.txt; bad "recover"; }
|
|
grep -q "1 of your listings were re-signed" $W/recover.txt && ok "recover re-signed the owner's listing" || { cat $W/recover.txt; bad "recover output"; }
|
|
ls $A | grep -q "device.key.revoked-" && ok "old device key was moved aside, not destroyed"
|
|
echo "wrong words here" | $BIN recover --data $A >/dev/null 2>&1 && bad "bad phrase accepted" || ok "recover rejects a wrong phrase"
|
|
|
|
# The recovered node has a new peer ID, so B's bootstrap entry for the old one
|
|
# is stale. Like a real recovered node, A dials out to its own bootstrap peer.
|
|
PEER_B=$(curl -s http://127.0.0.1:18102/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["peer_id"])')
|
|
$BIN run --data $A $COMMON --http 127.0.0.1:18101 --listen /ip4/127.0.0.1/tcp/14101 \
|
|
--bootstrap /ip4/127.0.0.1/tcp/14102/p2p/$PEER_B 2> $W/a.log &
|
|
PIDS[0]=$!
|
|
wait_for "A http again" 10 curl -sf http://127.0.0.1:18101/api/v1/status
|
|
NEW_DEVICE=$(curl -s http://127.0.0.1:18101/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["device"])')
|
|
[ "$OLD_DEVICE" != "$NEW_DEVICE" ] && ok "A runs with a new device key" || bad "device did not change"
|
|
OLDTOKEN=$TOKEN
|
|
curl -s -o /dev/null -w "%{http_code}" -X POST -H "Authorization: Bearer $OLDTOKEN" -d "$DRAFT" http://127.0.0.1:18101/api/v1/listings | grep -q 401 && ok "old admin token no longer works"
|
|
|
|
# B should learn of the revocation and the re-signed listing (seq 2, new device).
|
|
dev_on_b() { curl -s "http://127.0.0.1:18102/api/v1/listings?geohash=u1x" | python3 -c '
|
|
import json,sys
|
|
l=json.load(sys.stdin)
|
|
print(l[0]["device"] if len(l)==1 else "none")'; }
|
|
wait_for "B switches to the new device's version" 60 check eq "$NEW_DEVICE" dev_on_b
|
|
ok "node B now serves the listing re-signed by the new device (old device revoked network-wide)"
|
|
|
|
echo "== bootstrap node: two nodes that only know it find each other"
|
|
C=$W/c; X=$W/x; Y=$W/y
|
|
for d in $C $X $Y; do $BIN init --data $d >/dev/null || bad "init $d"; done
|
|
$BIN run --data $C $COMMON --public --http 127.0.0.1:18103 --listen /ip4/127.0.0.1/tcp/14103 2> $W/c.log &
|
|
PIDS+=($!)
|
|
wait_for "bootstrap node http" 10 curl -sf http://127.0.0.1:18103/api/v1/status
|
|
PEER_C=$(curl -s http://127.0.0.1:18103/api/v1/status | python3 -c 'import json,sys; print(json.load(sys.stdin)["peer_id"])')
|
|
grep -q "no public address" $W/c.log && ok "--public on loopback says it has no public address to publish" || bad "no hint about the missing public address"
|
|
$BIN run --data $X $COMMON --http 127.0.0.1:18104 --listen /ip4/127.0.0.1/tcp/14104 \
|
|
--bootstrap /ip4/127.0.0.1/tcp/14103/p2p/$PEER_C 2> $W/x.log &
|
|
XPID=$!; PIDS+=($XPID)
|
|
$BIN run --data $Y $COMMON --http 127.0.0.1:18105 --listen /ip4/127.0.0.1/tcp/14105 \
|
|
--bootstrap /ip4/127.0.0.1/tcp/14103/p2p/$PEER_C 2> $W/y.log &
|
|
PIDS+=($!)
|
|
wait_for "X and Y connected to the bootstrap node" 20 check ge 2 peers 18103
|
|
# Each of X and Y has two peers only if they found each other (C is the other one).
|
|
wait_for "X finds Y through the DHT" 60 check ge 2 peers 18104
|
|
wait_for "Y finds X through the DHT" 20 check ge 2 peers 18105
|
|
ok "X and Y found each other through the DHT, introduced by nobody"
|
|
|
|
echo "== a node remembers its peers: restart X without any bootstrap"
|
|
kill $XPID; wait $XPID 2>/dev/null
|
|
[ -s $X/peers.json ] && grep -q "$PEER_C" $X/peers.json && ok "peers were saved on shutdown" || bad "peers.json missing or without the bootstrap node"
|
|
$BIN run --data $X $COMMON --http 127.0.0.1:18104 --listen /ip4/127.0.0.1/tcp/14104 2> $W/x2.log &
|
|
PIDS+=($!)
|
|
wait_for "X restarted" 10 curl -sf http://127.0.0.1:18104/api/v1/status
|
|
wait_for "X reconnects from its remembered peers" 30 check ge 1 peers 18104
|
|
ok "X rejoined the network with no bootstrap configured"
|
|
|
|
echo "== regions: chosen by place name in the browser, even the first one"
|
|
D=$W/d
|
|
$BIN init --data $D >/dev/null || bad "init D"
|
|
# No --region: the node starts empty and says what to do.
|
|
$BIN run --data $D --no-mdns --no-default-bootstrap --difficulty $DIFF --http 127.0.0.1:18106 \
|
|
--listen /ip4/127.0.0.1/tcp/14106 2> $W/d.log &
|
|
DPID=$!; PIDS+=($DPID)
|
|
wait_for "D http" 10 curl -sf http://127.0.0.1:18106/api/v1/status
|
|
grep -q "follows no region yet" $W/d.log && ok "a node without a region starts and tells the owner what to do" || bad "no hint for the owner"
|
|
DTOKEN=$(cat $D/admin.token)
|
|
node $UI regions http://127.0.0.1:18106 $DTOKEN > $W/ui-regions.txt 2>&1 \
|
|
&& { sed 's/^OK /PASS: UI: /' $W/ui-regions.txt; } || { cat $W/ui-regions.txt; bad "choosing the first region through the web UI"; }
|
|
[ -s $D/regions.json ] && ok "the choice is saved in the data directory" || bad "regions.json missing"
|
|
kill $DPID; wait $DPID 2>/dev/null
|
|
$BIN run --data $D --no-mdns --no-default-bootstrap --difficulty $DIFF --http 127.0.0.1:18106 \
|
|
--listen /ip4/127.0.0.1/tcp/14106 2> $W/d2.log &
|
|
DPID=$!; PIDS+=($DPID)
|
|
wait_for "D restarted" 10 curl -sf http://127.0.0.1:18106/api/v1/status
|
|
curl -s http://127.0.0.1:18106/api/v1/status | grep -q '"regions":\["u1j"' && ok "after a restart without --region it still follows what the browser chose" || bad "regions were lost on restart"
|
|
|
|
echo "== --region takes place names"
|
|
$BIN run --data $W/nope --region Atlantisxyz 2>&1 | grep -q "neither a region code" && ok "an unknown place is refused with a hint" || bad "unknown place was not refused"
|
|
E=$W/e
|
|
$BIN init --data $E >/dev/null || bad "init E"
|
|
$BIN run --data $E --region cologne --no-mdns --no-default-bootstrap --difficulty $DIFF --http 127.0.0.1:18107 \
|
|
--listen /ip4/127.0.0.1/tcp/14107 2> $W/e.log &
|
|
PIDS+=($!)
|
|
wait_for "E http" 10 curl -sf http://127.0.0.1:18107/api/v1/status
|
|
grep -q 'Köln (Cologne)' $W/e.log && ok "'cologne' is announced as Köln, with the cells it follows" || bad "no note about what the name turned into"
|
|
curl -s http://127.0.0.1:18107/api/v1/status | grep -q '"regions":\["u1h"' && ok "Cologne's own cell (u1h) comes first" || bad "wrong region for cologne: $(curl -s http://127.0.0.1:18107/api/v1/status)"
|
|
|
|
echo "== a listing that runs out soon is reminded on the owner's terminal"
|
|
SOON='{"kind":"rent","category":"room","geohash":"u1jjjj","price":{"amount_cents":50000,"currency":"EUR","period":"month"},"title":"Zimmer, nur noch kurz","expires_in_days":3}'
|
|
curl -s -o /dev/null -w "%{http_code}" -X POST -H "Authorization: Bearer $DTOKEN" -d "$SOON" http://127.0.0.1:18106/api/v1/listings | grep -qE "^(200|201)$" || bad "could not publish the short listing on D"
|
|
wait_for "D's terminal reminds about the listing" 60 grep -q 'a listing runs out soon' $W/d2.log
|
|
grep 'a listing runs out soon' $W/d2.log | grep -q 'listing="Zimmer, nur noch kurz"' && ok "the reminder names the listing" || bad "reminder does not name the listing"
|
|
grep 'a listing runs out soon' $W/d2.log | grep -q 'left="3 days"' && ok "and says how long is left" || bad "reminder does not say how long is left"
|
|
grep 'a listing runs out soon' $W/d2.log | grep -q "renew=http://127.0.0.1:18106/#/mine" && ok "and links to where to renew" || bad "reminder has no link"
|
|
grep 'a listing runs out soon' $W/d2.log | grep -q "$DTOKEN" && bad "the sign-in token leaked into the log"
|
|
ok "the reminder does not carry the sign-in token"
|
|
grep -q "Helle Wohnung" $W/d2.log && bad "a listing with plenty of time left was reminded"
|
|
|
|
echo "ALL E2E CHECKS PASSED"
|