diff --git a/lib/primary.js b/lib/primary.js index 52be47ec47ef27a58cc4359a4f8541a93c3013e0..b9d0c4167f4b97bdf3d999abfa52669cfce9707e 100644 --- a/lib/primary.js +++ b/lib/primary.js @@ -56,13 +56,14 @@ function parseWellKnownBody(body, domain, delegates, cb) { bail = true; return cb("Too many hops while delegating authority " + JSON.stringify(dels)); } - logger.debug(domain,' is delegating to', v[k]); + logger.debug(domain + ' is delegating to' + v[k]); // recurse into low level get /.well-known/browserid and parse again? // If everything goes well, finally call our original callback delegates[domain] = dels.length; getWellKnown(v[k], delegates, function (err, nbody, ndomain, ndelegates) { if (err) { - cb(err); + bail = true; + return cb(err); } parseWellKnownBody(nbody, ndomain, ndelegates, cb); }); @@ -70,13 +71,16 @@ function parseWellKnownBody(body, domain, delegates, cb) { } }); if (bail) return; + var missing_keys = []; want.forEach(function(k) { if (-1 === got.indexOf(k)) { - cb("missing required key: " + k); + missing_keys.push(k); bail = true; } }); - if (bail) return; + if (bail) { + return cb("missing required key: " + missing_keys.join(', ')); + }; // Allow SHIMMED_PRIMARIES to change example.com into 127.0.0.1:10005 var url_prefix = 'https://' + domain; @@ -193,6 +197,8 @@ exports.checkSupport = function(domain, cb, delegates) { if (typeof domain !== 'string' || !domain.length) { return process.nextTick(function() { cb("invalid domain"); }); } + + getWellKnown(domain, delegates, function (err, body, domain, cbdelegates) { if (err) { logger.debug(err); @@ -221,6 +227,7 @@ exports.checkSupport = function(domain, cb, delegates) { } } }); + }; diff --git a/lib/wsapi/address_info.js b/lib/wsapi/address_info.js index 778bd4291953da0cc9af22988a039bd80e67cab3..9a4c9009f138bc4971ddd06fc2271ae520c3d25e 100644 --- a/lib/wsapi/address_info.js +++ b/lib/wsapi/address_info.js @@ -30,8 +30,13 @@ exports.process = function(req, res) { if (!m) { return httputils.badRequest(res, "invalid email address"); } - + // Saftey value for production branch only + var done = false; primary.checkSupport(m[1], function(err, urls, publicKey, delegates) { + if (done) { + return; + } + done = true; if (err) { logger.warn('error checking "' + m[1] + '" for primary support: ' + err); return httputils.serverError(res, "can't check email address");