Skip to content

Commit 135b62c

Browse files
committed
test(control-ui): cover IPv6 loopback token scope
1 parent 894ba94 commit 135b62c

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

ui/src/ui/storage.node.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,48 @@ describe("loadSettings default gateway URL derivation", () => {
249249
});
250250
});
251251

252+
it("reuses a session token across IPv6 and IPv4 loopback aliases", async () => {
253+
setTestLocation({
254+
protocol: "http:",
255+
host: "[::1]:18789",
256+
pathname: "/",
257+
});
258+
259+
const { loadSettings, saveSettings } = await import("./storage.ts");
260+
saveSettings({
261+
gatewayUrl: "ws://[::1]:18789",
262+
token: "loopback-token",
263+
sessionKey: "main",
264+
lastActiveSessionKey: "main",
265+
theme: "system",
266+
chatFocusMode: false,
267+
chatShowThinking: true,
268+
splitRatio: 0.6,
269+
navCollapsed: false,
270+
navGroupsCollapsed: {},
271+
});
272+
273+
localStorage.setItem(
274+
"openclaw.control.settings.v1",
275+
JSON.stringify({
276+
gatewayUrl: "ws://127.0.0.1:18789",
277+
sessionKey: "main",
278+
lastActiveSessionKey: "main",
279+
theme: "system",
280+
chatFocusMode: false,
281+
chatShowThinking: true,
282+
splitRatio: 0.6,
283+
navCollapsed: false,
284+
navGroupsCollapsed: {},
285+
}),
286+
);
287+
288+
expect(loadSettings()).toMatchObject({
289+
gatewayUrl: "ws://127.0.0.1:18789",
290+
token: "loopback-token",
291+
});
292+
});
293+
252294
it("does not reuse a loopback token across different ports", async () => {
253295
setTestLocation({
254296
protocol: "http:",

ui/src/ui/storage.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ function normalizeGatewayTokenScope(gatewayUrl: string): string {
4545
const parsed = base ? new URL(trimmed, base) : new URL(trimmed);
4646
const host = parsed.hostname.trim().toLowerCase();
4747
const isLoopbackHost =
48-
host === "localhost" ||
49-
host === "127.0.0.1" ||
50-
host === "::1" ||
51-
host === "[::1]" ||
52-
host.startsWith("127.");
48+
host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host.startsWith("127.");
5349
const pathname =
5450
parsed.pathname === "/" ? "" : parsed.pathname.replace(/\/+$/, "") || parsed.pathname;
5551
const hostPort = isLoopbackHost

0 commit comments

Comments
 (0)