@@ -326,6 +326,26 @@ describe("systemd availability", () => {
|
326 | 326 | expect(execFileMock).toHaveBeenCalledTimes(1); |
327 | 327 | }); |
328 | 328 | |
| 329 | +it("keeps root user scope when stale SUDO_USER is paired with root bus environment", async () => { |
| 330 | +mockEffectiveUid(0); |
| 331 | +execFileMock.mockImplementationOnce((_cmd, args, _opts, cb) => { |
| 332 | +assertUserSystemctlArgs(args, "status"); |
| 333 | +cb(null, "", ""); |
| 334 | +}); |
| 335 | + |
| 336 | +await expect( |
| 337 | +isSystemdUserServiceAvailable({ |
| 338 | +HOME: "/root", |
| 339 | +USER: "root", |
| 340 | +LOGNAME: "root", |
| 341 | +SUDO_USER: "debian", |
| 342 | +XDG_RUNTIME_DIR: "/run/user/0", |
| 343 | +DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/0/bus", |
| 344 | +}), |
| 345 | +).resolves.toBe(true); |
| 346 | +expect(execFileMock).toHaveBeenCalledTimes(1); |
| 347 | +}); |
| 348 | + |
329 | 349 | it("does not let stale SUDO_USER override a sudo-u target user scope", async () => { |
330 | 350 | mockEffectiveUid(1000); |
331 | 351 | execFileMock.mockImplementationOnce((_cmd, args, _opts, cb) => { |
@@ -2049,6 +2069,27 @@ describe("systemd service control", () => {
|
2049 | 2069 | await assertRestartSuccess({ SUDO_USER: "debian" }); |
2050 | 2070 | }); |
2051 | 2071 | |
| 2072 | +it("restarts root user services directly when stale SUDO_USER is paired with root bus environment", async () => { |
| 2073 | +mockEffectiveUid(0); |
| 2074 | +execFileMock |
| 2075 | +.mockImplementationOnce((_cmd, args, _opts, cb) => { |
| 2076 | +assertUserSystemctlArgs(args, "status"); |
| 2077 | +cb(null, "", ""); |
| 2078 | +}) |
| 2079 | +.mockImplementationOnce((_cmd, args, _opts, cb) => { |
| 2080 | +assertUserSystemctlArgs(args, "restart", GATEWAY_SERVICE); |
| 2081 | +cb(null, "", ""); |
| 2082 | +}); |
| 2083 | +await assertRestartSuccess({ |
| 2084 | +HOME: "/root", |
| 2085 | +USER: "root", |
| 2086 | +LOGNAME: "root", |
| 2087 | +SUDO_USER: "debian", |
| 2088 | +XDG_RUNTIME_DIR: "/run/user/0", |
| 2089 | +DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/0/bus", |
| 2090 | +}); |
| 2091 | +}); |
| 2092 | + |
2052 | 2093 | it("keeps direct --user scope when SUDO_USER is root", async () => { |
2053 | 2094 | execFileMock |
2054 | 2095 | .mockImplementationOnce((_cmd, args, _opts, cb) => { |
|