Files
HomerandClaude Opus 5.5 b52263d0bb Security (S11, S14, S16): the shell's own autocomplete is gone; least privilege in CI; set-up refuses root and another version's release
S11. autocomplete = 'shell' had the shell integration send what was typed
to the engine itself: it could not see a private pane or the AI switch,
and had its own timeout and no chosen model. autocomplete.bash and
autocomplete.zsh are removed, with what exported their switch; the shell
integration keeps its zones and the status record. 'shell' turns nothing
on and is said in the log.

S14. The build job may only read the repository; a job of its own,
for a tag only and after the build passed, downloads the build's artefact
and publishes the release with write access. Every action is pinned by
its commit, with the tag it was taken from beside it.

S16. The set-up program refuses to run as root (everything goes into the
person's own home). A signed SHA256SUMS whose first line names a product
and version must name the release asked for: an older signed release served
under the newest tag is refused. Sums that name nothing yet are still taken,
and that is said. Tests for both, and for the root refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 08:07:20 +00:00

127 lines
7.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# The set-up program without a network: what it says when everything is there, what it would do
# when nothing is, and that a release that is not signed by the release key is refused.
#
# llembas/tests/setup-test.sh
set -uo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
SETUP="$ROOT/llembas/setup/llembas-term-setup"
work="$(mktemp -d)"
trap 'rm -rf "${work:?}"' EXIT
failed=0
ok() { echo "ok $1"; }
bad() {
echo "FAIL $1"
[ -z "${GITHUB_ACTIONS:-}" ] || printf '::error title=setup::%s\n' "$(printf '%s' "$1" | head -c 900 | tr '\n\r' ' ')"
failed=1
}
expect() { if printf '%s' "$2" | grep -Eq -- "$3"; then ok "$1"; else bad "$1: wanted /$3/ in: $2"; fi; }
refuse() { if printf '%s' "$2" | grep -Eq -- "$3"; then bad "$1: found /$3/ in: $2"; else ok "$1"; fi; }
# A home with nothing in it, and only the system's tools on PATH.
run() { # home, then the program's arguments and environment through env
local home="$1"
shift
env -i PATH=/usr/bin:/bin HOME="$home" LANG=C.UTF-8 "$@" </dev/null 2>&1
}
mkdir -p "$work/empty" "$work/full/.local/bin"
printf '#!/bin/sh\necho 2.0.0-beta.18\n' >"$work/full/.local/bin/lembas"
printf '#!/bin/sh\n' >"$work/full/.local/bin/llembas-ide"
chmod +x "$work/full/.local/bin/lembas" "$work/full/.local/bin/llembas-ide"
out="$(run "$work/full" bash "$SETUP" --yes)"
expect "what is installed is found in ~/.local/bin, off PATH" "$out" "the LLeMbas CLI is installed: $work/full/.local/bin/lembas \(2\.0\.0-beta\.18\)"
expect "and LLeMbas IDE" "$out" "LLeMbas IDE is installed: $work/full/.local/bin/llembas-ide"
expect "it says how to log in" "$out" "lembas login"
refuse "and installs nothing" "$out" "installing|would find"
out="$(run "$work/empty" bash "$SETUP" --dry-run)"
expect "dry run: the CLI would be installed" "$out" "LLeMbas CLI \(lembas\) is not installed"
expect "dry run: from the stable releases by default" "$out" "would find the newest stable release of LLeMbas/LLeMbas-CLI"
expect "dry run: the IDE too" "$out" "would find the newest stable release of LLeMbas/LLeMbas-IDE"
if [ -z "$(find "$work/empty" -mindepth 1 | head -n1)" ]; then ok "a dry run writes nothing"; else bad "a dry run wrote: $(find "$work/empty" -mindepth 1 | head)"; fi
out="$(run "$work/empty" LLEMBAS_TERM=1.0.0-beta.3 bash "$SETUP" --dry-run --no-ide)"
expect "a beta terminal asks for the betas" "$out" "newest beta release of LLeMbas/LLeMbas-CLI"
refuse "--no-ide leaves the IDE out" "$out" "LLeMbas-IDE"
out="$(run "$work/empty" bash "$SETUP")"
expect "nobody to answer: nothing is installed" "$out" "not installed$"
if [ -z "$(find "$work/empty" -mindepth 1 | head -n1)" ]; then ok "and nothing is written"; else bad "written without an answer: $(find "$work/empty" -mindepth 1 | head)"; fi
# As root: refused, before anything is looked at (`id` stands in for root here).
mkdir -p "$work/root/bin" "$work/rootless"
printf '#!/bin/sh\necho 0\n' >"$work/root/bin/id"
chmod +x "$work/root/bin/id"
out="$(env -i PATH="$work/root/bin:/usr/bin:/bin" HOME="$work/rootless" LANG=C.UTF-8 bash "$SETUP" --yes </dev/null 2>&1)"
expect "it refuses to run as root" "$out" "not as root"
if [ -z "$(find "$work/rootless" -mindepth 1 | head -n1)" ]; then ok "and writes nothing"; else bad "as root it wrote: $(find "$work/rootless" -mindepth 1 | head)"; fi
# The shell integration's line of the terminal's old name in an rc file: the new line is said,
# and the file is not touched.
mkdir -p "$work/rc/.local/bin"
cp "$work/full/.local/bin/lembas" "$work/full/.local/bin/llembas-ide" "$work/rc/.local/bin/"
# shellcheck disable=SC2016 # as a person wrote it in their rc file
printf '%s\n' 'export EDITOR=vi' '[ -n "$LLEMBAS_TTY" ] && . /usr/share/llembas-tty/shell/llembas-tty.sh' >"$work/rc/.zshrc"
before="$(sha256sum <"$work/rc/.zshrc")"
out="$(run "$work/rc" bash "$SETUP" --yes)"
expect "an rc file with the old name's line is named" "$out" "$work/rc/\.zshrc still has the shell integration's line"
# shellcheck disable=SC2016 # a pattern for the line as it is printed
expect "with the line that replaces it" "$out" '\[ -n "\$LLEMBAS_TERM" \] && \. /.*share/llembas-term/shell/llembas-term\.sh'
if [ "$(sha256sum <"$work/rc/.zshrc")" = "$before" ]; then ok "and the rc file is not changed"; else bad "the rc file was changed"; fi
out="$(run "$work/full" bash "$SETUP" --yes)"
refuse "no rc file with it: nothing is said of it" "$out" "old name"
# A release on this machine: a listing, an installer that would leave a mark, and sums.
rel="$work/forge/LLeMbas/LLeMbas-CLI/releases/download/v9.9.9"
mkdir -p "$rel" "$work/api/repos/LLeMbas/LLeMbas-CLI"
printf '[{"tag_name": "v9.9.9-beta.1", "prerelease": true}, {"tag_name": "v9.9.9", "prerelease": false}]' >"$work/api/repos/LLeMbas/LLeMbas-CLI/releases"
# shellcheck disable=SC2016 # written into the stand-in installer as it is
printf '#!/bin/sh\necho "ran with ref=$LEMBAS_REF" > "$HOME/ran"\n' >"$rel/get.sh"
(cd "$rel" && sha256sum get.sh >SHA256SUMS)
ssh-keygen -q -t ed25519 -N '' -C test -f "$work/key" >/dev/null
ssh-keygen -q -t ed25519 -N '' -C other -f "$work/other" >/dev/null
local_forge=(LLEMBAS_SETUP_FORGE="file://$work/forge" LLEMBAS_SETUP_API="file://$work/api" LLEMBAS_SETUP_PUBKEY="$(cut -d' ' -f1,2 "$work/key.pub")")
mkdir -p "$work/h1" "$work/h2" "$work/h3" "$work/h4"
out="$(run "$work/h1" "${local_forge[@]}" bash "$SETUP" --yes --no-ide)"
expect "an unsigned release is refused" "$out" "is not signed \(no SHA256SUMS.sig\)"
if [ ! -e "$work/h1/ran" ]; then ok "and its installer does not run"; else bad "an unsigned installer ran"; fi
ssh-keygen -Y sign -q -f "$work/other" -n lembas-release "$rel/SHA256SUMS"
out="$(run "$work/h2" "${local_forge[@]}" bash "$SETUP" --yes --no-ide)"
expect "a release signed with another key is refused" "$out" "not signed by the LLeMbas release key"
if [ ! -e "$work/h2/ran" ]; then ok "and its installer does not run"; else bad "an installer signed by another key ran"; fi
rm -f "$rel/SHA256SUMS.sig"
ssh-keygen -Y sign -q -f "$work/key" -n lembas-release "$rel/SHA256SUMS"
printf '\n# changed after signing\n' >>"$rel/get.sh"
out="$(run "$work/h3" "${local_forge[@]}" bash "$SETUP" --yes --no-ide)"
expect "an installer that does not match the signed sums is refused" "$out" "does not match its SHA256SUMS"
if [ ! -e "$work/h3/ran" ]; then ok "and does not run"; else bad "a changed installer ran"; fi
# Signed sums of another release, served under this tag (a signed downgrade): refused when the
# sums name their release.
(cd "$rel" && { echo '# lembas 9.9.8'; sha256sum get.sh; } >SHA256SUMS) && rm -f "$rel/SHA256SUMS.sig"
ssh-keygen -Y sign -q -f "$work/key" -n lembas-release "$rel/SHA256SUMS"
mkdir -p "$work/h5"
out="$(run "$work/h5" "${local_forge[@]}" bash "$SETUP" --yes --no-ide)"
expect "signed sums of another release under this tag are refused" "$out" "is of another release \(it says: lembas 9\.9\.8\)"
if [ ! -e "$work/h5/ran" ]; then ok "and its installer does not run"; else bad "the installer of another release ran"; fi
(cd "$rel" && { echo '# lembas 9.9.9'; sha256sum get.sh; } >SHA256SUMS) && rm -f "$rel/SHA256SUMS.sig"
ssh-keygen -Y sign -q -f "$work/key" -n lembas-release "$rel/SHA256SUMS"
out="$(run "$work/h4" "${local_forge[@]}" bash "$SETUP" --yes --no-ide)"
expect "a signed, matching release is installed" "$out" "LLeMbas CLI v9\.9\.9: signature good, installing"
refuse "sums that name this release: nothing said of it" "$out" "does not name its release"
expect "the stable channel takes the release, not the beta beside it" "$(cat "$work/h4/ran" 2>/dev/null)" "^ran with ref=v9\.9\.9$"
(cd "$rel" && sha256sum get.sh >SHA256SUMS) && rm -f "$rel/SHA256SUMS.sig" "$work/h4/ran"
ssh-keygen -Y sign -q -f "$work/key" -n lembas-release "$rel/SHA256SUMS"
out="$(run "$work/h4" "${local_forge[@]}" bash "$SETUP" --yes --no-ide)"
expect "sums that do not name a release yet: installed, and said" "$out" "does not name its release"
expect "and it ran" "$(cat "$work/h4/ran" 2>/dev/null)" "^ran with ref=v9\.9\.9$"
[ "$failed" -eq 0 ] && echo "setup: all passed"
exit "$failed"