mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:18:26 +00:00
test(browser): dedupe explicit auth-mode auto-token checks
This commit is contained in:
@@ -18,6 +18,22 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
import { ensureBrowserControlAuth } from "./control-auth.js";
|
import { ensureBrowserControlAuth } from "./control-auth.js";
|
||||||
|
|
||||||
describe("ensureBrowserControlAuth", () => {
|
describe("ensureBrowserControlAuth", () => {
|
||||||
|
const expectExplicitModeSkipsAutoAuth = async (mode: "password" | "none") => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
gateway: {
|
||||||
|
auth: { mode },
|
||||||
|
},
|
||||||
|
browser: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv });
|
||||||
|
expect(result).toEqual({ auth: {} });
|
||||||
|
expect(mocks.loadConfig).not.toHaveBeenCalled();
|
||||||
|
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
mocks.loadConfig.mockReset();
|
mocks.loadConfig.mockReset();
|
||||||
@@ -80,41 +96,11 @@ describe("ensureBrowserControlAuth", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("respects explicit password mode", async () => {
|
it("respects explicit password mode", async () => {
|
||||||
const cfg: OpenClawConfig = {
|
await expectExplicitModeSkipsAutoAuth("password");
|
||||||
gateway: {
|
|
||||||
auth: {
|
|
||||||
mode: "password",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
browser: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv });
|
|
||||||
|
|
||||||
expect(result).toEqual({ auth: {} });
|
|
||||||
expect(mocks.loadConfig).not.toHaveBeenCalled();
|
|
||||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("respects explicit none mode", async () => {
|
it("respects explicit none mode", async () => {
|
||||||
const cfg: OpenClawConfig = {
|
await expectExplicitModeSkipsAutoAuth("none");
|
||||||
gateway: {
|
|
||||||
auth: {
|
|
||||||
mode: "none",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
browser: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv });
|
|
||||||
|
|
||||||
expect(result).toEqual({ auth: {} });
|
|
||||||
expect(mocks.loadConfig).not.toHaveBeenCalled();
|
|
||||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reuses auth from latest config snapshot", async () => {
|
it("reuses auth from latest config snapshot", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user