Skip to content

Commit

Permalink
test(express): Make sure debug headers are not injected by default (#…
Browse files Browse the repository at this point in the history
…4189)

Co-authored-by: Laura Beatris <[email protected]>
  • Loading branch information
wobsoriano and LauraBeatris authored Sep 19, 2024
1 parent ef824dc commit 8ef124e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .changeset/four-wolves-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
16 changes: 11 additions & 5 deletions packages/express/src/__tests__/clerkMiddleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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;',
Expand All @@ -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: {},
Expand All @@ -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');

Expand Down

0 comments on commit 8ef124e

Please sign in to comment.