all files / lib/strategy/ ValidateClientConfigStrategy.js

16% Statements 4/25
0% Branches 0/22
0% Functions 0/3
16% Lines 4/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                                                       
'use strict';
 
var extend = require('../helpers/clone-extend').extend;
 
/**
 * Represents a strategy that validates the configuration (post loading).
 *
 * @class
 */
function ValidateClientConfigStrategy () {
}
 
ValidateClientConfigStrategy.prototype.process = function (config, callback) {
  var newError = function (err) {
    callback(new Error(err));
  };
 
  if (!config) {
    return newError("Configuration not instantiated.");
  }
 
  var client = config.client;
 
  if (!client) {
    return newError("Client cannot be empty.");
  }
 
  var apiKey = client.apiKey;
 
  if (!apiKey) {
    return newError("API key cannot be empty.");
  } if (!apiKey.id || !apiKey.secret) {
    return newError("API key ID and secret is required.");
  }
 
  var application = config.application;
 
  if (!application) {
    return newError("Application cannot be empty.");
  }
 
  if (application.href && application.href.indexOf('/applications/') === -1) {
    return newError("Application HREF '" + application.href + "' is not a valid Stormpath Application HREF.");
  }
 
  var web = config.web;
 
  if (web && web.spa && web.spa.enabled && web.spa.view === null) {
    return newError("SPA mode is enabled but stormpath.web.spa.view isn't set. This needs to be the absolute path to the file that you want to serve as your SPA entry.");
  }
 
  callback(null, config);
};
 
module.exports = ValidateClientConfigStrategy;