Files
Echoion/scripts/tests/test-gitea-tag-verification.sh
T
faumaray 30e669359a
Signed release / publish (push) Failing after 21s
Container CI / release-build (push) Successful in 46m58s
Release: clarify lightweight tag rejection
2026-07-26 04:03:52 +03:00

108 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)
verifier="$root/scripts/verify-gitea-release-tag.sh"
temporary=$(mktemp -d)
trap 'rm -rf -- "$temporary"' EXIT
repository="$temporary/repository"
mkdir -p "$repository"
git -C "$repository" init -q -b main
git -C "$repository" config user.name 'Echoion Release Test'
git -C "$repository" config user.email 'release-test@echoion.invalid'
ssh-keygen -q -t ed25519 -N '' -f "$temporary/release-key"
git -C "$repository" config gpg.format ssh
git -C "$repository" config user.signingkey "$temporary/release-key"
printf '%s\n' test >"$repository/source.txt"
git -C "$repository" add source.txt
git -C "$repository" commit -q -m 'Test release source'
git -C "$repository" tag -s -a v1.2.3 \
-m 'Echoion 1.2.3' \
-m $'First release-note paragraph.\n\nSecond paragraph.'
git -C "$repository" switch -q --detach v1.2.3
principal='release-test@echoion.invalid'
printf '%s %s\n' "$principal" "$(<"$temporary/release-key.pub")" \
>"$temporary/allowed-signers"
tag_object=$(git -C "$repository" rev-parse 'refs/tags/v1.2.3^{tag}')
target_commit=$(git -C "$repository" rev-parse 'refs/tags/v1.2.3^{}')
actual_target=$(
cd "$repository"
"$verifier" \
--tag v1.2.3 \
--event-sha "$tag_object" \
--allowed-signers "$temporary/allowed-signers" \
--notes-output "$temporary/notes.md"
)
test "$actual_target" = "$target_commit"
grep -Fqx 'Echoion 1.2.3' "$temporary/notes.md"
grep -Fqx 'First release-note paragraph.' "$temporary/notes.md"
grep -Fqx 'Second paragraph.' "$temporary/notes.md"
if grep -Fq -- 'SSH SIGNATURE' "$temporary/notes.md"; then
printf '%s\n' 'release notes contain the SSH signature' >&2
exit 1
fi
(
cd "$repository"
"$verifier" \
--tag v1.2.3 \
--event-sha "$target_commit" \
--allowed-signers "$temporary/allowed-signers" \
--notes-output "$temporary/notes-from-commit.md" \
>/dev/null
)
if (
cd "$repository"
"$verifier" \
--tag v1.2.3 \
--event-sha 0000000000000000000000000000000000000000 \
--allowed-signers "$temporary/allowed-signers" \
--notes-output "$temporary/rejected-notes.md" \
>/dev/null 2>&1
); then
printf '%s\n' 'mismatched event SHA was accepted' >&2
exit 1
fi
printf '%s\n' 'other@example.invalid ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA' \
>"$temporary/untrusted-signers"
if (
cd "$repository"
"$verifier" \
--tag v1.2.3 \
--event-sha "$target_commit" \
--allowed-signers "$temporary/untrusted-signers" \
--notes-output "$temporary/untrusted-notes.md" \
>/dev/null 2>&1
); then
printf '%s\n' 'untrusted SSH signer was accepted' >&2
exit 1
fi
git -C "$repository" tag lightweight "$target_commit"
lightweight_error="$temporary/lightweight-error.txt"
if (
cd "$repository"
"$verifier" \
--tag lightweight \
--event-sha "$target_commit" \
--allowed-signers "$temporary/allowed-signers" \
--notes-output "$temporary/lightweight-notes.md" \
>/dev/null 2>"$lightweight_error"
); then
printf '%s\n' 'lightweight tag was accepted' >&2
exit 1
fi
grep -Fqx \
'verify-gitea-release-tag: lightweight tags are not allowed; create a signed annotated tag' \
"$lightweight_error"
printf '%s\n' 'Gitea signed-tag verification tests passed'