#!/usr/bin/env bash
# Run in an empty scratch directory; keep the terminal open during the scenario.
set -eu
ssh-keygen -q -t ed25519 -N '' -f ./host_key
sudo /usr/sbin/sshd -D -e -f /dev/null -h "$PWD/host_key" -p 2222 \
  -o ListenAddress=127.0.0.1 -o PidFile="$PWD/sshd.pid" &
fixture_pid=$!
trap 'kill "$fixture_pid"' EXIT
# The first connection to this fresh key must fail with exit 255 and
# "Host key verification failed." when there is no interactive terminal.
ssh -o BatchMode=no -o ConnectTimeout=10 -p 2222 127.0.0.1 true < /dev/null || true
wait "$fixture_pid"
