Skip to content
1        10        20        30        40        50        60        701#!/usr/bin/env bash2# Smoke-test a dial broker: publish one message and read it back.3#4# Usage: scripts/check-remote.sh [base-url]5#   base-url defaults to $DIAL_URL, then https://dial.silenlocatelli.ch6#7# Prompts for the API key without echoing it. Uses a throwaway topic, so it8# does not touch real topics. Exits 0 only if every check passes.9set -euo pipefail1011BASE="${1:-${DIAL_URL:-https://dial.silenlocatelli.ch}}"12BASE="${BASE%/}"1314read -rs -p "dial API key: " KEY15echo16if [[ -z "$KEY" ]]; then17  echo "no key entered" >&218  exit 119fi2021topic="selftest-$(date +%s)-$RANDOM"22payload="ping-$(date +%s)-$RANDOM"23failures=02425pass() { printf 'PASS  %s\n' "$1"; }26fail() { printf 'FAIL  %s\n' "$1"; failures=$((failures + 1)); }2728# 1. Publish with the key. The response carries the new message id.29out=$(curl -sS --max-time 20 -w '\n%{http_code}' -X POST \30  -H "Authorization: Bearer $KEY" --data "$payload" \31  "$BASE/publish/$topic" || true)32code=$(printf '%s\n' "$out" | tail -n1)33body=$(printf '%s\n' "$out" | sed '$d')34id=$(printf '%s' "$body" | sed -n 's/.*"id":\([0-9]*\).*/\1/p')35if [[ "$code" == 201 && -n "$id" ]]; then36  pass "publish with key (id $id)"37else38  fail "publish with key: HTTP $code $body"39fi4041# 2. Subscribe from just before that id and look for our payload.42if [[ -n "$id" ]]; then43  out=$(curl -sS --max-time 20 -w '\n%{http_code}' \44    -H "Authorization: Bearer $KEY" \45    "$BASE/subscribe/$topic?after=$((id - 1))" || true)46  code=$(printf '%s\n' "$out" | tail -n1)47  body=$(printf '%s\n' "$out" | sed '$d')48  if [[ "$code" == 200 && "$body" == *"\"payload\":\"$payload\""* ]]; then49    pass "subscribe returns the published message"50  else51    fail "subscribe: HTTP $code $body"52  fi53fi5455# 3. Without the key, publish must be refused.56code=$(curl -sS --max-time 20 -o /dev/null -w '%{http_code}' -X POST \57  --data "unauthenticated" "$BASE/publish/$topic" || true)58if [[ "$code" == 401 ]]; then59  pass "publish without key is rejected (401)"60else61  fail "publish without key returned HTTP $code (expected 401)"62fi6364echo65if (( failures == 0 )); then66  echo "all checks passed against $BASE"67else68  echo "$failures check(s) failed against $BASE"69fi70exit $(( failures > 0 ))