From ebf77f74b7bcbc61bc85780de9fa00b23b8e5a85 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 11 Jun 2019 12:19:49 +0200 Subject: [PATCH] Revert "DEV: prevents csrf token to leak state between tests (#7746)" This reverts commit b29d63a52d4e1ae5e0ab1127c47663dc79e953a9. --- .../discourse/initializers/csrf-token.js.es6 | 19 ++++--------------- test/javascripts/helpers/qunit-helpers.js.es6 | 2 -- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/discourse/initializers/csrf-token.js.es6 b/app/assets/javascripts/discourse/initializers/csrf-token.js.es6 index 46a6d05d80c..fd95c274d96 100644 --- a/app/assets/javascripts/discourse/initializers/csrf-token.js.es6 +++ b/app/assets/javascripts/discourse/initializers/csrf-token.js.es6 @@ -1,27 +1,16 @@ // Append our CSRF token to AJAX requests when necessary. -let _crsfCallbacks; - export default { name: "csrf-token", - - initialize(container) { - const session = container.lookup("session:main"); - _crsfCallbacks = $.Callbacks(); + initialize: function(container) { + var session = container.lookup("session:main"); // Add a CSRF token to all AJAX requests session.set("csrfToken", $("meta[name=csrf-token]").attr("content")); - _crsfCallbacks.add(function(options, originalOptions, xhr) { + $.ajaxPrefilter(function(options, originalOptions, xhr) { if (!options.crossDomain) { - xhr.setRequestHeader("X-CSRF-Token", session.csrfToken); + xhr.setRequestHeader("X-CSRF-Token", session.get("csrfToken")); } }); - - $.ajaxPrefilter(_crsfCallbacks); } }; - -export function resetCsrfCallbacks() { - _crsfCallbacks.empty(); - _crsfCallbacks = null; -} diff --git a/test/javascripts/helpers/qunit-helpers.js.es6 b/test/javascripts/helpers/qunit-helpers.js.es6 index 49271568023..759e64f7064 100644 --- a/test/javascripts/helpers/qunit-helpers.js.es6 +++ b/test/javascripts/helpers/qunit-helpers.js.es6 @@ -16,7 +16,6 @@ import { resetDecorators } from "discourse/widgets/widget"; import { resetDecorators as resetPostCookedDecorators } from "discourse/widgets/post-cooked"; import { resetCache as resetOneboxCache } from "pretty-text/oneboxer"; import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic"; -import { resetCsrfCallbacks } from "discourse/initializers/csrf-token"; export function currentUser() { return Discourse.User.create( @@ -129,7 +128,6 @@ export function acceptance(name, options) { resetPostCookedDecorators(); resetOneboxCache(); resetCustomPostMessageCallbacks(); - resetCsrfCallbacks(); Discourse.reset(); } });