test: fix windows-only expectations
This commit is contained in:
@@ -69,10 +69,7 @@ const hoisted = vi.hoisted(() => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const testConfigRoot = {
|
const testConfigRoot = {
|
||||||
value: path.join(
|
value: path.join(os.tmpdir(), `clawdbot-gateway-test-${process.pid}-${crypto.randomUUID()}`),
|
||||||
os.tmpdir(),
|
|
||||||
`clawdbot-gateway-test-${process.pid}-${crypto.randomUUID()}`,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setTestConfigRoot = (root: string) => {
|
export const setTestConfigRoot = (root: string) => {
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ async function waitForSocketConnect(socket: net.Socket) {
|
|||||||
|
|
||||||
describe("node bridge server", () => {
|
describe("node bridge server", () => {
|
||||||
let baseDir = "";
|
let baseDir = "";
|
||||||
|
const pairingTimeoutMs = process.platform === "win32" ? 8000 : 3000;
|
||||||
|
|
||||||
const pickNonLoopbackIPv4 = () => {
|
const pickNonLoopbackIPv4 = () => {
|
||||||
const ifaces = os.networkInterfaces();
|
const ifaces = os.networkInterfaces();
|
||||||
@@ -174,7 +175,7 @@ describe("node bridge server", () => {
|
|||||||
const list = await listNodePairing(baseDir);
|
const list = await listNodePairing(baseDir);
|
||||||
return list.pending.find((p) => p.nodeId === "n2");
|
return list.pending.find((p) => p.nodeId === "n2");
|
||||||
},
|
},
|
||||||
{ timeoutMs: 3000 },
|
{ timeoutMs: pairingTimeoutMs },
|
||||||
);
|
);
|
||||||
expect(pending).toBeTruthy();
|
expect(pending).toBeTruthy();
|
||||||
if (!pending) throw new Error("expected a pending request");
|
if (!pending) throw new Error("expected a pending request");
|
||||||
@@ -220,7 +221,7 @@ describe("node bridge server", () => {
|
|||||||
await waitForSocketConnect(socket);
|
await waitForSocketConnect(socket);
|
||||||
sendLine(socket, { type: "pair-request", nodeId: "n3", platform: "ios" });
|
sendLine(socket, { type: "pair-request", nodeId: "n3", platform: "ios" });
|
||||||
|
|
||||||
await pollUntil(async () => requested, { timeoutMs: 3000 });
|
await pollUntil(async () => requested, { timeoutMs: pairingTimeoutMs });
|
||||||
|
|
||||||
expect(requested?.nodeId).toBe("n3");
|
expect(requested?.nodeId).toBe("n3");
|
||||||
expect(typeof requested?.requestId).toBe("string");
|
expect(typeof requested?.requestId).toBe("string");
|
||||||
@@ -257,7 +258,7 @@ describe("node bridge server", () => {
|
|||||||
const list = await listNodePairing(baseDir);
|
const list = await listNodePairing(baseDir);
|
||||||
return list.pending.find((p) => p.nodeId === "n3-rpc");
|
return list.pending.find((p) => p.nodeId === "n3-rpc");
|
||||||
},
|
},
|
||||||
{ timeoutMs: 3000 },
|
{ timeoutMs: pairingTimeoutMs },
|
||||||
);
|
);
|
||||||
expect(pending).toBeTruthy();
|
expect(pending).toBeTruthy();
|
||||||
if (!pending) throw new Error("expected a pending request");
|
if (!pending) throw new Error("expected a pending request");
|
||||||
@@ -353,7 +354,7 @@ describe("node bridge server", () => {
|
|||||||
const list = await listNodePairing(baseDir);
|
const list = await listNodePairing(baseDir);
|
||||||
return list.pending.find((p) => p.nodeId === "n4");
|
return list.pending.find((p) => p.nodeId === "n4");
|
||||||
},
|
},
|
||||||
{ timeoutMs: 3000 },
|
{ timeoutMs: pairingTimeoutMs },
|
||||||
);
|
);
|
||||||
expect(pending).toBeTruthy();
|
expect(pending).toBeTruthy();
|
||||||
if (!pending) throw new Error("expected a pending request");
|
if (!pending) throw new Error("expected a pending request");
|
||||||
@@ -385,7 +386,7 @@ describe("node bridge server", () => {
|
|||||||
expect(line3.type).toBe("hello-ok");
|
expect(line3.type).toBe("hello-ok");
|
||||||
|
|
||||||
await pollUntil(async () => (lastAuthed?.nodeId === "n4" ? lastAuthed : null), {
|
await pollUntil(async () => (lastAuthed?.nodeId === "n4" ? lastAuthed : null), {
|
||||||
timeoutMs: 3000,
|
timeoutMs: pairingTimeoutMs,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(lastAuthed?.nodeId).toBe("n4");
|
expect(lastAuthed?.nodeId).toBe("n4");
|
||||||
|
|||||||
@@ -6,6 +6,16 @@ import { describe, expect, it } from "vitest";
|
|||||||
|
|
||||||
import { fixSecurityFootguns } from "./fix.js";
|
import { fixSecurityFootguns } from "./fix.js";
|
||||||
|
|
||||||
|
const isWindows = process.platform === "win32";
|
||||||
|
|
||||||
|
const expectPerms = (actual: number, expected: number) => {
|
||||||
|
if (isWindows) {
|
||||||
|
expect([expected, 0o666, 0o777]).toContain(actual);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
expect(actual).toBe(expected);
|
||||||
|
};
|
||||||
|
|
||||||
describe("security fix", () => {
|
describe("security fix", () => {
|
||||||
it("tightens groupPolicy + filesystem perms", async () => {
|
it("tightens groupPolicy + filesystem perms", async () => {
|
||||||
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-security-fix-"));
|
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-security-fix-"));
|
||||||
@@ -63,10 +73,10 @@ describe("security fix", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const stateMode = (await fs.stat(stateDir)).mode & 0o777;
|
const stateMode = (await fs.stat(stateDir)).mode & 0o777;
|
||||||
expect(stateMode).toBe(0o700);
|
expectPerms(stateMode, 0o700);
|
||||||
|
|
||||||
const configMode = (await fs.stat(configPath)).mode & 0o777;
|
const configMode = (await fs.stat(configPath)).mode & 0o777;
|
||||||
expect(configMode).toBe(0o600);
|
expectPerms(configMode, 0o600);
|
||||||
|
|
||||||
const parsed = JSON.parse(await fs.readFile(configPath, "utf-8")) as Record<string, unknown>;
|
const parsed = JSON.parse(await fs.readFile(configPath, "utf-8")) as Record<string, unknown>;
|
||||||
const channels = parsed.channels as Record<string, Record<string, unknown>>;
|
const channels = parsed.channels as Record<string, Record<string, unknown>>;
|
||||||
@@ -192,9 +202,9 @@ describe("security fix", () => {
|
|||||||
expect(res.ok).toBe(false);
|
expect(res.ok).toBe(false);
|
||||||
|
|
||||||
const stateMode = (await fs.stat(stateDir)).mode & 0o777;
|
const stateMode = (await fs.stat(stateDir)).mode & 0o777;
|
||||||
expect(stateMode).toBe(0o700);
|
expectPerms(stateMode, 0o700);
|
||||||
|
|
||||||
const configMode = (await fs.stat(configPath)).mode & 0o777;
|
const configMode = (await fs.stat(configPath)).mode & 0o777;
|
||||||
expect(configMode).toBe(0o600);
|
expectPerms(configMode, 0o600);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user