Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / tools/verify/walkthrough/operator-console.sh |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | tools/verify/walkthrough/operator-console.sh |
| Original SHA-256 | 78bd252bde9d5d5542e88131867eace28ae73236b9d7ca572704f63e56c99078 |
| Git blob SHA | c58273eb102e41bb2b90d92241aad9eb115bbd8a |
| Reading-copy SHA-256 | 78bd252bde9d5d5542e88131867eace28ae73236b9d7ca572704f63e56c99078 |
Recovered source transcript
Download complete source text ↓88 lines · 5.4 KB
#!/usr/bin/env bash
# OPERATOR CONSOLE PROOF. The gate is proven BOTH ways: a non operator must not see the surface at all, and
# an operator must be able to provision a tenant end to end.
set -uo pipefail
BASE="${BASE:-https://missionmatch-staging.thatwebhostingguy.com}"
PASS=0; FAIL=0
ok() { PASS=$((PASS+1)); printf ' PASS %-48s %s\n' "$1" "$2"; }
bad() { FAIL=$((FAIL+1)); printf ' FAIL %-48s %s\n' "$1" "$2"; }
jval(){ printf '%s' "$1" | grep -oE "\"$2\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" | head -1 | sed -E 's/.*:[[:space:]]*"([^"]*)"/\1/'; }
login() { # email pw jar -> echoes csrf
local e="$1" p="$2" j="$3" o t
rm -f "$j"
o=$(curl -s -m 20 -c "$j" "$BASE/api/auth/csrf"); t=$(jval "$o" csrf_token)
curl -s -m 20 -b "$j" -c "$j" -X POST "$BASE/api/auth/login" -H 'Content-Type: application/json' \
-H "X-CSRF-Token: $t" -H "Origin: $BASE" -d "{\"email\":\"$e\",\"password\":\"$p\"}" -o /dev/null
o=$(curl -s -m 20 -b "$j" -c "$j" "$BASE/api/auth/csrf"); jval "$o" csrf_token
}
call() { # method path jar csrf [json] -> sets R and C
local m="$1" p="$2" j="$3" c="$4" d="${5:-}" out
if [ -n "$d" ]; then
out=$(curl -s -m 25 -b "$j" -c "$j" -X "$m" "$BASE$p" -H 'Content-Type: application/json' \
-H "X-CSRF-Token: $c" -H "Origin: $BASE" -d "$d" -w $'\n%{http_code}')
else
out=$(curl -s -m 25 -b "$j" -c "$j" -X "$m" "$BASE$p" -H "X-CSRF-Token: $c" -H "Origin: $BASE" -w $'\n%{http_code}')
fi
C=$(printf '%s' "$out" | tail -1); R=$(printf '%s' "$out" | sed '$d')
}
echo "=== CONTROL FIRST. A NON operator must not even learn the surface exists ==="
J1=$(mktemp); C1=$(login "$MGR_EMAIL" "$MGR_PW" "$J1")
[ -n "$C1" ] && ok "manager logged in" "csrf issued" || bad "manager logged in" "no csrf"
call GET /api/platform/organizations "$J1" "$C1"
[ "$C" = "404" ] && ok "manager GET /platform/organizations" "404, correctly indistinguishable from absent" \
|| bad "manager GET /platform/organizations" "$C, expected 404. A 403 would CONFIRM the surface exists."
call POST /api/platform/organizations "$J1" "$C1" '{"name":"Sneaky","slug":"sneaky","owner_email":"a@b.test","owner_name":"A"}'
[ "$C" = "404" ] && ok "manager POST /platform/organizations" "404, refused" || bad "manager POST" "$C, a non operator reached provisioning"
rm -f "$J1"
echo "=== THE OPERATOR ==="
J2=$(mktemp); C2=$(login "$OP_EMAIL" "$OP_PW" "$J2")
[ -n "$C2" ] && ok "operator logged in" "csrf issued" || bad "operator logged in" "no csrf"
call GET /api/auth/session "$J2" "$C2"
[ "$(jval "$R" role)" = "operator" ] && ok "session role" "operator" || bad "session role" "$(jval "$R" role)"
call GET /api/platform/organizations "$J2" "$C2"
N=$(printf '%s' "$R" | grep -oE '"count":[0-9]+' | head -1)
[ "$C" = "200" ] && ok "operator GET /platform/organizations" "$C $N" || bad "operator GET" "$C $(printf '%s' "$R" | head -c 140)"
echo "=== VALIDATION, so a bad slug is a sentence not a constraint violation ==="
call POST /api/platform/organizations "$J2" "$C2" '{"name":"Bad Slug Co","slug":"Bad Slug","owner_email":"x@y.test","owner_name":"X"}'
[ "$C" = "422" ] && ok "invalid slug refused" "422: $(jval "$R" error | head -c 70)" || bad "invalid slug refused" "$C"
call POST /api/platform/organizations "$J2" "$C2" '{"name":"No Owner Co","slug":"no-owner-co","owner_email":"","owner_name":"X"}'
[ "$C" = "422" ] && ok "missing owner email refused" "422: field $(jval "$R" field)" || bad "missing owner email refused" "$C"
echo "=== PROVISION A REAL TENANT ==="
S="walkthru-$(date +%s)"
call POST /api/platform/organizations "$J2" "$C2" "{\"name\":\"Walkthrough Tenant\",\"slug\":\"$S\",\"owner_email\":\"owner@$S.test\",\"owner_name\":\"Pat Owner\"}"
NEWORG=$(jval "$R" organization_id); TOK=$(jval "$R" activation_token)
[ "$C" = "201" ] && [ -n "$NEWORG" ] && ok "operator provisioned a tenant" "$C org ${NEWORG:0:8}" \
|| bad "operator provisioned a tenant" "$C $(printf '%s' "$R" | head -c 200)"
[ -n "$TOK" ] && ok "activation token returned once" "length ${#TOK}, value not printed" || bad "activation token" "absent"
echo "=== THE SAME SLUG TWICE MUST CONFLICT, not 500 ==="
call POST /api/platform/organizations "$J2" "$C2" "{\"name\":\"Dup\",\"slug\":\"$S\",\"owner_email\":\"other@$S.test\",\"owner_name\":\"O\"}"
[ "$C" = "409" ] && ok "duplicate slug conflicts" "409" || bad "duplicate slug conflicts" "$C, expected 409"
echo "=== THE NEW OWNER CAN ACTUALLY REDEEM AND LOG IN, which is the whole point ==="
if [ -n "${TOK:-}" ]; then
J3=$(mktemp)
o=$(curl -s -m 20 -c "$J3" "$BASE/api/auth/csrf"); c3=$(jval "$o" csrf_token)
NEWPW="Redeem-$(openssl rand -hex 10)"
out=$(curl -s -m 25 -b "$J3" -c "$J3" -X POST "$BASE/api/auth/invite/accept" -H 'Content-Type: application/json' \
-H "X-CSRF-Token: $c3" -H "Origin: $BASE" -d "{\"token\":\"$TOK\",\"password\":\"$NEWPW\"}" -w $'\n%{http_code}')
rc=$(printf '%s' "$out" | tail -1)
[ "$rc" = "200" ] || [ "$rc" = "201" ] && ok "new owner redeemed the invite" "$rc" || bad "new owner redeemed the invite" "$rc $(printf '%s' "$out" | sed '$d' | head -c 160)"
C4=$(login "owner@$S.test" "$NEWPW" "$J3")
call GET /api/auth/session "$J3" "$C4"
R2=$(jval "$R" role)
[ "$R2" = "owner" ] && ok "new owner logs in" "role $R2, tools $(printf '%s' "$R" | grep -oE '"tools":\[[^]]*\]' | head -c 56)" \
|| bad "new owner logs in" "role '$R2' $(printf '%s' "$R" | head -c 140)"
rm -f "$J3"
fi
rm -f "$J2"
echo
echo "OPERATOR CONSOLE RESULT: $PASS passed, $FAIL failed"
[ "$FAIL" -gt 0 ] && exit 1 || exit 0