提交 6132d963 编写于 作者: N Nick Uraltsev 提交者: GitHub

Merge pull request #406 from pracucci/master

Fixing xsrf header on missing xsrfCookieName
......@@ -103,7 +103,7 @@ module.exports = function xhrAdapter(config) {
var cookies = require('./../helpers/cookies');
// Add xsrf header
var xsrfValue = config.withCredentials || isURLSameOrigin(config.url) ?
var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
cookies.read(config.xsrfCookieName) :
undefined;
......
var cookies = require('../../lib/helpers/cookies');
describe('xsrf', function () {
beforeEach(function () {
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) {
document.cookie = axios.defaults.xsrfCookieName + '=12345';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册