Skip to content

Commit

Permalink
closes hapijs#793
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Apr 26, 2013
1 parent 70c7625 commit 939f3c3
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 34 deletions.
14 changes: 7 additions & 7 deletions lib/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ internals.Auth.prototype.add = function (name, options) {
Utils.assert(name, 'Authentication strategy must have a name');
Utils.assert(!this._strategies[name], 'Authentication strategy name already exists');
Utils.assert(options && typeof options === 'object', 'Invalid strategy options');
Utils.assert(!options.scheme || ['basic', 'hawk', 'cookie', 'bewit'].indexOf(options.scheme) !== -1, name + ' has an unknown scheme: ' + options.scheme);
Utils.assert(!options.scheme || ['basic', 'hawk', 'cookie', 'bewit'].indexOf(options.scheme) !== -1, name, 'has an unknown scheme:', options.scheme);
Utils.assert(options.scheme || options.implementation, name + ' missing both scheme and extension implementation');
Utils.assert(!options.implementation || (typeof options.implementation === 'object' && typeof options.implementation.authenticate === 'function'), name + ' has invalid extension scheme implementation');
Utils.assert(!options.defaultMode || !this._defaultStrategy.name, 'Cannot set default required strategy more than once: ' + name + ' (already set to: ' + this._defaultStrategy + ')');
Utils.assert(!options.implementation || (typeof options.implementation === 'object' && typeof options.implementation.authenticate === 'function'), name, 'has invalid extension scheme implementation');
Utils.assert(!options.defaultMode || !this._defaultStrategy.name, 'Cannot set default required strategy more than once:', name, '- already set to:', this._defaultStrategy);

options.scheme = options.scheme || 'ext';
switch (options.scheme) {
Expand Down Expand Up @@ -101,10 +101,10 @@ internals.Auth.prototype.setupRoute = function (options) {
}

options.mode = options.mode || 'required';
Utils.assert(['required', 'optional', 'try'].indexOf(options.mode) !== -1, 'Unknown authentication mode: ' + options.mode);
Utils.assert(['required', 'optional', 'try'].indexOf(options.mode) !== -1, 'Unknown authentication mode:', options.mode);

Utils.assert(!options.entity || ['user', 'app', 'any'].indexOf(options.entity) !== -1, 'Unknown authentication entity type: ' + options.entity);
Utils.assert(!options.payload || ['required', 'optional'].indexOf(options.payload) !== -1, 'Unknown authentication payload mode: ' + options.entity);
Utils.assert(!options.entity || ['user', 'app', 'any'].indexOf(options.entity) !== -1, 'Unknown authentication entity type:', options.entity);
Utils.assert(!options.payload || ['required', 'optional'].indexOf(options.payload) !== -1, 'Unknown authentication payload mode:', options.entity);
Utils.assert(!(options.strategy && options.strategies), 'Route can only have a auth.strategy or auth.strategies (or use the default) but not both');
Utils.assert(!options.strategies || options.strategies.length, 'Cannot have empty auth.strategies array');
options.strategies = options.strategies || [options.strategy || 'default'];
Expand All @@ -114,7 +114,7 @@ internals.Auth.prototype.setupRoute = function (options) {
var hasAuthenticatePayload = false;
options.strategies.forEach(function (strategy) {

Utils.assert(self._strategies[strategy], 'Unknown authentication strategy: ' + strategy);
Utils.assert(self._strategies[strategy], 'Unknown authentication strategy:', strategy);
hasAuthenticatePayload = hasAuthenticatePayload || typeof self._strategies[strategy].authenticatePayload === 'function';
Utils.assert(options.payload !== 'required' || hasAuthenticatePayload, 'Payload validation can only be required when all strategies support it');
});
Expand Down
4 changes: 2 additions & 2 deletions lib/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ internals.Composer.prototype.start = function (callback) {
},
function (err) {

Utils.assert(!err, 'Failed starting plugins: ' + (err && err.message));
Utils.assert(!err, 'Failed starting plugins:', err && err.message);
return callback();
});
};
Expand All @@ -135,7 +135,7 @@ internals.Composer.prototype.stop = function (options, callback) {
},
function (err) {

Utils.assert(!err, 'Failed stopping plugins: ' + (err && err.message));
Utils.assert(!err, 'Failed stopping plugins:', err && err.message);
return callback();
});
};
8 changes: 4 additions & 4 deletions lib/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ internals.Ext.prototype._add = function (event, func, options, plugin) {

options = options || {};

Utils.assert(['onRequest', 'onPreAuth', 'onPostAuth', 'onPreHandler', 'onPostHandler', 'onPreResponse'].indexOf(event) !== -1, 'Unknown event type: ' + event);
Utils.assert(['onRequest', 'onPreAuth', 'onPostAuth', 'onPreHandler', 'onPostHandler', 'onPreResponse'].indexOf(event) !== -1, 'Unknown event type', event);

// Validate rules

var before = [].concat(options.before || []);
var after = [].concat(options.after || []);
var group = plugin || '?';

Utils.assert(before.indexOf(group) === -1, 'Plugin ext cannot come before itself (' + group + ')');
Utils.assert(before.indexOf(group) === -1, 'Plugin ext cannot come before itself:', group);
Utils.assert(before.indexOf('?') === -1, 'Plugin ext cannot come before unassociated exts');
Utils.assert(after.indexOf(group) === -1, 'Plugin ext cannot come after itself (' + group + ')');
Utils.assert(after.indexOf(group) === -1, 'Plugin ext cannot come after itself:', group);
Utils.assert(after.indexOf('?') === -1, 'Plugin ext cannot come after unassociated exts');

// Add functions
Expand All @@ -72,7 +72,7 @@ internals.Ext.prototype._add = function (event, func, options, plugin) {
// Insert event

var error = this.sort(event);
Utils.assert(!error, event + ' extension' + (plugin ? ' add by ' + plugin : '') + ' created a dependencies error');
Utils.assert(!error, event, 'extension', (plugin ? 'add by ' + plugin : ''), 'created a dependencies error');
};


Expand Down
8 changes: 4 additions & 4 deletions lib/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ internals.Pack.prototype._register = function (plugin, permissions, options, cal

Utils.assert(plugin, 'Missing plugin');
Utils.assert(callback, 'Missing callback');
Utils.assert(!this._env[plugin.name], 'Plugin already registered: ' + plugin.name);
Utils.assert(!this._env[plugin.name], 'Plugin already registered:', plugin.name);
Utils.assert(plugin.name, 'Plugin missing name');
Utils.assert(plugin.name !== '?', 'Plugin name cannot be \'?\'');
Utils.assert(plugin.version, 'Plugin missing version');
Expand Down Expand Up @@ -280,7 +280,7 @@ internals.Pack.prototype._register = function (plugin, permissions, options, cal
if (!_dependencies &&
dependencies[plugin.name]) {

Utils.assert(!dependencies[plugin.name].length, 'Plugin \'' + plugin.name + '\' missing dependencies: ' + dependencies[plugin.name].join(', '));
Utils.assert(!dependencies[plugin.name].length, 'Plugin', plugin.name, 'missing dependencies:', dependencies[plugin.name].join(', '));
}

callback(err);
Expand Down Expand Up @@ -406,7 +406,7 @@ internals.Pack.prototype._require = function (name, permissions, options, callba

dependencies[deps].forEach(function (dep) {

Utils.assert(self._env[dep], 'Plugin \'' + deps + '\' missing dependencies: ' + dep);
Utils.assert(self._env[dep], 'Plugin', deps, 'missing dependencies:', dep);
});
});

Expand Down Expand Up @@ -542,7 +542,7 @@ internals.Pack.prototype._provisionCache = function (options, type, name, segmen

Utils.assert(options, 'Invalid cache policy options');
Utils.assert(name, 'Invalid cache policy name');
Utils.assert(['helper', 'route', 'plugin'].indexOf(type) !== -1, 'Unknown cache policy type: ' + type);
Utils.assert(['helper', 'route', 'plugin'].indexOf(type) !== -1, 'Unknown cache policy type:', type);

if (type === 'helper') {
Utils.assert(!segment || segment.indexOf('##') === 0, 'Helper cache segment must start with \'##\'');
Expand Down
10 changes: 5 additions & 5 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ exports = module.exports = internals.Route = function (options, server, env) {
Utils.assert((typeof this.settings.handler === 'function') ^ !!this.settings.handler.proxy ^ !!this.settings.handler.file ^ !!this.settings.handler.directory ^ !!this.settings.handler.view ^ (this.settings.handler === 'notFound'), 'Handler must be a function or equal notFound or be an object with a proxy, file, directory, or view');

var schemaError = Schema.routeOptions(options);
Utils.assert(!schemaError, 'Invalid route options for \'' + options.path + '\': ' + schemaError);
Utils.assert(!schemaError, 'Invalid route options for', options.path, ':', schemaError);

schemaError = Schema.routeConfig(this.settings);
Utils.assert(!schemaError, 'Invalid route config for \'' + options.path + '\': ' + schemaError);
Utils.assert(!schemaError, 'Invalid route config for', options.path, ':', schemaError);

this.server = server;
this.env = env || {}; // Plugin-specific environment
Expand All @@ -43,7 +43,7 @@ exports = module.exports = internals.Route = function (options, server, env) {
this.path = options.path;
this.settings.method = this.method; // Expose method in settings

Utils.assert(this.path.match(internals.Route.validatePathRegex), 'Invalid path: ' + this.path);
Utils.assert(this.path.match(internals.Route.validatePathRegex), 'Invalid path:', this.path);
Utils.assert(this.path.match(internals.Route.validatePathEncodedRegex) === null, 'Path cannot contain encoded non-reserved path characters');

this.settings.plugins = this.settings.plugins || {}; // Route-specific plugins settings, namespaced using plugin name
Expand Down Expand Up @@ -73,7 +73,7 @@ exports = module.exports = internals.Route = function (options, server, env) {
var modes = {};
this.settings.cache.mode.forEach(function (mode) {

Utils.assert(mode === 'client' || mode === 'server', 'Unknown cache mode: ' + mode);
Utils.assert(mode === 'client' || mode === 'server', 'Unknown cache mode:', mode);
modes[mode] = true;
});

Expand Down Expand Up @@ -122,7 +122,7 @@ exports = module.exports = internals.Route = function (options, server, env) {
Utils.assert(typeof pre.method === 'function' || typeof pre.method === 'string', 'Prerequisite method must be a function or helper name');

pre.mode = pre.mode || 'serial';
Utils.assert(pre.mode === 'serial' || pre.mode === 'parallel', 'Unknown prerequisite mode: ' + pre.mode);
Utils.assert(pre.mode === 'serial' || pre.mode === 'parallel', 'Unknown prerequisite mode:', pre.mode);

if (typeof pre.method === 'string') {
var preMethodParts = pre.method.match(/^(\w+)(?:\s*)\((\s*\w+(?:\.\w+)*\s*(?:\,\s*\w+(?:\.\w+)*\s*)*)?\)$/);
Expand Down
10 changes: 5 additions & 5 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ module.exports = internals.Server = function (/* host, port, options */) {

var type = typeof arguments[a];
var key = argMap[type];
Utils.assert(key, 'Bad server constructor arguments: no match for arg type ' + type);
Utils.assert(!args[key], 'Bad server constructor arguments: duplicated arg type: ' + type);
Utils.assert(key, 'Bad server constructor arguments: no match for arg type:', type);
Utils.assert(!args[key], 'Bad server constructor arguments: duplicated arg type:', type);
args[key] = arguments[a];
}

this.settings = Utils.applyToDefaults(Defaults.server, args.options || {});
var schemaError = Schema.server(this.settings);
Utils.assert(!schemaError, 'Invalid server options: ' + schemaError);
Utils.assert(!schemaError, 'Invalid server options:', schemaError);

// Set basic configuration

Expand Down Expand Up @@ -317,7 +317,7 @@ internals.Server.prototype._route = function (configs, env) {
internals.Server.prototype.state = internals.Server.prototype.addState = function (name, options) {

Utils.assert(name && typeof name === 'string', 'Invalid name');
Utils.assert(!this._stateDefinitions[name], 'State already defined: ' + name);
Utils.assert(!this._stateDefinitions[name], 'State already defined:', name);
Utils.assert(!options || !options.encoding || ['base64json', 'base64', 'form', 'iron', 'none'].indexOf(options.encoding) !== -1, 'Bad encoding');

this._stateDefinitions[name] = Utils.applyToDefaults(Defaults.state, options || {});
Expand Down Expand Up @@ -364,7 +364,7 @@ internals.Server.prototype.helper = internals.Server.prototype.addHelper = funct

Utils.assert(typeof method === 'function', 'method must be a function');
Utils.assert(typeof name === 'string', 'name must be a string');
Utils.assert(name.match(/^\w+$/), 'Invalid name: ' + name);
Utils.assert(name.match(/^\w+$/), 'Invalid name:', name);
Utils.assert(!this.helpers[name], 'Helper function name already exists');
Utils.assert(!options || typeof options === 'object', 'options must be an object');
Utils.assert(!options || !options.generateKey || typeof options.generateKey === 'function', 'options.key must be a function');
Expand Down
2 changes: 1 addition & 1 deletion lib/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports = module.exports = internals.Manager = function (options) {

config = Utils.applyToDefaults(defaults, config);
var schemaError = Schema.view(config);
Utils.assert(!schemaError, 'Invalid server options: ' + schemaError);
Utils.assert(!schemaError, 'Invalid server options:', schemaError);

var engine = {
module: (typeof config.module === 'string' ? require(config.module) : config.module),
Expand Down
6 changes: 3 additions & 3 deletions test/integration/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ describe('Pack', function () {
expect(function () {

server.pack.allow({ ext: true }).require('./pack/--deps1', [{ ext: true }], function (err) { });
}).to.throw('Plugin \'--deps1\' missing dependencies: --deps2');
}).to.throw('Plugin --deps1 missing dependencies: --deps2');
done();
});

Expand All @@ -450,7 +450,7 @@ describe('Pack', function () {
expect(function () {

server.pack.allow({ ext: true }).register(plugin, function (err) { });
}).to.throw('Plugin \'test\' missing dependencies: none');
}).to.throw('Plugin test missing dependencies: none');
done();
});

Expand All @@ -461,7 +461,7 @@ describe('Pack', function () {
var domain = Domain.create();
domain.on('error', function (err) {

expect(err.message).to.equal('Plugin \'--deps1\' missing dependencies: --deps2');
expect(err.message).to.equal('Plugin --deps1 missing dependencies: --deps2');
done();
});

Expand Down
4 changes: 1 addition & 3 deletions test/integration/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var Http = require('http');
var Path = require('path');
var Stream = require('stream');
var Zlib = require('zlib');
var Assert = require('assert');
var Hapi = require('../..');


Expand Down Expand Up @@ -570,8 +569,7 @@ describe('Payload', function () {
expect(request.payload['my_file'].size).to.equal(stats.size);

var tmpContents = Fs.readFileSync(request.payload['my_file'].path, { encoding: 'binary' });
Assert.deepEqual(fileContents, tmpContents);

expect(fileContents).to.deep.equal(tmpContents);
done();
};

Expand Down

0 comments on commit 939f3c3

Please sign in to comment.