Skip to content

Commit

Permalink
validator: make sure the requested transport is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
esatterwhite committed May 2, 2017
1 parent b206164 commit effa81d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
8 changes: 8 additions & 0 deletions lib/server/api/validators/timer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'
const type_exp = /^\[object (.*)\]$/
const transports = require('../../../transports')

function typeOf(obj) {
if (obj === null) return 'Null';
if (obj === undefined) return 'Undefined';
Expand All @@ -26,12 +28,18 @@ module.exports = function(data = {}, cb) {
err.statusCode = 400;
return setImmediate(cb, err);
}

if (typeOf(data.callback.transport) !== 'String') {
const err = new TypeError('callback.transport is required and must be a string');
err.statusCode = 400;
return setImmediate(cb, err);
}

if (typeOf(transports[data.callback.transport]) !== 'Function') {
const err = new Error(`unknown transport ${data.callback.transport}`)
err.statusCode = 400
return setImmediate(cb, err)
}
if (typeOf(data.callback.uri) !== 'String') {
const err = new TypeError('callback.uri is required and must be a string');
err.statusCode = 400;
Expand Down
20 changes: 4 additions & 16 deletions lib/transports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,15 @@
*/

const callback = require('./callback')
const ENV = process.env.NODE_ENV
/**
* DESCRIPTION
* @memberof module:skyring/lib/transports
* @property {Object} http The HTTP transport
**/
exports.http = require('./http');

Object.defineProperty(exports, 'callback',{
enumerable: false
, configurable: false
, get: function(){
switch(process.env.NODE_ENV){
case 'production':
case 'prod':
const err = new Error('callback transport is for testing only')
err.name = 'TransportError';
err.code = 'ENOTRANSPORT';
throw err;
if(!ENV || ENV === 'development' || ENV === 'test') {
exports.callback = callback
}

default:
return callback;
}
}
});

0 comments on commit effa81d

Please sign in to comment.