run-policy-test.sh raw
1 #!/bin/bash
2 set -euo pipefail
3
4 # Config
5 PORT=${PORT:-34567}
6 URL=${URL:-ws://127.0.0.1:${PORT}}
7 LOG=/tmp/orly-policy.out
8 PID=/tmp/orly-policy.pid
9 DATADIR=$(mktemp -d)
10
11 cleanup() {
12 trap - EXIT
13 if [[ -f "$PID" ]]; then
14 kill -INT "$(cat "$PID")" 2>/dev/null || true
15 rm -f "$PID"
16 fi
17 rm -rf "$DATADIR"
18 }
19 trap cleanup EXIT
20
21 echo "Building relay and test client..."
22 go build -o orly .
23 go build -o cmd/policytest/policytest ./cmd/policytest
24
25 echo "Starting relay on ${URL} with policy enabled (data dir: ${DATADIR})..."
26 ORLY_DATA_DIR="$DATADIR" \
27 ORLY_PORT=${PORT} \
28 ORLY_POLICY_ENABLED=true \
29 ORLY_ACL_MODE=none \
30 ORLY_LOG_LEVEL=trace \
31 ./orly >"$LOG" 2>&1 & echo $! >"$PID"
32
33 sleep 1
34 if ! ps -p "$(cat "$PID")" >/dev/null 2>&1; then
35 echo "Relay failed to start; logs:" >&2
36 sed -n '1,200p' "$LOG" >&2
37 exit 1
38 fi
39
40 echo "Running policy test against ${URL}..."
41 set +e
42 out=$(cmd/policytest/policytest -url "${URL}" 2>&1)
43 rc=$?
44 set -e
45 echo "$out"
46
47 # Expect rejection; return 0 if we saw REJECT, else forward exit code
48 if grep -q '^REJECT:' <<<"$out"; then
49 exit 0
50 fi
51 exit $rc
52
53
54