mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Fixing requestHeaders.Authorization (#3287)
This commit is contained in:
+1
-1
@@ -30,7 +30,7 @@ module.exports = function xhrAdapter(config) {
|
|||||||
// HTTP basic authentication
|
// HTTP basic authentication
|
||||||
if (config.auth) {
|
if (config.auth) {
|
||||||
var username = config.auth.username || '';
|
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);
|
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-1
@@ -76,6 +76,21 @@ setupBasicAuthTest = function setupBasicAuthTest() {
|
|||||||
}, 100);
|
}, 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) {
|
it('should accept HTTP Basic auth credentials with non-Latin1 characters in password', function (done) {
|
||||||
axios('/foo', {
|
axios('/foo', {
|
||||||
auth: {
|
auth: {
|
||||||
@@ -86,7 +101,6 @@ setupBasicAuthTest = function setupBasicAuthTest() {
|
|||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var request = jasmine.Ajax.requests.mostRecent();
|
var request = jasmine.Ajax.requests.mostRecent();
|
||||||
console.log(request.requestHeaders['Authorization'], '\n\n\n');
|
|
||||||
|
|
||||||
expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjpvcGVuIMOfw6fCo+KYg3Nlc2FtZQ==');
|
expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjpvcGVuIMOfw6fCo+KYg3Nlc2FtZQ==');
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user