fix(credentials): ask for the password before a bulk removal
The cleanup page grouped its packages by provider but never handed those providers to the credential gate, which saw an empty list, concluded nothing was privileged and let the request through: pacman was then driven with an empty password. It only worked by accident, while sudo's timestamp was still valid. Every privileged path now goes through the same door, which the new test walks one by one — including the two ways of acting on a single copy of a multi-installed package — and asserts the request is refused, kept pending for the prompt, and refused again on replay. Nothing is ever replayed, so no test can run pacman as root.
This commit is contained in:
3 files changed
+66
-2
No files matched your search
+60
-1
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user