diff --git a/backend/app/api/routes.py b/backend/app/api/routes.py index a09e133..74a80a3 100644 --- a/backend/app/api/routes.py +++ b/backend/app/api/routes.py @@ -307,7 +307,7 @@ async def event_generator(): data=event.model_dump_json(), ) - return EventSourceResponse(event_generator()) + return EventSourceResponse(event_generator(), ping=15) # --------------------------------------------------------------------------- @@ -1721,7 +1721,7 @@ async def event_generator(): data=evt.model_dump_json() if hasattr(evt, "model_dump_json") else _json.dumps(evt), ) - return EventSourceResponse(event_generator()) + return EventSourceResponse(event_generator(), ping=15) @router.get("/projects/{project_id}/search", response_model=ProjectSearchResponse) diff --git a/web/src/app/api/auth/[...all]/__tests__/route.test.ts b/web/src/app/api/auth/[...all]/__tests__/route.test.ts index 890c5d6..2c9727c 100644 --- a/web/src/app/api/auth/[...all]/__tests__/route.test.ts +++ b/web/src/app/api/auth/[...all]/__tests__/route.test.ts @@ -15,14 +15,18 @@ function makePost(pathname: string) { } describe('POST /api/auth/[...all] — registration guard', () => { - const originalEnv = process.env; + const WATCHED = ['ALLOW_REGISTRATION'] as const; + const saved: Partial> = {}; beforeEach(() => { - process.env = { ...originalEnv }; + for (const key of WATCHED) saved[key] = process.env[key]; }); - afterAll(() => { - process.env = originalEnv; + afterEach(() => { + for (const key of WATCHED) { + if (saved[key] === undefined) delete process.env[key]; + else process.env[key] = saved[key]; + } }); it('blocks /sign-up/email with 403 when ALLOW_REGISTRATION=false', async () => { @@ -32,6 +36,7 @@ describe('POST /api/auth/[...all] — registration guard', () => { expect(res.status).toBe(403); const body = await res.json(); + expect(body.error).toBe('Registration is disabled'); expect(body.message).toBe('Registration is disabled'); }); diff --git a/web/src/app/api/auth/[...all]/route.ts b/web/src/app/api/auth/[...all]/route.ts index 3cb2781..72f1b39 100644 --- a/web/src/app/api/auth/[...all]/route.ts +++ b/web/src/app/api/auth/[...all]/route.ts @@ -10,7 +10,7 @@ export const GET = handlers.GET; export async function POST(request: NextRequest, _context: { params: Promise<{ all: string[] }> }) { const url = new URL(request.url); if (process.env.ALLOW_REGISTRATION === 'false' && url.pathname === '/api/auth/sign-up/email') { - return NextResponse.json({ message: 'Registration is disabled' }, { status: 403 }); + return NextResponse.json({ error: 'Registration is disabled', message: 'Registration is disabled' }, { status: 403 }); } return handlers.POST(request); } diff --git a/web/src/app/api/auth/config/__tests__/route.test.ts b/web/src/app/api/auth/config/__tests__/route.test.ts index 99042bc..be04fb6 100644 --- a/web/src/app/api/auth/config/__tests__/route.test.ts +++ b/web/src/app/api/auth/config/__tests__/route.test.ts @@ -1,14 +1,24 @@ import { GET } from '../route'; describe('GET /api/auth/config', () => { - const originalEnv = process.env; + const WATCHED = [ + 'GITHUB_CLIENT_ID', + 'GITHUB_CLIENT_SECRET', + 'GOOGLE_CLIENT_ID', + 'GOOGLE_CLIENT_SECRET', + 'ALLOW_REGISTRATION', + ] as const; + const saved: Partial> = {}; beforeEach(() => { - process.env = { ...originalEnv }; + for (const key of WATCHED) saved[key] = process.env[key]; }); - afterAll(() => { - process.env = originalEnv; + afterEach(() => { + for (const key of WATCHED) { + if (saved[key] === undefined) delete process.env[key]; + else process.env[key] = saved[key]; + } }); it('returns github=true when both GitHub secrets are set', async () => {