mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 03:14:09 +00:00
40 lines
1.6 KiB
Bash
Executable File
40 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Verify the drill's probe against both supported transports on a private broker.
|
|
set -euo pipefail
|
|
repo=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
|
|
fixture=$(mktemp -d)
|
|
name="ukmesh-restore-mqtt-$$"
|
|
image=eclipse-mosquitto@sha256:9cfdd46ad59f3e3e5f592f6baf57ab23e1ad00605509d0f5c1e9b179c5314d87
|
|
trap 'docker rm -fv "$name" >/dev/null 2>&1 || true; rm -rf -- "$fixture"' EXIT
|
|
cat >"$fixture/mosquitto.conf" <<'CONF'
|
|
listener 1883
|
|
protocol mqtt
|
|
listener 9001
|
|
protocol websockets
|
|
allow_anonymous false
|
|
password_file /mosquitto/config/passwd
|
|
acl_file /mosquitto/config/acl
|
|
CONF
|
|
export DRILL_USERNAME=drill-fixture
|
|
export DRILL_PASSWORD="$(openssl rand -hex 12)"
|
|
app_image="${APP_IMAGE:?Set APP_IMAGE to the candidate backend image}"
|
|
docker run --rm --network none --user 0 --entrypoint sh -e DRILL_USERNAME -e DRILL_PASSWORD \
|
|
-v "$fixture:/fixture" "$image" -ec '
|
|
mosquitto_passwd -b -c /fixture/passwd "$DRILL_USERNAME" "$DRILL_PASSWORD" >/dev/null
|
|
printf "user %s\ntopic readwrite restore-drill/%s\n" "$DRILL_USERNAME" "$DRILL_USERNAME" >/fixture/acl
|
|
chmod 755 /fixture
|
|
chown 1883:1883 /fixture/passwd /fixture/acl
|
|
'
|
|
docker run -d --name "$name" --network none \
|
|
-v "$fixture:/mosquitto/config:ro" "$image" >/dev/null
|
|
round_trip() {
|
|
docker run --rm -i --network "container:$name" -e DRILL_USERNAME -e DRILL_PASSWORD \
|
|
-v "$repo/scripts/lib/restore-mqtt.cjs:/app/restore-mqtt.cjs:ro" \
|
|
"$app_image" node /app/restore-mqtt.cjs <"$fixture/mosquitto.conf"
|
|
}
|
|
round_trip
|
|
if DRILL_PASSWORD=incorrect round_trip; then
|
|
echo "Round trip unexpectedly passed with incorrect credentials" >&2
|
|
exit 1
|
|
fi
|