#!/usr/bin/env bash # Integration test: the device HttpClient + auth signer against the REAL backend prototype. # Starts the webrick backend with auth enforced, POSTs a signed webhook, asserts accept/reject. # Run: bash components/dialer-patch/tests/integration.sh set -uo pipefail cd "$(dirname "$0")/.." # -> components/dialer-patch PORT=4055 JAVAC=$(ls /build/grapheneos/prebuilts/jdk/jdk*/linux-x86/bin/javac 2>/dev/null | head -1); [ -x "$JAVAC" ] || JAVAC=$(command -v javac) JAVA=$(ls /build/grapheneos/prebuilts/jdk/jdk*/linux-x86/bin/java 2>/dev/null | head -1); [ -x "$JAVA" ] || JAVA=$(command -v java) OUT=$(mktemp -d) mapfile -t SRCS < <(find overlay tests -name '*.java') "$JAVAC" -encoding UTF-8 -d "$OUT" "${SRCS[@]}" || { echo "COMPILE FAILED"; exit 1; } # start the backend (auth enforced = defaults) on a private port fuser -k "$PORT/tcp" 2>/dev/null HELPDESK_AUTH=1 PORT=$PORT ruby ../backend/server.rb >/tmp/helpdesk-it-backend.log 2>&1 & BPID=$! trap 'kill "$BPID" 2>/dev/null' EXIT curl -s --retry 25 --retry-connrefused --retry-delay 1 -o /dev/null "http://localhost:$PORT/healthz" \ || { echo "backend did not come up"; cat /tmp/helpdesk-it-backend.log; exit 1; } RES=$("$JAVA" -cp "$OUT" com.android.dialer.helpdesk.http.HelpdeskHttpClientIT "http://localhost:$PORT/api/v1") echo "$RES" v=$(echo "$RES" | sed -n 's/VALID_STATUS=//p') t=$(echo "$RES" | sed -n 's/TAMPERED_STATUS=//p') bt=$(echo "$RES" | sed -n 's/BADTOKEN_STATUS=//p') fail=0 [ "$v" = "200" ] && echo " ok valid signed /calls/incoming accepted (200)" || { echo " FAIL valid=$v"; fail=1; } [ "$t" = "401" ] && echo " ok tampered signature rejected (401)" || { echo " FAIL tampered=$t"; fail=1; } [ "$bt" = "401" ] && echo " ok wrong bearer token rejected (401)" || { echo " FAIL badtoken=$bt"; fail=1; } echo; [ "$fail" = 0 ] && echo "INTEGRATION GREEN" || echo "INTEGRATION FAIL" exit $fail