From e7bcbd3e7ede0a05d8d6270e5a95591edee1f27d Mon Sep 17 00:00:00 2001 From: Shakker Date: Fri, 5 Jun 2026 02:14:03 +0100 Subject: [PATCH] test: isolate windows acl system root --- src/security/windows-acl.test.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/security/windows-acl.test.ts b/src/security/windows-acl.test.ts index 85b6d123680c..f7fbb589ae43 100644 --- a/src/security/windows-acl.test.ts +++ b/src/security/windows-acl.test.ts @@ -4,6 +4,7 @@ import { DEFAULT_WINDOWS_SYSTEM_ROOT, resetWindowsInstallRootsForTests, } from "../infra/windows-install-roots.js"; +import { withEnvAsync } from "../test-utils/env.js"; import type { WindowsAclEntry, WindowsAclSummary } from "./windows-acl.js"; const MOCK_USERNAME = "MockUser"; @@ -33,7 +34,6 @@ beforeAll(async () => { }); beforeEach(() => { - vi.unstubAllEnvs(); resetWindowsInstallRootsForTests(); }); @@ -512,22 +512,23 @@ Successfully processed 1 files`; it("uses the discovered process SystemRoot when env options are omitted", async () => { resetWindowsInstallRootsForTests({ queryRegistryValue: () => null }); - vi.stubEnv("SystemRoot", "D:\\Windows"); const mockExec = vi.fn().mockResolvedValue({ stdout: "C:\\test\\file.txt *S-1-5-18:(F)", stderr: "", }); - const result = await inspectWindowsAcl("C:\\test\\file.txt", { - exec: mockExec, - }); + await withEnvAsync({ SystemRoot: "D:\\Windows" }, async () => { + const result = await inspectWindowsAcl("C:\\test\\file.txt", { + exec: mockExec, + }); - expectInspectSuccess(result, 1); - expect(mockExec).toHaveBeenCalledWith("D:\\Windows\\System32\\icacls.exe", [ - "C:\\test\\file.txt", - "/sid", - ]); + expectInspectSuccess(result, 1); + expect(mockExec).toHaveBeenCalledWith("D:\\Windows\\System32\\icacls.exe", [ + "C:\\test\\file.txt", + "/sid", + ]); + }); }); it("classifies *S-1-5-18 (SID form of SYSTEM from /sid) as trusted", async () => {