Add coreapp signin: test an app's sign-in on the Core, as a browser would

The Vikunja rehearsal's agent could only test sign-in against a stand-in
Authelia. coreapp signin follows the app's sign-in through the Core's real
Authelia as a test person (coreapp.test, made by coreapps test-account
with a new random password each run, kept nowhere), prints each step with
Authelia's errors, and says whether it got back to the app signed in.
--code covers apps that start sign-in in the browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 17:57:48 -07:00
co-authored by Claude Opus 5.5
parent 5d06f1bd9b
commit da767e2139
8 changed files with 422 additions and 15 deletions
+58 -1
View File
@@ -13,6 +13,13 @@
# coreapp status its container, address and URL
# coreapp logs [-f] its log
# coreapp shell [command] a shell in its container, or run one command there
# coreapp signin [path] sign in to it with the Core's test account, as a
# browser would, starting at path (default /login);
# --cookies <file> keeps the app's cookies
# coreapp signin --code for sign-in started in the browser's JavaScript:
# get a code for the app's callback from Authelia
# coreapp signin --remove-account
# remove the test account from the Core
# coreapp remove uninstall it from the Core (asks first)
# coreapp list the apps on the Core installed this way
# coreapp install <https://host/owner/repo>[@tag]
@@ -27,7 +34,7 @@
# build the release image and push it to the
# registry in coreapp.toml, and tag the commit
#
# Run deploy, check, status, logs, shell, remove and publish in the app's
# Run deploy, check, status, logs, shell, signin, remove and publish in the app's
# folder (the one with coreapp.toml). COREAPP_VM picks the VM (default coreserver).
set -euo pipefail
@@ -37,6 +44,7 @@ TEMPLATES="$(dirname "$SELF_DIR")/templates"
TEMPLATE="$TEMPLATES/app"
# The installer that runs on the Core (coreapps), and where it goes there
INSTALLER="$(dirname "$SELF_DIR")/core"
SIGNIN="$(dirname "$SELF_DIR")/lib/signin.py"
REMOTE_INSTALLER=/opt/coreapps
DATA="$HOME/.local/share/coreapp-dev"
SSH_KEY="$DATA/ssh/id_ed25519"
@@ -90,6 +98,7 @@ core_domain() {
# From coreapp.toml, as checked by the installer
NAME="" TITLE="" VERSION="" IMAGE="" PORT="" HEALTH="" NEEDS="" ICON="" ICON_NOTE=""
SSO_CALLBACK="" SSO_PKCE=""
load_app() {
load_manifest
init_core
@@ -112,6 +121,8 @@ load_manifest() {
needs) NEEDS="$value" ;;
icon) ICON="$value" ;;
icon_note) ICON_NOTE="$value" ;;
sso_callback) SSO_CALLBACK="$value" ;;
sso_pkce) SSO_PKCE="$value" ;;
esac
done <<< "$values"
}
@@ -329,6 +340,51 @@ cmd_shell() {
fi
}
# --- signin -----------------------------------------------------------------
# The Core's test account (a person in its LDAP, made by coreapps
# test-account) gets a new random password each time, given to the Core and
# to signin.py on stdin, and kept nowhere
cmd_signin() {
local path="" cookies="" code=0 domain password account issuer client pkce
while [[ $# -gt 0 ]]; do
case "$1" in
--code) code=1 ;;
--cookies)
[[ $# -ge 2 ]] || die "--cookies needs a file: coreapp signin --cookies <file> [path]"
cookies="$2"; shift ;;
--remove-account)
init_core; sync_installer
core "$REMOTE_INSTALLER/coreapps test-account --remove"
return ;;
/*) [[ -z "$path" ]] || die "One path: coreapp signin [path]"; path="$1" ;;
*) die "coreapp signin [--cookies <file>] [path], coreapp signin --code, or coreapp signin --remove-account (a path starts with /)" ;;
esac
shift
done
load_app
[[ " $NEEDS " == *" sso "* ]] \
|| die "$NAME doesn't sign in with Core accounts (no \"sso\" in coreapp.toml's needs)."
domain="$(core_domain)"
sync_installer
password="$(python3 -c 'import secrets; print(secrets.token_urlsafe(24))')"
account="$(printf '%s' "$password" | core "$REMOTE_INSTALLER/coreapps test-account")" || exit 1
echo "Signing in to $NAME as the Core's test account, $account:"
if ((code)); then
issuer="$(core "sed -n 's/^OIDC_ISSUER=//p' /federated/apps/$NAME/.env 2> /dev/null")"
client="$(core "sed -n 's/^OIDC_CLIENT_ID=//p' /federated/apps/$NAME/.env 2> /dev/null")"
[[ -n "$issuer" && -n "$client" ]] \
|| die "$NAME isn't installed on the Core with sign-in yet: coreapp deploy"
pkce=()
[[ "$SSO_PKCE" == true ]] && pkce=(--pkce)
printf '%s' "$password" | python3 "$SIGNIN" --code "${pkce[@]}" \
"$issuer" "$client" "https://$NAME.$domain$SSO_CALLBACK" "$account"
else
printf '%s' "$password" | python3 "$SIGNIN" ${cookies:+--cookies "$cookies"} \
"https://$NAME.$domain${path:-/login}" "$account"
fi
}
cmd_remove() {
local answer
load_app
@@ -528,6 +584,7 @@ case "$cmd" in
status) cmd_status ;;
logs) cmd_logs "$@" ;;
shell) cmd_shell "$@" ;;
signin) cmd_signin "$@" ;;
remove | rm) cmd_remove ;;
list | ls) cmd_list ;;
publish) cmd_publish "$@" ;;