From a76223307fbf83d5d1f4c3af1a6800097e07a278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 7 Jul 2023 09:57:03 +0200 Subject: [PATCH] refactor(core): Load `cookieParser` middleware only once (no-changelog) (#6614) [Server.ts already explicitly loads `cookieParser`](https://github.com/n8n-io/n8n/blob/master/packages/cli/src/Server.ts#L571) --- packages/cli/src/middlewares/auth.ts | 3 --- packages/cli/test/integration/shared/utils.ts | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/middlewares/auth.ts b/packages/cli/src/middlewares/auth.ts index f6a9764280..4a4dff63ff 100644 --- a/packages/cli/src/middlewares/auth.ts +++ b/packages/cli/src/middlewares/auth.ts @@ -1,6 +1,5 @@ import type { Application, NextFunction, Request, RequestHandler, Response } from 'express'; import jwt from 'jsonwebtoken'; -import cookieParser from 'cookie-parser'; import passport from 'passport'; import { Strategy } from 'passport-jwt'; import { sync as globSync } from 'fast-glob'; @@ -78,8 +77,6 @@ export const setupAuthMiddlewares = ( ignoredEndpoints: Readonly, restEndpoint: string, ) => { - // needed for testing; not adding overhead since it directly returns if req.cookies exists - app.use(cookieParser()); app.use(userManagementJwtAuth()); app.use(async (req: Request, res: Response, next: NextFunction) => { diff --git a/packages/cli/test/integration/shared/utils.ts b/packages/cli/test/integration/shared/utils.ts index ef6dbf2e96..54cef95a21 100644 --- a/packages/cli/test/integration/shared/utils.ts +++ b/packages/cli/test/integration/shared/utils.ts @@ -2,6 +2,7 @@ import { Container } from 'typedi'; import { randomBytes } from 'crypto'; import { existsSync } from 'fs'; +import cookieParser from 'cookie-parser'; import bodyParser from 'body-parser'; import { CronJob } from 'cron'; import express from 'express'; @@ -121,6 +122,7 @@ export async function initTestServer({ testServer.app.use(bodyParser.json()); testServer.app.use(bodyParser.urlencoded({ extended: true })); + testServer.app.use(cookieParser()); config.set('userManagement.jwtSecret', 'My JWT secret'); config.set('userManagement.isInstanceOwnerSetUp', false);