Add runtime provider controls and searchable AI routing
Manage provider keys at runtime, route current-information questions through server-side search with safe fallback, and scope OOBE usage claims to grants.
This commit is contained in:
@@ -276,4 +276,30 @@ describe("adminApi", () => {
|
||||
);
|
||||
expect(result.totpSecret).toBe("JBSWY3DPEHPK3PXP");
|
||||
});
|
||||
|
||||
it("Provider API Key 替换请求携带 CSRF 且只提交新 Key", async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
providerId: "deepseek",
|
||||
configured: true,
|
||||
source: "RUNTIME_OVERRIDE",
|
||||
updatedAt: "2026-08-22T08:00:00Z",
|
||||
}),
|
||||
{ status: 200, headers: { "Content-Type": "application/json" } },
|
||||
),
|
||||
);
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
setCsrfToken("csrf-provider");
|
||||
|
||||
await adminApi.updateProviderApiKey("deepseek", { apiKey: "new-provider-key" });
|
||||
|
||||
expect(fetchMock.mock.calls[0]?.[0]).toBe(
|
||||
"/v1/admin/providers/deepseek/api-key",
|
||||
);
|
||||
const request = fetchMock.mock.calls[0]?.[1] as RequestInit;
|
||||
expect(request.method).toBe("PUT");
|
||||
expect((request.headers as Headers).get("X-CSRF-Token")).toBe("csrf-provider");
|
||||
expect(request.body).toBe(JSON.stringify({ apiKey: "new-provider-key" }));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user