/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['middleware/basicAuth.js']) {
  _$jscoverage['middleware/basicAuth.js'] = [];
  _$jscoverage['middleware/basicAuth.js'][13] = 0;
  _$jscoverage['middleware/basicAuth.js'][48] = 0;
  _$jscoverage['middleware/basicAuth.js'][49] = 0;
  _$jscoverage['middleware/basicAuth.js'][52] = 0;
  _$jscoverage['middleware/basicAuth.js'][53] = 0;
  _$jscoverage['middleware/basicAuth.js'][54] = 0;
  _$jscoverage['middleware/basicAuth.js'][55] = 0;
  _$jscoverage['middleware/basicAuth.js'][56] = 0;
  _$jscoverage['middleware/basicAuth.js'][57] = 0;
  _$jscoverage['middleware/basicAuth.js'][58] = 0;
  _$jscoverage['middleware/basicAuth.js'][62] = 0;
  _$jscoverage['middleware/basicAuth.js'][64] = 0;
  _$jscoverage['middleware/basicAuth.js'][65] = 0;
  _$jscoverage['middleware/basicAuth.js'][67] = 0;
  _$jscoverage['middleware/basicAuth.js'][68] = 0;
  _$jscoverage['middleware/basicAuth.js'][70] = 0;
  _$jscoverage['middleware/basicAuth.js'][72] = 0;
  _$jscoverage['middleware/basicAuth.js'][74] = 0;
  _$jscoverage['middleware/basicAuth.js'][78] = 0;
  _$jscoverage['middleware/basicAuth.js'][80] = 0;
  _$jscoverage['middleware/basicAuth.js'][84] = 0;
  _$jscoverage['middleware/basicAuth.js'][85] = 0;
  _$jscoverage['middleware/basicAuth.js'][86] = 0;
  _$jscoverage['middleware/basicAuth.js'][87] = 0;
  _$jscoverage['middleware/basicAuth.js'][88] = 0;
  _$jscoverage['middleware/basicAuth.js'][89] = 0;
  _$jscoverage['middleware/basicAuth.js'][90] = 0;
  _$jscoverage['middleware/basicAuth.js'][94] = 0;
  _$jscoverage['middleware/basicAuth.js'][95] = 0;
  _$jscoverage['middleware/basicAuth.js'][96] = 0;
  _$jscoverage['middleware/basicAuth.js'][98] = 0;
}
_$jscoverage['middleware/basicAuth.js'][13]++;
var utils = require("../utils"), unauthorized = utils.unauthorized;
_$jscoverage['middleware/basicAuth.js'][48]++;
module.exports = (function basicAuth(callback, realm) {
  _$jscoverage['middleware/basicAuth.js'][49]++;
  var username, password;
  _$jscoverage['middleware/basicAuth.js'][52]++;
  if ("string" == typeof callback) {
    _$jscoverage['middleware/basicAuth.js'][53]++;
    username = callback;
    _$jscoverage['middleware/basicAuth.js'][54]++;
    password = realm;
    _$jscoverage['middleware/basicAuth.js'][55]++;
    if ("string" != typeof password) {
      _$jscoverage['middleware/basicAuth.js'][55]++;
      throw new Error("password argument required");
    }
    _$jscoverage['middleware/basicAuth.js'][56]++;
    realm = arguments[2];
    _$jscoverage['middleware/basicAuth.js'][57]++;
    callback = (function (user, pass) {
  _$jscoverage['middleware/basicAuth.js'][58]++;
  return user == username && pass == password;
});
  }
  _$jscoverage['middleware/basicAuth.js'][62]++;
  realm = realm || "Authorization Required";
  _$jscoverage['middleware/basicAuth.js'][64]++;
  return (function (req, res, next) {
  _$jscoverage['middleware/basicAuth.js'][65]++;
  var authorization = req.headers.authorization;
  _$jscoverage['middleware/basicAuth.js'][67]++;
  if (req.user) {
    _$jscoverage['middleware/basicAuth.js'][67]++;
    return next();
  }
  _$jscoverage['middleware/basicAuth.js'][68]++;
  if (! authorization) {
    _$jscoverage['middleware/basicAuth.js'][68]++;
    return unauthorized(res, realm);
  }
  _$jscoverage['middleware/basicAuth.js'][70]++;
  var parts = authorization.split(" ");
  _$jscoverage['middleware/basicAuth.js'][72]++;
  if (parts.length !== 2) {
    _$jscoverage['middleware/basicAuth.js'][72]++;
    return next(utils.error(400));
  }
  _$jscoverage['middleware/basicAuth.js'][74]++;
  var scheme = parts[0], credentials = new Buffer(parts[1], "base64").toString(), index = credentials.indexOf(":");
  _$jscoverage['middleware/basicAuth.js'][78]++;
  if ("Basic" != scheme || index < 0) {
    _$jscoverage['middleware/basicAuth.js'][78]++;
    return next(utils.error(400));
  }
  _$jscoverage['middleware/basicAuth.js'][80]++;
  var user = credentials.slice(0, index), pass = credentials.slice(index + 1);
  _$jscoverage['middleware/basicAuth.js'][84]++;
  if (callback.length >= 3) {
    _$jscoverage['middleware/basicAuth.js'][85]++;
    var pause = utils.pause(req);
    _$jscoverage['middleware/basicAuth.js'][86]++;
    callback(user, pass, (function (err, user) {
  _$jscoverage['middleware/basicAuth.js'][87]++;
  if (err || ! user) {
    _$jscoverage['middleware/basicAuth.js'][87]++;
    return unauthorized(res, realm);
  }
  _$jscoverage['middleware/basicAuth.js'][88]++;
  req.user = req.remoteUser = user;
  _$jscoverage['middleware/basicAuth.js'][89]++;
  next();
  _$jscoverage['middleware/basicAuth.js'][90]++;
  pause.resume();
}));
  }
  else {
    _$jscoverage['middleware/basicAuth.js'][94]++;
    if (callback(user, pass)) {
      _$jscoverage['middleware/basicAuth.js'][95]++;
      req.user = req.remoteUser = user;
      _$jscoverage['middleware/basicAuth.js'][96]++;
      next();
    }
    else {
      _$jscoverage['middleware/basicAuth.js'][98]++;
      unauthorized(res, realm);
    }
  }
});
});
_$jscoverage['middleware/basicAuth.js'].source = ["","/*!"," * Connect - basicAuth"," * Copyright(c) 2010 Sencha Inc."," * Copyright(c) 2011 TJ Holowaychuk"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var utils = require('../utils')","  , unauthorized = utils.unauthorized;","","/**"," * Basic Auth:"," *"," * Enfore basic authentication by providing a `callback(user, pass)`,"," * which must return `true` in order to gain access. Alternatively an async"," * method is provided as well, invoking `callback(user, pass, callback)`. Populates"," * `req.user`. The final alternative is simply passing username / password"," * strings."," *"," *  Simple username and password"," *"," *     connect(connect.basicAuth('username', 'password'));"," *"," *  Callback verification"," *"," *     connect()"," *       .use(connect.basicAuth(function(user, pass){"," *         return 'tj' == user &amp; 'wahoo' == pass;"," *       }))"," *"," *  Async callback verification, accepting `fn(err, user)`."," *"," *     connect()"," *       .use(connect.basicAuth(function(user, pass, fn){"," *         User.authenticate({ user: user, pass: pass }, fn);"," *       }))"," *"," * @param {Function|String} callback or username"," * @param {String} realm"," * @api public"," */","","module.exports = function basicAuth(callback, realm) {","  var username, password;","","  // user / pass strings","  if ('string' == typeof callback) {","    username = callback;","    password = realm;","    if ('string' != typeof password) throw new Error('password argument required');","    realm = arguments[2];","    callback = function(user, pass){","      return user == username &amp;&amp; pass == password;","    }","  }","","  realm = realm || 'Authorization Required';","","  return function(req, res, next) {","    var authorization = req.headers.authorization;","","    if (req.user) return next();","    if (!authorization) return unauthorized(res, realm);","","    var parts = authorization.split(' ');","","    if (parts.length !== 2) return next(utils.error(400));","","    var scheme = parts[0]","      , credentials = new Buffer(parts[1], 'base64').toString()","      , index = credentials.indexOf(':');","","    if ('Basic' != scheme || index &lt; 0) return next(utils.error(400));","    ","    var user = credentials.slice(0, index)","      , pass = credentials.slice(index + 1);","","    // async","    if (callback.length &gt;= 3) {","      var pause = utils.pause(req);","      callback(user, pass, function(err, user){","        if (err || !user)  return unauthorized(res, realm);","        req.user = req.remoteUser = user;","        next();","        pause.resume();","      });","    // sync","    } else {","      if (callback(user, pass)) {","        req.user = req.remoteUser = user;","        next();","      } else {","        unauthorized(res, realm);","      }","    }","  }","};",""];
