Skip to content

Commit 6cfe755

Browse files
committed
fix(global): refresh dns recovery sudoers rule
1 parent bd2c074 commit 6cfe755

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/commands/global.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,7 @@ async function globalAuthorize(): Promise<number> {
792792
return 1;
793793
}
794794

795-
if (await pathExists(MAC_DNS_SUDOERS_PATH)) {
796-
logger.info({
797-
message: `${MAC_DNS_SUDOERS_PATH} already installed`,
798-
});
799-
return 0;
800-
}
795+
const sudoersRuleExists = await pathExists(MAC_DNS_SUDOERS_PATH);
801796

802797
const brew = await findExecutableInPath("brew");
803798
if (!brew) {
@@ -826,6 +821,12 @@ async function globalAuthorize(): Promise<number> {
826821
return 0;
827822
}
828823

824+
if (sudoersRuleExists) {
825+
logger.info({
826+
message: `Refreshing ${MAC_DNS_SUDOERS_PATH}`,
827+
});
828+
}
829+
829830
const tempDir = resolve(getGlobalPaths().root, "tmp");
830831
await ensureDir(tempDir);
831832
const tempPath = resolve(tempDir, MAC_DNS_SUDOERS_TEMP_FILENAME);

tests/global-command.macos.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,39 @@ test("global authorize installs passwordless dns recovery sudoers rule", async (
316316
);
317317
});
318318

319+
test("global authorize refreshes an existing dns recovery sudoers rule", async () => {
320+
pathExistsOverrides.set("/etc/sudoers.d/dance.hack-dns-recovery", true);
321+
322+
const { runCli } = await import("../src/cli/run.ts");
323+
const code = await runCli(["global", "authorize"]);
324+
325+
expect(code).toBe(0);
326+
expect(runCalls).toEqual(
327+
expect.arrayContaining([
328+
[
329+
"/usr/bin/mock-bin",
330+
"-cf",
331+
expect.stringContaining("dance.hack-dns-recovery.sudoers"),
332+
],
333+
["sudo", "install", "-d", "-m", "0755", "/etc/sudoers.d"],
334+
[
335+
"sudo",
336+
"install",
337+
"-m",
338+
"0440",
339+
expect.stringContaining("dance.hack-dns-recovery.sudoers"),
340+
"/etc/sudoers.d/dance.hack-dns-recovery",
341+
],
342+
[
343+
"sudo",
344+
"/usr/bin/mock-bin",
345+
"-cf",
346+
"/etc/sudoers.d/dance.hack-dns-recovery",
347+
],
348+
])
349+
);
350+
});
351+
319352
test("global authorize uses the OS account lookup instead of USER env", async () => {
320353
idUser = "real-login-user";
321354
process.env.USER = "spoofed-user";

0 commit comments

Comments
 (0)