Set-OPS-Public/scripts/tests/test_apps_nextcloud.py

55 lines
2.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""Les applications Nextcloud viennent du depot du SITE, epinglees — plus de l'app store.
POURQUOI (2026-10-08). `occ app:install` tirait `user_oidc` et `richdocuments`
d'apps.nextcloud.com a chaque construction ; l'app store servant son catalogue a 77 ko/s,
la reconstruction de Technolibre s'est arretee. Ce test garde la declaration coherente : une
version qui differerait entre `nom` et `url` ferait tenir au site un fichier que personne ne
demande, et la divergence se lirait « le depot sert un fichier », pas « le mauvais ».
"""
from __future__ import annotations
import re
import sys
from pathlib import Path
import yaml
RACINE = Path(__file__).resolve().parents[2]
ECHECS: list[str] = []
def verifier(cond: bool, msg: str) -> None:
print(("OK " if cond else "ECHEC ") + msg)
if not cond:
ECHECS.append(msg)
def main() -> int:
apps = yaml.safe_load((RACINE / "roles/serveur_nextcloud/defaults/main.yml").read_text())["serveur_nextcloud_apps"]
verifier(len({a["id"] for a in apps}) == len(apps) and len(apps) > 0, f"{len(apps)} application(s), identifiants uniques")
for a in apps:
v, i = a["version"], a["id"]
verifier(f"-{i}-{v}." in a["nom"] and a["nom"].startswith("nextcloud-app-"), f"{i} : le nom porte l'id et la version ({a['nom']})")
verifier(f"/{i}/" in a["url"] and f"v{v}" in a["url"], f"{i} : l'url porte l'id et la version")
verifier(re.fullmatch(r"[0-9a-f]{64}", a["sha256"]) is not None, f"{i} : sha256 bien formee")
taches = (RACINE / "roles/serveur_artefacts/tasks/main.yml").read_text()
verifier("serveur_nextcloud_apps" in taches, "le site tient les applications declarees par serveur_nextcloud")
# Les commandes, pas les commentaires : `restaurer.yml` raconte encore pourquoi
# `occ app:install` refusait une base restauree trop tot.
roles = "".join(l for p in (RACINE / "roles/serveur_nextcloud/tasks").glob("*.yml")
for l in p.read_text().splitlines(keepends=True) if not l.lstrip().startswith("#"))
verifier("app:install" not in roles, "plus aucune tache ne tire une application de l'app store (`app:install`)")
for f, app in (("oidc.yml", "user_oidc"), ("collabora.yml", "richdocuments")):
t = (RACINE / "roles/serveur_nextcloud/tasks" / f).read_text()
verifier(f"serveur_nextcloud_app_id: {app}" in t, f"{f} installe {app} par app_tierce.yml")
if ECHECS:
print(f"\n{len(ECHECS)} echec(s).")
return 1
print("\nLes applications Nextcloud sont epinglees, tenues par le site, installees sans l'app store.")
return 0
if __name__ == "__main__":
sys.exit(main())