diff --git a/doc/tests.md b/doc/tests.md index 0d266cf..ab5dbe3 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -22,7 +22,7 @@ lance qu'une partie (`ctest -R progress`). | `package-utils-test` | Logique partagée de `package-manager.h` : fusion des doublons entre fournisseurs, tri par fournisseur puis par nom. | Aucune. | | `progress-tracker-test` | `ProgressTracker` : compteurs pacman/Flatpak, pourcentages seuls, phases pondérées, étapes non identifiables, monotonie, faux positifs ; exécution d'une commande (`/bin/sh` en une ligne) : suppression des séquences ANSI, remontage d'une sortie au fil de l'eau, dernière ligne sans retour à la ligne, jalons de progression d'une jauge « sur place ». | Aucune, **même pas Qt**. | | `plugin-shop-test` | Format du catalogue (valide, invalide, entrées incomplètes) et comptabilité d'installation/désinstallation dans un dossier temporaire. | Qt Core + Network, aucun accès réseau. | -| `app-core-test` | La couche logique : portes d'entrée (opération en cours, mot de passe, providers), file d'attente des listes, historique, mode d'identification, refus d'un fichier qu'aucun fournisseur ne sait installer. | Qt Core seulement — **pas** QtWidgets. | +| `app-core-test` | La couche logique : portes d'entrée (opération en cours, mot de passe, providers), file d'attente des listes, historique, mode d'identification, refus d'un fichier qu'aucun fournisseur ne sait installer ; **porte du mot de passe** : chaque chemin privilégié (install, suppression, mise à jour, globale, rafraîchissement, caches, nettoyage groupé, suppression d'une ou de plusieurs installations, libération du verrou) s'arrête là, sans lancer de commande, et sa demande reste rejouable. | Qt Core seulement — **pas** QtWidgets. | | `update-manager-test` | Comparaison de versions, choix de la méthode de mise à jour, et le script d'installation, exécuté pour de vrai contre un binaire en cours d'exécution. | Qt Core + Network. | ### Pourquoi `app-core-test` ne lie pas QtWidgets diff --git a/src/app-core.cpp b/src/app-core.cpp index 7d83597..6a4022e 100644 --- a/src/app-core.cpp +++ b/src/app-core.cpp @@ -684,6 +684,11 @@ AppCore::StartResult AppCore::startRequest(Request request) { return refused(QStringLiteral("Aucun paquet sélectionné n'est supprimable.")); } m_cleanupRemovalDescription = request.description; + // The gate has to see who the groups belong to: a bulk removal of pacman + // packages is a privileged operation like any other, and without them + // here it would run `sudo` with an empty password instead of asking — + // which only works by accident, when sudo's timestamp is still valid. + for (const auto& group : m_pendingRemovals) providers.push_back(group.first); bulk = true; } else if (action == QLatin1String("install-plugin-tool")) { if (!m_pacman || !m_pacman->isAvailable()) { diff --git a/tests/app-core.test.cpp b/tests/app-core.test.cpp index 48eebde..5fc66c8 100644 --- a/tests/app-core.test.cpp +++ b/tests/app-core.test.cpp @@ -84,7 +84,7 @@ void testPrivilegedActionAsksForThePasswordFirst() { if (!core.hasAvailableProvider()) return; // nothing to update on this box // No password captured yet: the request is refused but kept pending, so the - // view can prompt and replay it. + // view can prompt and replay. const AppCore::StartResult result = core.updateAll(); assert(!result.started); if (result.needsPassword) { @@ -96,6 +96,64 @@ void testPrivilegedActionAsksForThePasswordFirst() { } } +// Every way into a privileged operation must stop at the same door, and must +// leave the request waiting to be replayed. A privileged path that skipped the +// gate would run `sudo` with an empty password and fail with a raw sudo error +// instead of asking. +// +// Nothing is ever replayed here: doing so would really run pacman as root. The +// pending request is dropped instead, exactly as a cancelled prompt would. +void testEveryPrivilegedPathAsksForThePassword() { + AppCore core; + if (!core.hasAvailableProvider()) return; // nothing privileged on this box + + PackageInfo pkg; + pkg.name = "firefox"; + pkg.provider = "pacman"; + + const auto check = [&](const AppCore::StartResult& result) { + assert(!result.started); + // Refused before the password? Then this box has no privileged tool (no + // pacman, no sudo) and there is nothing to check. + if (!result.needsPassword) return; + // The view can prompt, and the request is waiting for it. + assert(core.hasPendingRequest()); + // Replaying without a password must land on the very same door, and + // leave the request waiting again: a request mangled on its way through + // (a lost target, a lost package) would be refused earlier instead. + const AppCore::StartResult replayed = core.retryPendingRequest(); + assert(!replayed.started); + assert(replayed.needsPassword); + assert(core.hasPendingRequest()); + core.cancelPendingRequest(); + assert(!core.hasPendingRequest()); + }; + + check(core.install(pkg)); + check(core.remove(pkg)); + check(core.update(pkg)); + check(core.updateAll()); + check(core.refresh()); + check(core.cleanCaches()); + check(core.removePackages({pkg}, QStringLiteral("un paquet"))); + // The two ways of acting on one copy of a package the provider holds several + // of: one target, and several at once. Both are privileged when the owner is + // pacman, so both must ask first. + check(core.removeInstances(pkg, {"user:firefox/x86_64/stable"})); + check(core.removeInstances( + pkg, {"user:firefox/x86_64/stable", "system:firefox/x86_64/stable"})); + // An empty pick is the plain removal, and goes through the same door. + check(core.removeInstances(pkg, {})); + + // Releasing the database lock is privileged too, and has its own door. + const AppCore::StartResult lock = core.releaseDatabaseLock(); + assert(!lock.started); + if (lock.needsPassword) { + assert(core.hasPendingRequest()); + core.cancelPendingRequest(); + } +} + void testCredentialsStayInTheCore() { AppCore core; assert(!core.hasSudoPassword()); @@ -215,6 +273,7 @@ int main(int argc, char* argv[]) { testFileInstallRefusesWhatNoProviderKnows(); testBulkRemovalRefusesAnEmptySelection(); testPrivilegedActionAsksForThePasswordFirst(); + testEveryPrivilegedPathAsksForThePassword(); testCredentialsStayInTheCore(); testCredentialModeIsPersistedAndReported(); testRetryWithoutAPendingRequestIsRefused();