test: move query token checks to settings unit

This commit is contained in:
Peter Steinberger
2026-04-17 18:57:15 +01:00
parent 4ba12bd134
commit 783bb1f759
2 changed files with 7 additions and 30 deletions

View File

@@ -299,7 +299,7 @@ describe("applySettingsFromUrl", () => {
});
it("hydrates query token params and strips them from the URL", () => {
setTestWindowUrl("https://control.example/ui/overview?token=abc123");
setTestWindowUrl("https://control.example/ui/overview?token=abc123&password=sekret");
const host = createHost("overview");
host.settings.gatewayUrl = "wss://control.example/openclaw";
@@ -307,6 +307,9 @@ describe("applySettingsFromUrl", () => {
expect(host.settings.token).toBe("abc123");
expect(window.location.search).toBe("");
expect(JSON.parse(localStorage.getItem("openclaw.control.settings.v1") ?? "{}").token).toBe(
undefined,
);
});
it("prefers fragment tokens over legacy query tokens when both are present", () => {

View File

@@ -39,22 +39,6 @@ function expectConfirmedGatewayChange(app: ReturnType<typeof mountApp>) {
}
describe("control UI routing", () => {
it("keeps chat navigation links visible and updates the URL when clicked", async () => {
const app = mountApp("/chat");
await app.updateComplete;
const dreamsLink = app.querySelector<HTMLAnchorElement>('a.nav-item[href="/dreaming"]');
expect(dreamsLink).not.toBeNull();
const link = app.querySelector<HTMLAnchorElement>('a.nav-item[href="/channels"]');
expect(link).not.toBeNull();
link?.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, button: 0 }));
await app.updateComplete;
expect(app.tab).toBe("channels");
expect(window.location.pathname).toBe("/channels");
});
it("renders the dreaming view on the /dreaming route", async () => {
const app = mountApp("/dreaming");
app.dreamingStatus = {
@@ -127,6 +111,9 @@ describe("control UI routing", () => {
expect(window.matchMedia("(max-width: 768px)").matches).toBe(true);
const dreamsLink = app.querySelector<HTMLAnchorElement>('a.nav-item[href="/dreaming"]');
expect(dreamsLink).not.toBeNull();
expect(app.querySelector(".topnav-shell")).not.toBeNull();
expect(app.querySelector(".topnav-shell__content")).not.toBeNull();
expect(app.querySelector(".topnav-shell__actions")).not.toBeNull();
@@ -400,19 +387,6 @@ describe("control UI routing", () => {
expect(container.scrollTop).toBe(targetScrollTop);
});
it("hydrates safe query params and strips unsafe credentials from the URL", async () => {
const app = mountApp("/ui/overview?token=abc123&password=sekret");
await app.updateComplete;
expect(app.settings.token).toBe("abc123");
expect(app.password).toBe("");
expect(JSON.parse(localStorage.getItem("openclaw.control.settings.v1") ?? "{}").token).toBe(
undefined,
);
expect(window.location.pathname).toBe("/ui/overview");
expect(window.location.search).toBe("");
});
it("hydrates token from URL hash, strips it, and clears it after gateway changes", async () => {
const app = mountApp("/ui/overview#token=abc123");
await app.updateComplete;