mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:48:26 +00:00
test: fix flaky auth tests when OPENCLAW_GATEWAY_TOKEN is present
This commit is contained in:
@@ -66,6 +66,11 @@ describe("profile CRUD endpoints", () => {
|
|||||||
state.prevGatewayPort = process.env.OPENCLAW_GATEWAY_PORT;
|
state.prevGatewayPort = process.env.OPENCLAW_GATEWAY_PORT;
|
||||||
process.env.OPENCLAW_GATEWAY_PORT = String(state.testPort - 2);
|
process.env.OPENCLAW_GATEWAY_PORT = String(state.testPort - 2);
|
||||||
|
|
||||||
|
state.prevGatewayToken = process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||||
|
state.prevGatewayPassword = process.env.OPENCLAW_GATEWAY_PASSWORD;
|
||||||
|
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||||
|
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
|
||||||
|
|
||||||
vi.stubGlobal(
|
vi.stubGlobal(
|
||||||
"fetch",
|
"fetch",
|
||||||
vi.fn(async (url: string) => {
|
vi.fn(async (url: string) => {
|
||||||
@@ -82,6 +87,16 @@ describe("profile CRUD endpoints", () => {
|
|||||||
vi.unstubAllGlobals();
|
vi.unstubAllGlobals();
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
restoreGatewayPortEnv(state.prevGatewayPort);
|
restoreGatewayPortEnv(state.prevGatewayPort);
|
||||||
|
if (state.prevGatewayToken !== undefined) {
|
||||||
|
process.env.OPENCLAW_GATEWAY_TOKEN = state.prevGatewayToken;
|
||||||
|
} else {
|
||||||
|
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||||
|
}
|
||||||
|
if (state.prevGatewayPassword !== undefined) {
|
||||||
|
process.env.OPENCLAW_GATEWAY_PASSWORD = state.prevGatewayPassword;
|
||||||
|
} else {
|
||||||
|
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
|
||||||
|
}
|
||||||
await stopBrowserControlServer();
|
await stopBrowserControlServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||||
import { resolveGatewayRuntimeConfig } from "./server-runtime-config.js";
|
import { resolveGatewayRuntimeConfig } from "./server-runtime-config.js";
|
||||||
|
|
||||||
const TRUSTED_PROXY_AUTH = {
|
const TRUSTED_PROXY_AUTH = {
|
||||||
@@ -103,6 +103,21 @@ describe("resolveGatewayRuntimeConfig", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("token/password auth modes", () => {
|
describe("token/password auth modes", () => {
|
||||||
|
let originalToken: string | undefined;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
originalToken = process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||||
|
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
if (originalToken !== undefined) {
|
||||||
|
process.env.OPENCLAW_GATEWAY_TOKEN = originalToken;
|
||||||
|
} else {
|
||||||
|
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
{
|
{
|
||||||
name: "lan binding with token",
|
name: "lan binding with token",
|
||||||
@@ -126,7 +141,8 @@ describe("resolveGatewayRuntimeConfig", () => {
|
|||||||
{
|
{
|
||||||
name: "token mode without token",
|
name: "token mode without token",
|
||||||
cfg: { gateway: { bind: "lan" as const, auth: { mode: "token" as const } } },
|
cfg: { gateway: { bind: "lan" as const, auth: { mode: "token" as const } } },
|
||||||
expectedMessage: "gateway auth mode is token, but no token was configured",
|
expectedMessage:
|
||||||
|
"gateway auth mode is token, but no token was configured (set gateway.auth.token or OPENCLAW_GATEWAY_TOKEN)",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "lan binding with explicit none auth",
|
name: "lan binding with explicit none auth",
|
||||||
|
|||||||
Reference in New Issue
Block a user