Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(api): keep auth chunk in self-host bypass
Yufeng He67f5ebb8fbf1
diff --git a/apps/api/src/controllers/__tests__/auth.test.ts b/apps/api/src/controllers/__tests__/auth.test.tsnew file mode 100644index 000000000..fdf0c0664--- /dev/null+++ b/apps/api/src/controllers/__tests__/auth.test.ts@@ -0,0 +1,74 @@+import { vi } from "vitest";+import { authenticateUser } from "../auth";+import { config } from "../../config";+import { RateLimiterMode } from "../../types";++vi.mock("../../services/queue-service", () => ({+ getRedisConnection: vi.fn(() => ({+ sadd: vi.fn(),+ })),+}));++vi.mock("uuid", () => ({+ validate: vi.fn(() => true),+}));++vi.mock("../../services/redis", () => ({+ getValue: vi.fn(),+ setValue: vi.fn(),+ deleteKey: vi.fn(),+}));++vi.mock("../../services/redlock", () => ({+ redlock: {+ using: vi.fn(),+ },+}));++vi.mock("../../db/connection", () => ({+ db: {},+ dbRr: {},+}));++vi.mock("../../db/rpc", () => ({+ authCreditUsageChunk: vi.fn(),+ authCreditUsageChunkFromTeam: vi.fn(),+}));++vi.mock("../../services/rate-limiter", () => ({+ getRateLimiter: vi.fn(),+}));++vi.mock("../../services/agent-sponsor", () => ({+ getAgentSponsorStatus: vi.fn(),+}));++describe("authenticateUser", () => {+ const originalUseDbAuth = config.USE_DB_AUTHENTICATION;++ afterEach(() => {+ config.USE_DB_AUTHENTICATION = originalUseDbAuth;+ });++ it("keeps a mock ACUC chunk in no-auth mode", async () => {+ config.USE_DB_AUTHENTICATION = false;++ const auth = await authenticateUser(+ { headers: {}, socket: {} },+ {},+ RateLimiterMode.ExtractAgentPreview,+ );++ expect(auth.success).toBe(true);+ if (!auth.success) throw new Error("expected bypass auth to succeed");+ expect(auth.team_id).toBe("bypass");+ expect(auth.chunk).toEqual(+ expect.objectContaining({+ api_key: "bypass",+ api_key_id: 0,+ team_id: "bypass",+ is_extract: true,+ }),+ );+ });+});diff --git a/apps/api/src/controllers/auth.ts b/apps/api/src/controllers/auth.tsindex d7a50c6c0..e27ed6ffa 100644--- a/apps/api/src/controllers/auth.ts+++ b/apps/api/src/controllers/auth.ts@@ -633,10 +633,16 @@ export async function authenticateUser(mode?: RateLimiterMode,options?: { allowKeyless?: boolean },): Promise<AuthResponse> {+ const bypassChunk = mockACUC();+ bypassChunk.is_extract =+ mode === RateLimiterMode.Extract ||+ mode === RateLimiterMode.ExtractStatus ||+ mode === RateLimiterMode.ExtractAgentPreview;+return withAuth(supaAuthenticateUser, {success: true,- chunk: null,- team_id: "bypass",+ chunk: bypassChunk,+ team_id: bypassChunk.team_id,org_id: null,})(req, res, mode, options);}