mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-05-31 00:00:07 +08:00
fix #36: setting basic authentication not working correctly
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user