Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing requestHeaders.Authorization #3287

Merged
merged 2 commits into from Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/adapters/xhr.js
Expand Up @@ -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);
}

Expand Down
16 changes: 15 additions & 1 deletion test/specs/__helpers.js
Expand Up @@ -76,6 +76,21 @@ 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();

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: {
Expand All @@ -86,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();
Expand Down