From 5e08f7e60494243ced71d9ef33db13faa3628a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 14 Dec 2021 14:44:05 -0500 Subject: [PATCH] test: don't use csrf_token for get,head, options --- test/helpers/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/helpers/index.js b/test/helpers/index.js index eab17d186e..e9df664ee3 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -21,11 +21,19 @@ helpers.getCsrfToken = async (jar) => { }; helpers.request = async function (method, uri, options) { - const csrf_token = await helpers.getCsrfToken(options.jar); + const ignoreMethods = ['GET', 'HEAD', 'OPTIONS']; + const lowercaseMethod = String(method).toLowerCase(); + let csrf_token; + if (!ignoreMethods.some(method => method.toLowerCase() === lowercaseMethod)) { + csrf_token = await helpers.getCsrfToken(options.jar); + } + return new Promise((resolve, reject) => { options.headers = options.headers || {}; - options.headers['x-csrf-token'] = csrf_token; - request[method](`${nconf.get('url')}${uri}`, options, (err, res, body) => { + if (csrf_token) { + options.headers['x-csrf-token'] = csrf_token; + } + request[lowercaseMethod](`${nconf.get('url')}${uri}`, options, (err, res, body) => { if (err) reject(err); else resolve({ res, body }); });