mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:00:42 +00:00
test(gateway): avoid startup auth module reset churn
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { expectGeneratedTokenPersistedToGatewayAuth } from "../test-utils/auth-token-assertions.js";
|
||||
import {
|
||||
assertGatewayAuthNotKnownWeak,
|
||||
assertHooksTokenSeparateFromGatewayAuth,
|
||||
ensureGatewayStartupAuth,
|
||||
} from "./startup-auth.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
replaceConfigFile: vi.fn(async (_params: { nextConfig: OpenClawConfig }) => {}),
|
||||
@@ -14,19 +19,6 @@ vi.mock("../config/config.js", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
let assertGatewayAuthNotKnownWeak: typeof import("./startup-auth.js").assertGatewayAuthNotKnownWeak;
|
||||
let assertHooksTokenSeparateFromGatewayAuth: typeof import("./startup-auth.js").assertHooksTokenSeparateFromGatewayAuth;
|
||||
let ensureGatewayStartupAuth: typeof import("./startup-auth.js").ensureGatewayStartupAuth;
|
||||
|
||||
async function loadFreshStartupAuthModuleForTest() {
|
||||
vi.resetModules();
|
||||
({
|
||||
assertGatewayAuthNotKnownWeak,
|
||||
assertHooksTokenSeparateFromGatewayAuth,
|
||||
ensureGatewayStartupAuth,
|
||||
} = await import("./startup-auth.js"));
|
||||
}
|
||||
|
||||
describe("ensureGatewayStartupAuth", () => {
|
||||
async function expectEphemeralGeneratedTokenWhenOverridden(cfg: OpenClawConfig) {
|
||||
const result = await ensureGatewayStartupAuth({
|
||||
@@ -43,10 +35,9 @@ describe("ensureGatewayStartupAuth", () => {
|
||||
expect(mocks.replaceConfigFile).not.toHaveBeenCalled();
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
mocks.replaceConfigFile.mockClear();
|
||||
await loadFreshStartupAuthModuleForTest();
|
||||
});
|
||||
|
||||
async function expectNoTokenGeneration(cfg: OpenClawConfig, mode: string) {
|
||||
@@ -476,8 +467,9 @@ describe("ensureGatewayStartupAuth", () => {
|
||||
});
|
||||
|
||||
describe("assertGatewayAuthNotKnownWeak", () => {
|
||||
beforeEach(async () => {
|
||||
await loadFreshStartupAuthModuleForTest();
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
mocks.replaceConfigFile.mockClear();
|
||||
});
|
||||
|
||||
it("throws on the known-weak token sentinel", () => {
|
||||
|
||||
Reference in New Issue
Block a user