fix(webui): gate bootstrap API token issuance

This commit is contained in:
chengyongru
2026-07-08 21:01:48 +08:00
committed by Xubin Ren
parent 7204d88a4c
commit 88143a8bf0
16 changed files with 219 additions and 85 deletions
+26 -1
View File
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { deriveWsUrl, fetchBootstrap } from "@/lib/bootstrap";
import { consumeUrlBootstrapSecret, deriveWsUrl, fetchBootstrap } from "@/lib/bootstrap";
describe("bootstrap helpers", () => {
afterEach(() => {
@@ -50,4 +50,29 @@ describe("bootstrap helpers", () => {
await pending;
});
it("rejects bootstrap responses without an API token", async () => {
vi.stubGlobal(
"fetch",
vi.fn(async () => ({
ok: true,
json: async () => ({ token: "ws-token", ws_path: "/", expires_in: 300 }),
})),
);
await expect(fetchBootstrap()).rejects.toThrow(
"bootstrap response missing api_token",
);
});
it("consumes bootstrap secrets from the URL fragment", () => {
window.history.replaceState(
null,
"",
"/#/settings?bootstrapSecret=s3cret&section=models",
);
expect(consumeUrlBootstrapSecret()).toBe("s3cret");
expect(window.location.hash).toBe("#/settings?section=models");
});
});