mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor: move CSRF code into plugin (#56447)
This commit is contained in:
committed by
GitHub
parent
86527f448c
commit
ced457fed5
+3
-2
@@ -3,6 +3,7 @@ import request from 'supertest';
|
||||
import { build } from './src/app';
|
||||
import { createUserInput } from './src/utils/create-user';
|
||||
import { examJson } from './__mocks__/exam';
|
||||
import { CSRF_COOKIE, CSRF_HEADER } from './src/plugins/csrf';
|
||||
|
||||
type FastifyTestInstance = Awaited<ReturnType<typeof build>>;
|
||||
|
||||
@@ -25,7 +26,7 @@ const requests = {
|
||||
};
|
||||
|
||||
export const getCsrfToken = (setCookies: string[]): string | undefined => {
|
||||
const csrfSetCookie = setCookies.find(str => str.includes('csrf_token'));
|
||||
const csrfSetCookie = setCookies.find(str => str.includes(CSRF_COOKIE));
|
||||
const [csrfCookie] = csrfSetCookie?.split(';') ?? [];
|
||||
const [_key, csrfToken] = csrfCookie?.split('=') ?? [];
|
||||
|
||||
@@ -72,7 +73,7 @@ export function superRequest(
|
||||
|
||||
const csrfToken = (setCookies && getCsrfToken(setCookies)) ?? '';
|
||||
if (sendCSRFToken) {
|
||||
void req.set('CSRF-Token', csrfToken);
|
||||
void req.set(CSRF_HEADER, csrfToken);
|
||||
}
|
||||
return req;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user