fix #36: setting basic authentication not working correctly

This commit is contained in:
Sefa Ilkimen
2017-10-26 12:11:14 +02:00
parent 8c596d80b0
commit 77c0a887ac
2 changed files with 9 additions and 2 deletions
+8
View File
@@ -15,6 +15,9 @@ describe('Advanced HTTP www interface', function() {
this.timeout(900000);
beforeEach(() => {
// mocked btoa function (base 64 encoding strings)
global.btoa = decoded => new Buffer(decoded).toString('base64');
mock('cordova/exec', noop);
mock(`${PLUGIN_ID}.angular-integration`, { registerService: noop });
mock(`${PLUGIN_ID}.cookie-handler`, {});
@@ -91,4 +94,9 @@ describe('Advanced HTTP www interface', function() {
http.get('https://www.google.de/?gws_rd=ssl', {}, { myKey: 'myValue' }, noop, noop);
});
it('sets basic authentication header correctly', () => {
http.useBasicAuth('name', 'pass');
http.headers['*'].Authorization.should.equal('Basic bmFtZTpwYXNz');
});
});
+1 -2
View File
@@ -151,8 +151,7 @@ var http = {
return {'Authorization': 'Basic ' + b64EncodeUnicode(username + ':' + password)};
},
useBasicAuth: function (username, password) {
this.headers['*'] = this.headers['*'] || {};
this.headers['*'].Authorization = 'Basic ' + b64EncodeUnicode(username + ':' + password);
this.setHeader('*', 'Authorization', 'Basic ' + b64EncodeUnicode(username + ':' + password));
},
setHeader: function () {
// this one is for being backward compatible