mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-19 12:34:45 +00:00
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { GatewayRemoteConfig } from "../config/types.gateway.js";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { resolveGatewayInteractiveSurfaceAuth } from "./auth-surface-resolution.js";
|
|
|
|
function remoteGatewayConfig(remote?: GatewayRemoteConfig): OpenClawConfig {
|
|
return {
|
|
gateway: {
|
|
mode: "remote",
|
|
remote: {
|
|
url: "wss://remote.example/ws",
|
|
...remote,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("resolveGatewayInteractiveSurfaceAuth", () => {
|
|
it("uses OPENCLAW_GATEWAY_TOKEN as remote interactive fallback", async () => {
|
|
await expect(
|
|
resolveGatewayInteractiveSurfaceAuth({
|
|
config: remoteGatewayConfig(),
|
|
env: {
|
|
OPENCLAW_GATEWAY_TOKEN: "env-token",
|
|
},
|
|
surface: "remote",
|
|
}),
|
|
).resolves.toEqual({
|
|
token: "env-token",
|
|
password: undefined,
|
|
});
|
|
});
|
|
|
|
it("keeps configured remote token ahead of OPENCLAW_GATEWAY_TOKEN", async () => {
|
|
await expect(
|
|
resolveGatewayInteractiveSurfaceAuth({
|
|
config: remoteGatewayConfig({ token: "remote-token" }),
|
|
env: {
|
|
OPENCLAW_GATEWAY_TOKEN: "env-token",
|
|
},
|
|
surface: "remote",
|
|
}),
|
|
).resolves.toEqual({
|
|
token: "remote-token",
|
|
password: undefined,
|
|
});
|
|
});
|
|
|
|
it("falls back to OPENCLAW_GATEWAY_TOKEN when the remote token ref is unresolved", async () => {
|
|
await expect(
|
|
resolveGatewayInteractiveSurfaceAuth({
|
|
config: {
|
|
...remoteGatewayConfig({
|
|
token: { source: "env", provider: "default", id: "MISSING_REMOTE_TOKEN" },
|
|
}),
|
|
},
|
|
env: {
|
|
OPENCLAW_GATEWAY_TOKEN: "env-token",
|
|
},
|
|
surface: "remote",
|
|
}),
|
|
).resolves.toEqual({
|
|
token: "env-token",
|
|
password: undefined,
|
|
});
|
|
});
|
|
});
|