From 8ef124ea6155b48fe27c71d4416383fe81f9c76f Mon Sep 17 00:00:00 2001 From: Robert Soriano Date: Thu, 19 Sep 2024 06:38:03 -0700 Subject: [PATCH] test(express): Make sure debug headers are not injected by default (#4189) Co-authored-by: Laura Beatris <48022589+LauraBeatris@users.noreply.github.com> --- .changeset/four-wolves-float.md | 2 ++ .../src/__tests__/clerkMiddleware.test.ts | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/four-wolves-float.md diff --git a/.changeset/four-wolves-float.md b/.changeset/four-wolves-float.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/four-wolves-float.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/express/src/__tests__/clerkMiddleware.test.ts b/packages/express/src/__tests__/clerkMiddleware.test.ts index e57da8a623..2ae6308b8d 100644 --- a/packages/express/src/__tests__/clerkMiddleware.test.ts +++ b/packages/express/src/__tests__/clerkMiddleware.test.ts @@ -70,9 +70,6 @@ describe('clerkMiddleware', () => { it('supports usage without parameters: app.use(clerkMiddleware())', async () => { await runMiddleware(clerkMiddleware(), { Cookie: '__clerk_db_jwt=deadbeef;' }).expect(200, 'Hello world!'); - - // TODO: Observability headers are not added by default - // assertSignedOutDebugHeaders(response); }); it('supports usage with parameters: app.use(clerkMiddleware(options))', async () => { @@ -140,6 +137,15 @@ describe('clerkMiddleware', () => { expect(response.header).not.toHaveProperty('x-clerk-auth-custom', 'custom-value'); }); + it('disables handshake flow by default', async () => { + const response = await runMiddleware(clerkMiddleware(), { + Cookie: '__client_uat=1711618859;', + 'Sec-Fetch-Dest': 'document', + }).expect(200); + + assertNoDebugHeaders(response); + }); + it('supports handshake flow', async () => { const response = await runMiddleware(clerkMiddleware({ enableHandshake: true }), { Cookie: '__client_uat=1711618859;', @@ -150,7 +156,7 @@ describe('clerkMiddleware', () => { expect(response.header).toHaveProperty('location', expect.stringContaining('/v1/client/handshake?redirect_url=')); }); - it('it calls next with an error when request URL is invalid', async () => { + it('calls next with an error when request URL is invalid', () => { const req = { url: '//', cookies: {}, @@ -159,7 +165,7 @@ describe('clerkMiddleware', () => { const res = {} as Response; const mockNext = jest.fn(); - await clerkMiddleware()[0](req, res, mockNext); + clerkMiddleware()[0](req, res, mockNext); expect(mockNext.mock.calls[0][0].message).toBe('Invalid URL');