Skip to content

Commit 08c1d22

Browse files
committed
test(express): add tests for empty proxy path fallback
1 parent 98161b0 commit 08c1d22

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

packages/express/src/__tests__/clerkMiddleware.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,35 @@ describe('clerkMiddleware', () => {
171171
expect(response.header).toHaveProperty('x-clerk-auth-status', 'handshake');
172172
});
173173

174+
it('falls back to default proxy path when path reduces to empty string', async () => {
175+
mockClerkFrontendApiProxy.mockResolvedValueOnce(new globalThis.Response('proxied', { status: 200 }));
176+
177+
// path: '/' strips to '' — should fall back to DEFAULT_PROXY_PATH (/__clerk)
178+
// and only intercept /__clerk, not every request
179+
await runMiddlewareOnPath(
180+
clerkMiddleware({ frontendApiProxy: { enabled: true, path: '/' } }),
181+
'/__clerk/v1/client',
182+
{},
183+
).expect(200);
184+
185+
expect(mockClerkFrontendApiProxy).toHaveBeenCalled();
186+
});
187+
188+
it('does not intercept non-proxy paths when path reduces to empty string', async () => {
189+
// path: '/' strips to '' — without the fallback guard, this would match everything
190+
const response = await runMiddlewareOnPath(
191+
clerkMiddleware({ frontendApiProxy: { enabled: true, path: '/' } }),
192+
'/api/users',
193+
{
194+
Cookie: '__client_uat=1711618859;',
195+
'Sec-Fetch-Dest': 'document',
196+
},
197+
).expect(307);
198+
199+
expect(response.header).toHaveProperty('x-clerk-auth-status', 'handshake');
200+
expect(mockClerkFrontendApiProxy).not.toHaveBeenCalled();
201+
});
202+
174203
it('still authenticates requests to other paths when proxy is configured', async () => {
175204
const response = await runMiddlewareOnPath(
176205
clerkMiddleware({ frontendApiProxy: { enabled: true } }),

0 commit comments

Comments
 (0)