test: fix flaky auth tests when OPENCLAW_GATEWAY_TOKEN is present

This commit is contained in:
tyler
2026-02-22 10:32:00 +08:00
committed by Peter Steinberger
parent 9f2b25426b
commit 9b23e5ce1f
2 changed files with 33 additions and 2 deletions

View File

@@ -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";
const TRUSTED_PROXY_AUTH = {
@@ -103,6 +103,21 @@ describe("resolveGatewayRuntimeConfig", () => {
});
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([
{
name: "lan binding with token",
@@ -126,7 +141,8 @@ describe("resolveGatewayRuntimeConfig", () => {
{
name: "token mode without token",
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",