Files
Echoion/scripts/tests/test-component-ssh-secrets.sh
faumaray 697db046d3
Modular container CI / release-build (push) Has been cancelled
Release: harden multiline secret handling
2026-07-30 03:58:21 +03:00

39 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)
# shellcheck source=scripts/lib/component-ssh.sh
source "$root/scripts/lib/component-ssh.sh"
temporary=$(mktemp -d)
trap 'rm -rf -- "$temporary"' EXIT
ssh-keygen -q -t ed25519 -N '' -f "$temporary/source-key"
encoded=$(base64 -w0 "$temporary/source-key")
echoion_decode_base64_secret "$encoded" "$temporary/decoded-key"
cmp -- "$temporary/source-key" "$temporary/decoded-key"
echoion_configure_component_ssh "$temporary/credentials" "$encoded"
expected_public=$(ssh-keygen -y -f "$temporary/source-key")
actual_public=$(ssh-keygen -y -f "$temporary/credentials/component-ssh-key")
test "$actual_public" = "$expected_public"
test -n "$GIT_SSH_COMMAND"
if echoion_decode_base64_secret \
"$(<"$temporary/source-key")" "$temporary/rejected-raw-key" \
>/dev/null 2>&1
then
echo "raw multiline private key was accepted" >&2
exit 1
fi
if echoion_decode_base64_secret 'not-base64!' "$temporary/rejected-invalid-key" \
>/dev/null 2>&1
then
echo "invalid base64 private key was accepted" >&2
exit 1
fi
echo "component SSH secret encoding tests passed"