mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-09 01:01:04 -04:00
refactor: move CSRF code into plugin (#56447)
This commit is contained in:
committed by
GitHub
parent
86527f448c
commit
ced457fed5
@@ -1,5 +1,5 @@
|
||||
import { setupServer, superRequest } from '../jest.utils';
|
||||
import { HOME_LOCATION, COOKIE_DOMAIN } from './utils/env';
|
||||
import { HOME_LOCATION } from './utils/env';
|
||||
|
||||
jest.mock('./utils/env', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
@@ -12,26 +12,6 @@ jest.mock('./utils/env', () => {
|
||||
describe('server', () => {
|
||||
setupServer();
|
||||
|
||||
describe('CSRF protection', () => {
|
||||
it('should receive a new CSRF token with the expected properties', async () => {
|
||||
const response = await superRequest('/status/ping', { method: 'GET' });
|
||||
const newCookies = response.get('Set-Cookie');
|
||||
const csrfTokenCookie = newCookies.find(cookie =>
|
||||
cookie.includes('csrf_token')
|
||||
);
|
||||
|
||||
expect(csrfTokenCookie).toEqual(
|
||||
expect.stringContaining('SameSite=Strict')
|
||||
);
|
||||
expect(csrfTokenCookie).toEqual(
|
||||
expect.stringContaining(`Domain=${COOKIE_DOMAIN}`)
|
||||
);
|
||||
expect(csrfTokenCookie).toEqual(expect.stringContaining('Path=/'));
|
||||
// Since we're not mocking FREECODECAMP_NODE_ENV to production, there's no
|
||||
// point checking if it is secure (it won't be in testing).
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /', () => {
|
||||
test('should have OWASP recommended headers', async () => {
|
||||
const res = await superRequest('/', { method: 'GET' });
|
||||
|
||||
Reference in New Issue
Block a user