Skip to content

Commit

Permalink
Allow error bubbling while resolving applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis J Van Wetering IV committed Apr 13, 2016
1 parent 43fc93a commit d1dac67
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serveros",
"version": "0.2.6",
"version": "0.3.0",
"description": "Auth for networks of applications.",
"repository": {
"type": "git",
Expand Down
14 changes: 10 additions & 4 deletions src/classes/ServerosMaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/errors/master/ApplicationResolutionError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
*
Expand All @@ -36,6 +45,7 @@ ApplicationResolutionError.prototype.applicationType = "No Application Type Prov
ApplicationResolutionError.prototype.additionalInformation = function() {
return {
type: this.applicationType
, cause: this.cause
};
};

Expand Down

0 comments on commit d1dac67

Please sign in to comment.