let createIcaclsResetCommand: typeofimport("./windows-acl.js").createIcaclsResetCommand;
let formatIcaclsResetCommand: typeofimport("./windows-acl.js").formatIcaclsResetCommand;
let formatWindowsAclSummary: typeofimport("./windows-acl.js").formatWindowsAclSummary;
let inspectWindowsAcl: typeofimport("./windows-acl.js").inspectWindowsAcl;
let parseIcaclsOutput: typeofimport("./windows-acl.js").parseIcaclsOutput;
let resolveWindowsUserPrincipal: typeofimport("./windows-acl.js").resolveWindowsUserPrincipal;
let summarizeWindowsAcl: typeofimport("./windows-acl.js").summarizeWindowsAcl;
describe("windows-acl", () => {
describe("resolveWindowsUserPrincipal", () => {
it("returns DOMAIN\\USERNAME when both are present", () => { const env = { USERNAME: "TestUser", USERDOMAIN: "WORKGROUP" };
expect(resolveWindowsUserPrincipal(env)).toBe("WORKGROUP\\TestUser");
});
it("returns just USERNAME when USERDOMAIN is not present", () => { const env = { USERNAME: "TestUser" };
expect(resolveWindowsUserPrincipal(env)).toBe("TestUser");
});
it("falls back to os.userInfo when USERNAME is empty", () => { // When USERNAME env is empty, falls back to os.userInfo().username const env = { USERNAME: "", USERDOMAIN: "WORKGROUP" }; const result = resolveWindowsUserPrincipal(env); // Should return a username (from os.userInfo fallback) with WORKGROUP domain
expect(result).toBe(`WORKGROUP\\${MOCK_USERNAME}`);
});
});
describe("parseIcaclsOutput", () => {
it("parses standard icacls output", () => { const output = `C:\\test\\file.txt BUILTIN\\Administrators:(F)
NT AUTHORITY\\SYSTEM:(F)
WORKGROUP\\TestUser:(R)
it("skips entries with parentheses but no colon separator (line 190)", () => { // parseAceEntry: entry has '(' so passes the early guard but has no ':' const output = `C:\\test\\file.txt BUILTIN(F)\n BUILTIN\\Administrators:(F)`; const entries = parseIcaclsOutput(output, "C:\\test\\file.txt"); // BUILTIN(F) has no ':' → returns null; only the Administrators entry is kept
expectSinglePrincipal(entries, "BUILTIN\\Administrators");
});
it("skips entries where all tokens are inherit flags (line 207)", () => { // Only inherit flags: I, OI, CI — after filtering, rights is empty → returns null const output = `C:\\test\\file.txt BUILTIN\\Users:(I)(OI)(CI)\n BUILTIN\\Administrators:(F)`; const entries = parseIcaclsOutput(output, "C:\\test\\file.txt");
expectSinglePrincipal(entries, "BUILTIN\\Administrators");
});
const result = await inspectWindowsAcl("C:\\test\\file.txt", {
exec: mockExec,
});
expectInspectSuccess(result, 2); // /sid is passed so that account names are printed as SIDs, making the // audit locale-independent (fixes #35834).
expect(mockExec).toHaveBeenCalledWith("icacls.exe", ["C:\\test\\file.txt", "/sid"]);
});
it("classifies *S-1-5-18 (SID form of SYSTEM from /sid) as trusted", async () => { // When icacls is called with /sid it outputs *S-X-X-X instead of // locale-dependent names like "NT AUTHORITY\\SYSTEM" or the Russian // garbled equivalent. const mockExec = vi.fn().mockResolvedValue({
stdout: "C:\\test\\file.txt *S-1-5-21-111-222-333-1001:(F)\n *S-1-5-18:(F)\n *S-1-5-32-544:(F)",
stderr: "",
});
const result = await inspectWindowsAcl("C:\\test\\file.txt", {
exec: mockExec,
env: { USERSID: "S-1-5-21-111-222-333-1001" },
});
expectInspectSuccess(result, 3); // All three entries (current user, SYSTEM, Administrators) must be trusted.
expect(result.trusted).toHaveLength(3);
expect(result.untrustedGroup).toHaveLength(0);
expect(result.untrustedWorld).toHaveLength(0);
});
it("resolves current user SID via whoami when USERSID is missing", async () => { const mockExec = vi
.fn()
.mockResolvedValueOnce({
stdout: "C:\\test\\file.txt *S-1-5-21-111-222-333-1001:(F)\n *S-1-5-18:(F)",
stderr: "",
})
.mockResolvedValueOnce({
stdout: '"mock-host\\\\MockUser","S-1-5-21-111-222-333-1001"\r\n',
stderr: "",
});
it("generates command for directories with inheritance flags", () => { const env = { USERNAME: "TestUser", USERDOMAIN: "WORKGROUP" }; const result = formatIcaclsResetCommand("C:\\test\\dir", {
isDir: true,
env,
});
expect(result).toContain("(OI)(CI)F");
});
it("uses system username when env is empty (falls back to os.userInfo)", () => { // When env is empty, resolveWindowsUserPrincipal falls back to os.userInfo().username const result = formatIcaclsResetCommand("C:\\test\\file.txt", {
isDir: false,
env: {},
}); // Should contain the actual system username from os.userInfo
expect(result).toContain(`"${MOCK_USERNAME}:F"`);
expect(result).not.toContain("%USERNAME%");
});
});
it("returns command with system username when env is empty (falls back to os.userInfo)", () => { // When env is empty, resolveWindowsUserPrincipal falls back to os.userInfo().username const result = createIcaclsResetCommand("C:\\test\\file.txt", {
isDir: false,
env: {},
}); // Should return a valid command using the system username
expect(result).not.toBeNull();
expect(result?.command).toBe("icacls");
expect(result?.args).toContain(`${MOCK_USERNAME}:F`);
});
it("world SIDs in USERSID env are not added to trusted set", () => { // S-1-1-0 = Everyone. Even if USERSID is set to this, it must NOT be trusted. const env = { USERSID: "S-1-1-0" }; const entries: WindowsAclEntry[] = [
aclEntry({
principal: "S-1-1-0",
rights: ["F"],
rawRights: "(F)",
canRead: true,
canWrite: true,
}),
]; const summary = summarizeWindowsAcl(entries, env); // Everyone must remain in untrustedWorld, not trusted
expect(summary.untrustedWorld).toHaveLength(1);
expect(summary.trusted).toHaveLength(0);
});
it("returns null when no username can be resolved (line 348)", () => { // Temporarily make os.userInfo().username empty so resolveWindowsUserPrincipal returns null
userInfoMock.mockReturnValueOnce({
username: "",
uid: -1,
gid: -1,
shell: "",
homedir: "",
}); const result = createIcaclsResetCommand("C:\\test\\file.txt", {
isDir: false,
env: { USERNAME: "", USERDOMAIN: "" },
});
expect(result).toBeNull();
});
});
describe("summarizeWindowsAcl — localized SYSTEM account names", () => {
it("classifies French SYSTEM (AUTORITE NT\\Système) as trusted", () => {
expectTrustedOnly([aclEntry({ principal: "AUTORITE NT\\Système" })]);
});
it("classifies German SYSTEM (NT-AUTORITÄT\\SYSTEM) as trusted", () => {
expectTrustedOnly([aclEntry({ principal: "NT-AUTORITÄT\\SYSTEM" })]);
});
it("classifies Spanish SYSTEM (AUTORIDAD NT\\SYSTEM) as trusted", () => {
expectTrustedOnly([aclEntry({ principal: "AUTORIDAD NT\\SYSTEM" })]);
});
it("classifies principal with diacritic not in TRUSTED_BASE but matching stripped suffix (line 145)", () => { // "NT Authority\\Syst\u00e9me" has \u00e9 (e-acute) which is not in TRUSTED_BASE directly. // After diacritic stripping: "nt authority\\systeme" which ends with stripped("\\syst\u00e8me") = "\\systeme". // This exercises the classifyPrincipal diacritic-strip fallback at line 145.
expectTrustedOnly([aclEntry({ principal: "NT Authority\\Syst\u00e9me" })]);
});
it("French Windows full scenario: user + Système only → no untrusted", () => { const entries: WindowsAclEntry[] = [
aclEntry({ principal: "MYPC\\Pierre" }),
aclEntry({ principal: "AUTORITE NT\\Système" }),
]; const env = { USERNAME: "Pierre", USERDOMAIN: "MYPC" }; const { trusted, untrustedWorld, untrustedGroup } = summarizeWindowsAcl(entries, env);
expect(trusted).toHaveLength(2);
expect(untrustedWorld).toHaveLength(0);
expect(untrustedGroup).toHaveLength(0);
});
});
describe("formatIcaclsResetCommand — uses SID for SYSTEM", () => {
it("uses *S-1-5-18 instead of SYSTEM in reset command", () => { const cmd = formatIcaclsResetCommand("C:\\test.json", {
isDir: false,
env: { USERNAME: "TestUser", USERDOMAIN: "PC" },
});
expect(cmd).toContain("*S-1-5-18:F");
expect(cmd).not.toContain("SYSTEM:F");
});
});
});
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-09)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.