fix(credentials): run sudo without a password when the account has none

A passwordless sudo setup (NOPASSWD, or an account without a password) was
still asked for a password: leaving the field empty never satisfied the gate,
so the dialog reopened and the operation could not run at all.

The gate now asks sudo itself (`sudo -n true`) and lets the request through
when it needs nothing, privileged commands fall back to `sudo -n` when no
password is held, and an empty field cancels instead of looping. Releasing the
lock records its own pending request so an answered prompt is replayed rather
than lost.
This commit is contained in:
BlackAngelTV committed 2026-11-11 18:49:55 +01:00
1 parent d27792975e
commit 97d99c63a2
9 files changed
+131 -24

No files matched your search

+11
View File
@@ -83,6 +83,9 @@ void testBulkRemovalRefusesAnEmptySelection() {
void testPrivilegedActionAsksForThePasswordFirst() {
AppCore core;
if (!core.hasAvailableProvider()) return; // nothing to update on this box
// A passwordless sudo setup has nothing to ask (and the request would
// really update the machine): there is no dialog to check here.
if (!core.sudoRequiresPassword()) return;
// No password captured yet: the request is refused but kept pending, so the
// view can prompt and replay.
@@ -107,6 +110,9 @@ void testPrivilegedActionAsksForThePasswordFirst() {
void testEveryPrivilegedPathAsksForThePassword() {
AppCore core;
if (!core.hasAvailableProvider()) return; // nothing privileged on this box
// Without a password to ask for, the gate accepts every path: nothing is
// left waiting for the view, and nothing is run to check it here.
if (!core.sudoRequiresPassword()) return;
PackageInfo pkg;
pkg.name = "firefox";
@@ -163,6 +169,11 @@ void testCredentialsStayInTheCore() {
assert(core.hasSudoPassword());
core.clearSudoPassword();
assert(!core.hasSudoPassword());
// An empty password is not a secret: it means "none", which the
// passwordless-sudo path handles instead of storing an empty string.
core.setSudoPassword(QString());
assert(!core.hasSudoPassword());
}
void testCredentialModeIsPersistedAndReported() {