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:
@@ -22,6 +22,9 @@ coreapps login <host> <user> keep a token (read from stdin) for
|
||||
installing private apps from host
|
||||
coreapps logout <host> forget host's token
|
||||
coreapps logins the hosts this Core has tokens for
|
||||
coreapps test-account [--remove] make (or refresh, with the password on
|
||||
stdin) the person coreapp signin signs
|
||||
in with, or remove it
|
||||
|
||||
<source> is a folder with coreapp.toml (and icon.png), or a git
|
||||
repository: https://host/owner/repo[@tag]. A private repository, and a
|
||||
@@ -1164,6 +1167,78 @@ def list_apps():
|
||||
return 0
|
||||
|
||||
|
||||
# --- The test account (coreapp signin) ---------------------------------------------
|
||||
|
||||
# A person in the Core's LDAP that coreapp signin signs in with, on a
|
||||
# developer's own Core. Its uid has a dot, which no app name has, so it is
|
||||
# never an app's mail account (coreapp-<name>).
|
||||
TEST_UID = "coreapp.test"
|
||||
TEST_DESCRIPTION = "coreapps: test account for coreapp signin"
|
||||
|
||||
|
||||
def ldap_base():
|
||||
return service_value(APPS + "/mail/.env", "LDAP_SEARCH_BASE").removeprefix("ou=people,")
|
||||
|
||||
|
||||
def ldap(args, stdin=None):
|
||||
"""Run an LDAP tool in the Core's ldap container, as its admin."""
|
||||
with open(APPS + "/ldap/.ldap.secret") as f:
|
||||
admin_pw = f.read().strip()
|
||||
return run(["docker", "exec", "-i", "ldap", args[0], "-x", "-H", "ldap://localhost",
|
||||
"-D", f"cn=admin,{ldap_base()}", "-w", admin_pw] + args[1:], input=stdin or "")
|
||||
|
||||
|
||||
def test_account(remove=False):
|
||||
"""Make or refresh the test person with the password on stdin (or
|
||||
remove it). Only an entry this made is changed."""
|
||||
domain, _ = federated_settings()
|
||||
mail = f"{TEST_UID}@{domain}"
|
||||
base = ldap_base()
|
||||
if not base or not os.path.exists(APPS + "/ldap/.ldap.secret"):
|
||||
raise Refused("Can't find the Core's LDAP settings.")
|
||||
found = ldap(["ldapsearch", "-LLL", "-o", "ldif-wrap=no", "-b", base,
|
||||
f"(|(uid={TEST_UID})(mail={mail}))", "description"])
|
||||
if found.returncode != 0:
|
||||
raise Refused(f"Can't search the Core's LDAP: {found.stderr.strip()}")
|
||||
dn = f"uid={TEST_UID},ou=people,{base}"
|
||||
ours = f"dn: {dn}\ndescription: {TEST_DESCRIPTION}"
|
||||
entries = found.stdout.strip()
|
||||
if entries and entries != ours:
|
||||
raise Refused(f"LDAP already has an entry with uid {TEST_UID} or {mail} that "
|
||||
"coreapps didn't make; left it alone.")
|
||||
if remove:
|
||||
if entries:
|
||||
out = ldap(["ldapdelete", dn])
|
||||
if out.returncode != 0:
|
||||
raise Refused(f"Can't remove {dn}: {out.stderr.strip()}")
|
||||
say(f"Removed the test account {mail}.")
|
||||
else:
|
||||
say("There's no test account.")
|
||||
return 0
|
||||
password = sys.stdin.read()
|
||||
if len(password) < 16:
|
||||
raise Refused("Give the test account's password (16 characters or more) on stdin.")
|
||||
if not entries:
|
||||
out = ldap(["ldapadd"], f"""dn: {dn}
|
||||
objectClass: inetOrgPerson
|
||||
uid: {TEST_UID}
|
||||
cn: Coreapp Test
|
||||
givenName: Coreapp
|
||||
sn: Test
|
||||
mail: {mail}
|
||||
description: {TEST_DESCRIPTION}
|
||||
userPassword: {{CRYPT}}!
|
||||
""")
|
||||
if out.returncode != 0:
|
||||
raise Refused(f"Can't add the test account: {out.stderr.strip()}")
|
||||
# The server hashes it
|
||||
out = ldap(["ldappasswd", "-T", "/dev/stdin", dn], password)
|
||||
if out.returncode != 0:
|
||||
raise Refused(f"Can't set the test account's password: {out.stderr.strip()}")
|
||||
print(mail)
|
||||
return 0
|
||||
|
||||
|
||||
# --- Command line -----------------------------------------------------------------
|
||||
|
||||
def main(args):
|
||||
@@ -1218,6 +1293,8 @@ def main(args):
|
||||
return list_logins()
|
||||
if cmd == "list" and not rest:
|
||||
return list_apps()
|
||||
if cmd == "test-account" and rest in ([], ["--remove"]):
|
||||
return test_account(remove=bool(rest))
|
||||
sys.stderr.write(__doc__.split("\n\n", 2)[2].strip() + "\n")
|
||||
return 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user