mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:22:47 +00:00
test(browser): dedupe generated-token persistence assertions
This commit is contained in:
@@ -34,6 +34,18 @@ describe("ensureBrowserControlAuth", () => {
|
|||||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const expectGeneratedTokenPersisted = (result: {
|
||||||
|
generatedToken?: string;
|
||||||
|
auth: { token?: string };
|
||||||
|
}) => {
|
||||||
|
expect(result.generatedToken).toMatch(/^[0-9a-f]{48}$/);
|
||||||
|
expect(result.auth.token).toBe(result.generatedToken);
|
||||||
|
expect(mocks.writeConfigFile).toHaveBeenCalledTimes(1);
|
||||||
|
const persisted = mocks.writeConfigFile.mock.calls[0]?.[0];
|
||||||
|
expect(persisted?.gateway?.auth?.mode).toBe("token");
|
||||||
|
expect(persisted?.gateway?.auth?.token).toBe(result.generatedToken);
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
mocks.loadConfig.mockReset();
|
mocks.loadConfig.mockReset();
|
||||||
@@ -69,13 +81,7 @@ describe("ensureBrowserControlAuth", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv });
|
const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv });
|
||||||
|
expectGeneratedTokenPersisted(result);
|
||||||
expect(result.generatedToken).toMatch(/^[0-9a-f]{48}$/);
|
|
||||||
expect(result.auth.token).toBe(result.generatedToken);
|
|
||||||
expect(mocks.writeConfigFile).toHaveBeenCalledTimes(1);
|
|
||||||
const persisted = mocks.writeConfigFile.mock.calls[0]?.[0];
|
|
||||||
expect(persisted?.gateway?.auth?.mode).toBe("token");
|
|
||||||
expect(persisted?.gateway?.auth?.token).toBe(result.generatedToken);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("skips auto-generation in test env", async () => {
|
it("skips auto-generation in test env", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user