fix: import the behavior of the web

This commit is contained in:
2026-07-12 20:28:25 +07:00
parent 83e7863fd9
commit 69927775ed
17 changed files with 234 additions and 88 deletions
+7 -13
View File
@@ -52,7 +52,7 @@ function request(pathname, headers = {}, authToken) {
describe("dashboard guard public LLM API access", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.getSettings.mockResolvedValue({ requireLogin: true });
mocks.getSettings.mockResolvedValue({});
mocks.getUserById.mockResolvedValue(null);
mocks.validateApiKey.mockResolvedValue(false);
mocks.getConsistentMachineId.mockResolvedValue("cli-token");
@@ -197,7 +197,7 @@ describe("dashboard guard public LLM API access", () => {
describe("dashboard guard local-only access", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.getSettings.mockResolvedValue({ requireLogin: true });
mocks.getSettings.mockResolvedValue({});
mocks.getUserById.mockResolvedValue(null);
mocks.validateApiKey.mockResolvedValue(false);
mocks.getConsistentMachineId.mockResolvedValue("cli-token");
@@ -214,7 +214,7 @@ describe("dashboard guard local-only access", () => {
expect(response.body.error).toBe("Local only: CLI token required");
});
it("rejects local-only route on loopback when requireLogin=true and no JWT", async () => {
it("rejects local-only route on loopback without a JWT", async () => {
const response = await proxy(request("/api/mcp/filesystem/sse", {
host: "localhost:20128",
origin: "http://localhost:20128",
@@ -224,9 +224,7 @@ describe("dashboard guard local-only access", () => {
expect(response.body.error).toBe("Local only: CLI token required");
});
it("requires an administrator for CLI Tools even when dashboard login is disabled", async () => {
mocks.getSettings.mockResolvedValue({ requireLogin: false });
it("requires an administrator for CLI Tools", async () => {
const response = await proxy(request("/api/cli-tools/antigravity-mitm", {
host: "localhost:20128",
origin: "http://localhost:20128",
@@ -236,9 +234,7 @@ describe("dashboard guard local-only access", () => {
expect(response.body.error).toBe("Administrator access required");
});
it("rejects local-only route from tunnel host even when requireLogin=false", async () => {
mocks.getSettings.mockResolvedValue({ requireLogin: false });
it("rejects local-only route from a tunnel host", async () => {
const response = await proxy(request("/api/cli-tools/antigravity-mitm", {
host: "router.example.com",
}));
@@ -247,8 +243,6 @@ describe("dashboard guard local-only access", () => {
});
it("rejects local-only route when Origin is non-loopback (CSRF block)", async () => {
mocks.getSettings.mockResolvedValue({ requireLogin: false });
const response = await proxy(request("/api/cli-tools/antigravity-mitm", {
host: "localhost:20128",
origin: "http://evil.example.com",
@@ -270,7 +264,7 @@ describe("dashboard guard local-only access", () => {
describe("dashboard guard CLI Tools administration access", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.getSettings.mockResolvedValue({ requireLogin: true });
mocks.getSettings.mockResolvedValue({});
mocks.getUserById.mockResolvedValue({ id: "user-1", isActive: true, role: "user" });
mocks.validateApiKey.mockResolvedValue(false);
mocks.getConsistentMachineId.mockResolvedValue("cli-token");
@@ -315,7 +309,7 @@ describe("dashboard guard CLI Tools administration access", () => {
describe("dashboard guard token saver administration access", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.getSettings.mockResolvedValue({ requireLogin: true });
mocks.getSettings.mockResolvedValue({});
mocks.getUserById.mockResolvedValue({ id: "user-1", isActive: true, role: "user" });
mocks.getConsistentMachineId.mockResolvedValue("cli-token");
mocks.getDashboardAuthSession.mockResolvedValue({ userId: "user-1" });
-2
View File
@@ -28,12 +28,10 @@ describe("DB SQLite layer — public API parity", () => {
const s = await sqliteDb.getSettings();
expect(s).toBeDefined();
expect(s.cloudEnabled).toBe(false);
expect(s.requireLogin).toBe(true);
const updated = await sqliteDb.updateSettings({ cloudEnabled: true, customField: "x" });
expect(updated.cloudEnabled).toBe(true);
expect(updated.customField).toBe("x");
expect(updated.requireLogin).toBe(true); // default preserved
const re = await sqliteDb.getSettings();
expect(re.cloudEnabled).toBe(true);
+5 -1
View File
@@ -6,6 +6,10 @@ import os from "node:os";
import path from "node:path";
import { describe, it, expect, beforeAll, afterAll, vi } from "vitest";
vi.mock("@/lib/auth/currentUser", () => ({
requireUsageDashboardUser: vi.fn(async () => ({ id: "test-admin", role: "admin" })),
}));
const originalDataDir = process.env.DATA_DIR;
let tempDir;
let db;
@@ -22,7 +26,7 @@ beforeAll(async () => {
vi.resetModules();
db = await import("@/lib/db/index.js");
await db.initDb();
await db.updateSettings({ enableObservability2: true, observabilityBatchSize: 1 });
await db.updateSettings({ enableObservability: true, observabilityBatchSize: 1 });
const { getAdapter } = await import("@/lib/db/driver.js");
adapter = await getAdapter();