mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Merge pull request #406 from pracucci/master
Fixing xsrf header on missing xsrfCookieName
This commit is contained in:
+1
-1
@@ -103,7 +103,7 @@ module.exports = function xhrAdapter(config) {
|
|||||||
var cookies = require('./../helpers/cookies');
|
var cookies = require('./../helpers/cookies');
|
||||||
|
|
||||||
// Add xsrf header
|
// Add xsrf header
|
||||||
var xsrfValue = config.withCredentials || isURLSameOrigin(config.url) ?
|
var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
|
||||||
cookies.read(config.xsrfCookieName) :
|
cookies.read(config.xsrfCookieName) :
|
||||||
undefined;
|
undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
var cookies = require('../../lib/helpers/cookies');
|
||||||
|
|
||||||
describe('xsrf', function () {
|
describe('xsrf', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
jasmine.Ajax.install();
|
jasmine.Ajax.install();
|
||||||
@@ -28,6 +30,32 @@ describe('xsrf', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not set xsrf header if xsrfCookieName is null', function (done) {
|
||||||
|
document.cookie = axios.defaults.xsrfCookieName + '=12345';
|
||||||
|
|
||||||
|
axios('/foo', {
|
||||||
|
xsrfCookieName: null
|
||||||
|
});
|
||||||
|
|
||||||
|
getAjaxRequest().then(function (request) {
|
||||||
|
expect(request.requestHeaders[axios.defaults.xsrfHeaderName]).toEqual(undefined);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not read cookies at all if xsrfCookieName is null', function (done) {
|
||||||
|
spyOn(cookies, "read");
|
||||||
|
|
||||||
|
axios('/foo', {
|
||||||
|
xsrfCookieName: null
|
||||||
|
});
|
||||||
|
|
||||||
|
getAjaxRequest().then(function (request) {
|
||||||
|
expect(cookies.read).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should not set xsrf header for cross origin', function (done) {
|
it('should not set xsrf header for cross origin', function (done) {
|
||||||
document.cookie = axios.defaults.xsrfCookieName + '=12345';
|
document.cookie = axios.defaults.xsrfCookieName + '=12345';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user