mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 20:01:23 +00:00
refactor(core): dedupe gateway runtime and config tests
This commit is contained in:
@@ -39,6 +39,19 @@ describe("ensureGatewayStartupAuth", () => {
|
||||
mocks.writeConfigFile.mockReset();
|
||||
});
|
||||
|
||||
async function expectNoTokenGeneration(cfg: OpenClawConfig, mode: string) {
|
||||
const result = await ensureGatewayStartupAuth({
|
||||
cfg,
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
persist: true,
|
||||
});
|
||||
|
||||
expect(result.generatedToken).toBeUndefined();
|
||||
expect(result.persistedGeneratedToken).toBe(false);
|
||||
expect(result.auth.mode).toBe(mode);
|
||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||
}
|
||||
|
||||
it("generates and persists a token when startup auth is missing", async () => {
|
||||
const result = await ensureGatewayStartupAuth({
|
||||
cfg: {},
|
||||
@@ -79,64 +92,43 @@ describe("ensureGatewayStartupAuth", () => {
|
||||
});
|
||||
|
||||
it("does not generate in password mode", async () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
gateway: {
|
||||
auth: {
|
||||
mode: "password",
|
||||
await expectNoTokenGeneration(
|
||||
{
|
||||
gateway: {
|
||||
auth: {
|
||||
mode: "password",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const result = await ensureGatewayStartupAuth({
|
||||
cfg,
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
persist: true,
|
||||
});
|
||||
|
||||
expect(result.generatedToken).toBeUndefined();
|
||||
expect(result.persistedGeneratedToken).toBe(false);
|
||||
expect(result.auth.mode).toBe("password");
|
||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||
"password",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not generate in trusted-proxy mode", async () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
gateway: {
|
||||
auth: {
|
||||
mode: "trusted-proxy",
|
||||
trustedProxy: { userHeader: "x-forwarded-user" },
|
||||
await expectNoTokenGeneration(
|
||||
{
|
||||
gateway: {
|
||||
auth: {
|
||||
mode: "trusted-proxy",
|
||||
trustedProxy: { userHeader: "x-forwarded-user" },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const result = await ensureGatewayStartupAuth({
|
||||
cfg,
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
persist: true,
|
||||
});
|
||||
|
||||
expect(result.generatedToken).toBeUndefined();
|
||||
expect(result.persistedGeneratedToken).toBe(false);
|
||||
expect(result.auth.mode).toBe("trusted-proxy");
|
||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||
"trusted-proxy",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not generate in explicit none mode", async () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
gateway: {
|
||||
auth: {
|
||||
mode: "none",
|
||||
await expectNoTokenGeneration(
|
||||
{
|
||||
gateway: {
|
||||
auth: {
|
||||
mode: "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const result = await ensureGatewayStartupAuth({
|
||||
cfg,
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
persist: true,
|
||||
});
|
||||
|
||||
expect(result.generatedToken).toBeUndefined();
|
||||
expect(result.persistedGeneratedToken).toBe(false);
|
||||
expect(result.auth.mode).toBe("none");
|
||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||
"none",
|
||||
);
|
||||
});
|
||||
|
||||
it("treats undefined token override as no override", async () => {
|
||||
|
||||
Reference in New Issue
Block a user