From cf15b1f53d894e8960495cbe8265b3453e22c15d Mon Sep 17 00:00:00 2001 From: Stephen Glass Date: Mon, 29 Jul 2024 17:12:28 -0400 Subject: [PATCH] use cookie parser in test instead of mock Signed-off-by: Stephen Glass --- .../createCookieAuthErrorMiddleware.test.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/plugins/auth-backend/src/service/createCookieAuthErrorMiddleware.test.ts b/plugins/auth-backend/src/service/createCookieAuthErrorMiddleware.test.ts index 1d270a953f..f0c547842a 100644 --- a/plugins/auth-backend/src/service/createCookieAuthErrorMiddleware.test.ts +++ b/plugins/auth-backend/src/service/createCookieAuthErrorMiddleware.test.ts @@ -16,6 +16,7 @@ import express from 'express'; import request from 'supertest'; +import cookieParser from 'cookie-parser'; import { createCookieAuthErrorMiddleware } from './createCookieAuthErrorMiddleware'; const AUTH_ERROR_COOKIE = 'auth-error'; @@ -28,19 +29,7 @@ describe('createCookieAuthErrorMiddleware', () => { app.use(express.json()); app.use(express.urlencoded({ extended: true })); - // Mock cookie parser middleware - app.use((req, _, next) => { - req.cookies = {}; - const cookieHeader = req.headers.cookie; - if (cookieHeader) { - const cookies = cookieHeader.split(';'); - cookies.forEach(cookie => { - const [name, ...rest] = cookie.split('='); - req.cookies[name.trim()] = decodeURIComponent(rest.join('=')); - }); - } - next(); - }); + app.use(cookieParser()); app.use( createCookieAuthErrorMiddleware(