mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:38:26 +00:00
test(gateway): dedupe startup auth override token checks
This commit is contained in:
@@ -16,6 +16,21 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||||||
import { ensureGatewayStartupAuth } from "./startup-auth.js";
|
import { ensureGatewayStartupAuth } from "./startup-auth.js";
|
||||||
|
|
||||||
describe("ensureGatewayStartupAuth", () => {
|
describe("ensureGatewayStartupAuth", () => {
|
||||||
|
async function expectEphemeralGeneratedTokenWhenOverridden(cfg: OpenClawConfig) {
|
||||||
|
const result = await ensureGatewayStartupAuth({
|
||||||
|
cfg,
|
||||||
|
env: {} as NodeJS.ProcessEnv,
|
||||||
|
authOverride: { mode: "token" },
|
||||||
|
persist: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.generatedToken).toMatch(/^[0-9a-f]{48}$/);
|
||||||
|
expect(result.persistedGeneratedToken).toBe(false);
|
||||||
|
expect(result.auth.mode).toBe("token");
|
||||||
|
expect(result.auth.token).toBe(result.generatedToken);
|
||||||
|
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
mocks.writeConfigFile.mockReset();
|
mocks.writeConfigFile.mockReset();
|
||||||
@@ -145,68 +160,32 @@ describe("ensureGatewayStartupAuth", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("keeps generated token ephemeral when runtime override flips explicit non-token mode", async () => {
|
it("keeps generated token ephemeral when runtime override flips explicit non-token mode", async () => {
|
||||||
const cfg: OpenClawConfig = {
|
await expectEphemeralGeneratedTokenWhenOverridden({
|
||||||
gateway: {
|
gateway: {
|
||||||
auth: {
|
auth: {
|
||||||
mode: "password",
|
mode: "password",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
|
||||||
const result = await ensureGatewayStartupAuth({
|
|
||||||
cfg,
|
|
||||||
env: {} as NodeJS.ProcessEnv,
|
|
||||||
authOverride: { mode: "token" },
|
|
||||||
persist: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.generatedToken).toMatch(/^[0-9a-f]{48}$/);
|
|
||||||
expect(result.persistedGeneratedToken).toBe(false);
|
|
||||||
expect(result.auth.mode).toBe("token");
|
|
||||||
expect(result.auth.token).toBe(result.generatedToken);
|
|
||||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps generated token ephemeral when runtime override flips explicit none mode", async () => {
|
it("keeps generated token ephemeral when runtime override flips explicit none mode", async () => {
|
||||||
const cfg: OpenClawConfig = {
|
await expectEphemeralGeneratedTokenWhenOverridden({
|
||||||
gateway: {
|
gateway: {
|
||||||
auth: {
|
auth: {
|
||||||
mode: "none",
|
mode: "none",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
|
||||||
const result = await ensureGatewayStartupAuth({
|
|
||||||
cfg,
|
|
||||||
env: {} as NodeJS.ProcessEnv,
|
|
||||||
authOverride: { mode: "token" },
|
|
||||||
persist: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.generatedToken).toMatch(/^[0-9a-f]{48}$/);
|
|
||||||
expect(result.persistedGeneratedToken).toBe(false);
|
|
||||||
expect(result.auth.mode).toBe("token");
|
|
||||||
expect(result.auth.token).toBe(result.generatedToken);
|
|
||||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps generated token ephemeral when runtime override flips implicit password mode", async () => {
|
it("keeps generated token ephemeral when runtime override flips implicit password mode", async () => {
|
||||||
const cfg: OpenClawConfig = {
|
await expectEphemeralGeneratedTokenWhenOverridden({
|
||||||
gateway: {
|
gateway: {
|
||||||
auth: {
|
auth: {
|
||||||
password: "configured-password",
|
password: "configured-password",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
|
||||||
const result = await ensureGatewayStartupAuth({
|
|
||||||
cfg,
|
|
||||||
env: {} as NodeJS.ProcessEnv,
|
|
||||||
authOverride: { mode: "token" },
|
|
||||||
persist: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.generatedToken).toMatch(/^[0-9a-f]{48}$/);
|
|
||||||
expect(result.persistedGeneratedToken).toBe(false);
|
|
||||||
expect(result.auth.mode).toBe("token");
|
|
||||||
expect(result.auth.token).toBe(result.generatedToken);
|
|
||||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user