Skip to content

Commit 04d45f2

Browse files
authored
Fixing requestHeaders.Authorization (#3287)
1 parent e8c6e19 commit 04d45f2

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/adapters/xhr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function xhrAdapter(config) {
3030
// HTTP basic authentication
3131
if (config.auth) {
3232
var username = config.auth.username || '';
33-
var password = unescape(encodeURIComponent(config.auth.password)) || '';
33+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
3434
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
3535
}
3636

test/specs/__helpers.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ setupBasicAuthTest = function setupBasicAuthTest() {
7676
}, 100);
7777
});
7878

79+
it('should accept HTTP Basic auth credentials without the password parameter', function (done) {
80+
axios('/foo', {
81+
auth: {
82+
username: 'Aladdin'
83+
}
84+
});
85+
86+
setTimeout(function () {
87+
var request = jasmine.Ajax.requests.mostRecent();
88+
89+
expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjo=');
90+
done();
91+
}, 100);
92+
});
93+
7994
it('should accept HTTP Basic auth credentials with non-Latin1 characters in password', function (done) {
8095
axios('/foo', {
8196
auth: {
@@ -86,7 +101,6 @@ setupBasicAuthTest = function setupBasicAuthTest() {
86101

87102
setTimeout(function () {
88103
var request = jasmine.Ajax.requests.mostRecent();
89-
console.log(request.requestHeaders['Authorization'], '\n\n\n');
90104

91105
expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjpvcGVuIMOfw6fCo+KYg3Nlc2FtZQ==');
92106
done();

0 commit comments

Comments
 (0)