From 9aa460c0fd7c8ff502ddc7561d5583f71c25c29a Mon Sep 17 00:00:00 2001 From: Allanbcruz Date: Sun, 13 Sep 2020 17:24:28 -0300 Subject: [PATCH 1/2] Fixing requestHeaders.Authorization Correction of the requestHeaders.Authorization parameter concatenation. Close #3286. --- lib/adapters/xhr.js | 2 +- test/specs/__helpers.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index f83f1444bc..71e3a5e67c 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -30,7 +30,7 @@ module.exports = function xhrAdapter(config) { // HTTP basic authentication if (config.auth) { var username = config.auth.username || ''; - var password = unescape(encodeURIComponent(config.auth.password)) || ''; + var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : ''; requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password); } diff --git a/test/specs/__helpers.js b/test/specs/__helpers.js index 660ae09a53..4830f71655 100644 --- a/test/specs/__helpers.js +++ b/test/specs/__helpers.js @@ -76,6 +76,22 @@ setupBasicAuthTest = function setupBasicAuthTest() { }, 100); }); + it('should accept HTTP Basic auth credentials without the password parameter', function (done) { + axios('/foo', { + auth: { + username: 'Aladdin' + } + }); + + setTimeout(function () { + var request = jasmine.Ajax.requests.mostRecent(); + console.log(request.requestHeaders['Authorization'], '\n\n\n'); + + expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjo='); + done(); + }, 100); + }); + it('should accept HTTP Basic auth credentials with non-Latin1 characters in password', function (done) { axios('/foo', { auth: { From 4422e5d711c3839cbdae87b561882bf4e3836dc2 Mon Sep 17 00:00:00 2001 From: Allan Cruz <57270969+Allanbcruz@users.noreply.github.com> Date: Sat, 19 Sep 2020 17:23:36 -0300 Subject: [PATCH 2/2] Update __helpers.js --- test/specs/__helpers.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/specs/__helpers.js b/test/specs/__helpers.js index 4830f71655..a08b8eb1cc 100644 --- a/test/specs/__helpers.js +++ b/test/specs/__helpers.js @@ -85,7 +85,6 @@ setupBasicAuthTest = function setupBasicAuthTest() { setTimeout(function () { var request = jasmine.Ajax.requests.mostRecent(); - console.log(request.requestHeaders['Authorization'], '\n\n\n'); expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjo='); done(); @@ -102,7 +101,6 @@ setupBasicAuthTest = function setupBasicAuthTest() { setTimeout(function () { var request = jasmine.Ajax.requests.mostRecent(); - console.log(request.requestHeaders['Authorization'], '\n\n\n'); expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjpvcGVuIMOfw6fCo+KYg3Nlc2FtZQ=='); done();