mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 14:24:59 +00:00
test: migrate suites to e2e coverage layout
This commit is contained in:
85
src/commands/configure.gateway-auth.e2e.test.ts
Normal file
85
src/commands/configure.gateway-auth.e2e.test.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildGatewayAuthConfig } from "./configure.js";
|
||||
|
||||
describe("buildGatewayAuthConfig", () => {
|
||||
it("preserves allowTailscale when switching to token", () => {
|
||||
const result = buildGatewayAuthConfig({
|
||||
existing: {
|
||||
mode: "password",
|
||||
password: "secret",
|
||||
allowTailscale: true,
|
||||
},
|
||||
mode: "token",
|
||||
token: "abc",
|
||||
});
|
||||
|
||||
expect(result).toEqual({ mode: "token", token: "abc", allowTailscale: true });
|
||||
});
|
||||
|
||||
it("drops password when switching to token", () => {
|
||||
const result = buildGatewayAuthConfig({
|
||||
existing: {
|
||||
mode: "password",
|
||||
password: "secret",
|
||||
allowTailscale: false,
|
||||
},
|
||||
mode: "token",
|
||||
token: "abc",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
mode: "token",
|
||||
token: "abc",
|
||||
allowTailscale: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("drops token when switching to password", () => {
|
||||
const result = buildGatewayAuthConfig({
|
||||
existing: { mode: "token", token: "abc" },
|
||||
mode: "password",
|
||||
password: "secret",
|
||||
});
|
||||
|
||||
expect(result).toEqual({ mode: "password", password: "secret" });
|
||||
});
|
||||
|
||||
it("generates random token when token param is undefined", () => {
|
||||
const result = buildGatewayAuthConfig({
|
||||
mode: "token",
|
||||
token: undefined,
|
||||
});
|
||||
|
||||
expect(result?.mode).toBe("token");
|
||||
expect(result?.token).toBeDefined();
|
||||
expect(result?.token).not.toBe("undefined");
|
||||
expect(typeof result?.token).toBe("string");
|
||||
expect(result?.token?.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("generates random token when token param is empty string", () => {
|
||||
const result = buildGatewayAuthConfig({
|
||||
mode: "token",
|
||||
token: "",
|
||||
});
|
||||
|
||||
expect(result?.mode).toBe("token");
|
||||
expect(result?.token).toBeDefined();
|
||||
expect(result?.token).not.toBe("undefined");
|
||||
expect(typeof result?.token).toBe("string");
|
||||
expect(result?.token?.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("generates random token when token param is whitespace only", () => {
|
||||
const result = buildGatewayAuthConfig({
|
||||
mode: "token",
|
||||
token: " ",
|
||||
});
|
||||
|
||||
expect(result?.mode).toBe("token");
|
||||
expect(result?.token).toBeDefined();
|
||||
expect(result?.token).not.toBe("undefined");
|
||||
expect(typeof result?.token).toBe("string");
|
||||
expect(result?.token?.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user