From d1dac67a3696ed626d228699c01c4680c163b8e8 Mon Sep 17 00:00:00 2001 From: Francis J Van Wetering IV Date: Wed, 13 Apr 2016 17:51:35 -0400 Subject: [PATCH] Allow error bubbling while resolving applications. --- package.json | 2 +- src/classes/ServerosMaster.js | 14 ++++++++++---- src/errors/master/ApplicationResolutionError.js | 12 +++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6053b30..0a26fd9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serveros", - "version": "0.2.6", + "version": "0.3.0", "description": "Auth for networks of applications.", "repository": { "type": "git", diff --git a/src/classes/ServerosMaster.js b/src/classes/ServerosMaster.js index f11bf70..f260b41 100644 --- a/src/classes/ServerosMaster.js +++ b/src/classes/ServerosMaster.js @@ -73,17 +73,19 @@ ServerosMaster.prototype.authenticate = function(authenticationMessage, callback * A callback for the {@link SeverosMaster.publicKeyFunction} * @callback Serveros.ServerosMaster~publicKeyResponse * + * @param {object} error * @param {object} data App Data. * @param {mixed} data.id The id of the application. + * @param {mixed} data.publicKey The public key, or public keys of the requested application. * @param {string[]} [data.hashes={@link Serveros.Encrypter~hashes}] A list of acceptable hashes, in order of descending preference * @param {string[]} [data.ciphers={@link Serveros.Encrypter~ciphers}] A list of acceptable Ciphers, in order of descending preference * @param {integer} data.keysLast The amount of time, in milliseconds, this application wants to honor keys. * @param {mixed} data.authData Any additional data about the application that should be passed on to the service. */ try { - that.publicKeyFunction(decrypted.requester, decrypted.requested, function(requester) { - if (!requester) { - callback(new MasterError.ApplicationResolutionError("requester")); + that.publicKeyFunction(decrypted.requester, decrypted.requested, function(err, requester) { + if (err || !requester) { + callback(new MasterError.ApplicationResolutionError("requester", err)); return; } that.iverify(requester.publicKey @@ -209,7 +211,11 @@ ServerosMaster.prototype.getTicket = function(request, requester, privateKeyNum, var that = this , privateKey = this.privateKey instanceof Array ? this.privateKey[privateKeyNum] : this.privateKey ; - this.publicKeyFunction(request.requested, null, function(requested) { + this.publicKeyFunction(request.requested, null, function(err, requested) { + if (err || !requested) { + callback(new MasterError.ApplicationResolutionError("requested", err)); + return; + } that.buildTicket(request, requested, requester, function(err, ticket) { if (err) { callback(err); diff --git a/src/errors/master/ApplicationResolutionError.js b/src/errors/master/ApplicationResolutionError.js index 36e09aa..a518899 100644 --- a/src/errors/master/ApplicationResolutionError.js +++ b/src/errors/master/ApplicationResolutionError.js @@ -8,10 +8,12 @@ var ServerosError = require('../ServerosError') * @extends ServerosError * @inheritdoc * @param {String} applicationType the type of application being resolved - requester or requested. + * @param {mixed} [cause] The underlying error bubbled up by the publicKeyFunction */ -function ApplicationResolutionError(applicationType) { +function ApplicationResolutionError(applicationType, cause) { ServerosError.call(this, "Application resolution failed.", 422); if(applicationType) this.applicationType = applicationType; + if(cause) this.cause = cause; } ApplicationResolutionError.prototype = Object.create(ServerosError.prototype); @@ -28,6 +30,13 @@ Object.defineProperty(ApplicationResolutionError.prototype, 'constructor', { */ ApplicationResolutionError.prototype.applicationType = "No Application Type Provided."; +/** + * The underlying error, bubble up from below. + * + * @default + */ +ApplicationResolutionError.prototype.cause = null; + /** * Return the type of application which failed resoltion. * @@ -36,6 +45,7 @@ ApplicationResolutionError.prototype.applicationType = "No Application Type Prov ApplicationResolutionError.prototype.additionalInformation = function() { return { type: this.applicationType + , cause: this.cause }; };