Permalink
Browse files

allow for empty password on basic auth

  • Loading branch information...
1 parent ff91349 commit fffa809079f531a6067fbb818781ece29c015988 bitmage committed Nov 15, 2012
Showing with 12 additions and 1 deletion.
  1. +5 −1 lib/restler.js
  2. +7 −0 test/restler.js
View
@@ -24,6 +24,10 @@ function mixin(target, source) {
return target;
}
+function exists(thing) {
+ return typeof thing !== "undefined" && thing !== null;
+}
+
function Request(uri, options) {
this.url = url.parse(uri);
this.options = options;
@@ -109,7 +113,7 @@ mixin(Request.prototype, {
this.options.password = authParts[1];
}
- if (this.options.username && this.options.password) {
+ if (this.options.username && exists(this.options.password)) {
var b = new Buffer([this.options.username, this.options.password].join(':'));
this.headers['Authorization'] = "Basic " + b.toString('base64');
}
View
@@ -179,6 +179,13 @@ module.exports['Basic'] = {
});
},
+ 'Should send basic auth with blank password': function(test) {
+ rest.post(host, { username: 'danwrong', password: '' }).on('complete', function(data) {
+ test.re(data, /authorization\: Basic ZGFud3Jvbmc6/, 'should have "authorization "header');
+ test.done();
+ });
+ },
+
'Should send basic auth if in url': function(test) {
rest.post('http://danwrong:flange@' + hostname + ':' + port).on('complete', function(data) {
test.re(data, /authorization\: Basic ZGFud3Jvbmc6Zmxhbmdl/, 'should have "authorization" header');

0 comments on commit fffa809

Please sign in to comment.