Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
expect (a, b) {
//header
if (arguments.length === 2) {
let name = a;
let value = b;
this._asserts.headers[name] = value;
return this;
}
// status code
if (arguments.length === 1 && is.number(a)) {
this._asserts.statusCode = a;
return this;
}
// function
if (arguments.length === 1 && is.function(a)) {
this._assertFn = a;
return this;
}
// plain body
if (arguments.length === 1 && is.string(a)) {
this._asserts.body = a;
}
if (!valid) {
addError('torProxy', app.polyglot.t('serverConfigModelErrors.invalidTorProxy'));
}
}
if (!attrs.torPassword && this.isTorPwRequired()) {
addError('torPassword', app.polyglot.t('serverConfigModelErrors.provideValue'));
}
}
if (!attrs.builtIn) {
if (attrs.port === undefined || attrs.port === '') {
addError('port', app.polyglot.t('serverConfigModelErrors.provideValue'));
} else if (!is.number(attrs.port)) {
addError('port', app.polyglot.t('serverConfigModelErrors.providePortAsNumber'));
} else if (!is.within(attrs.port, -1, 65536)) {
addError('port', app.polyglot.t('serverConfigModelErrors.provideValidPortRange'));
}
} else {
if (is.existy(attrs.port) && attrs.port !== this.defaults().port) {
// For now, not allowing the port to be changed on built in servers,
// since there is currently no way to set the port as an option
// on the command line, the local bundled server will always be started
// with the default port.
addError('port', `On a built-in server, the port can only be ${this.defaults().port}.`);
}
}
if (Object.keys(errObj).length) return errObj;
Interceptor.prototype.set = function set(a, b) {
// header
if (arguments.length === 2) {
var _name = a;
var value = b;
this._headers[_name] = value;
return this;
}
// status code
if (arguments.length === 1 && is.number(a)) {
this._statusCode = a;
return this;
}
// function
if (arguments.length === 1 && is['function'](a)) {
this._respondFn = a;
return this;
}
// plain body
if (arguments.length === 1 && is.string(a)) {
this._body = a;
Object.keys(args).forEach(function forEachArgsKey(key) {
// Get the value of the key
var value = args[key];
// Validity check to push only string, number and boolean values command line arguments
var validValue = is.string(value) || is.number(value) || is.boolean(value);
// Validity check
if (validValue && is.truthy(value)) {
// Check for custom handling keys
if (is.not.inArray(key, keysIgnored)) {
// Push the key
argsToSpawn.push(key);
// Push value for string and number values
if (is.string(value)) argsToSpawn.push(value);
else if (is.number(value)) argsToSpawn.push(value.toString());
}
// Check if should handle loop
else if (is.equal(key, '--loop')) {
self._configurations.loop = true;
}
}
});
send(path, payload, cb) {
if (is.not.function(cb)) cb = function() {};
if (is.not.string(path) || is.empty(path))
return cb(new Error('INVALID_PATH'));
const delimiter = this.options.delimiter;
const timeout = this.options.timeout, useTimeout = is.number(timeout) && timeout > 0;
const service = path.split(is.string(delimiter) && is.not.empty(delimiter) ? delimiter : '.');
if (service.length < 2) return cb(new Error('MISSING_METHOD'));
else if (!service[1].trim().length || service[1].charAt(0) === '_')
return cb(new Error('INVALID_METHOD'));
const socket = this._getSocket(service[0]);
if (socket) {
let t_o = null;
try {
if (useTimeout)
t_o = setTimeout(() => {
t_o = undefined;
cb(new Error('REQUEST_TIMEOUT'));
}, timeout);
socket.send(path, payload, response => {
if (is.not.undefined(t_o)) {
async start() {
this._options.port = await portFinder.getPortPromise({
port: is.number(this._options.port) ? Math.abs(this._options.port) : undefined
});
this._http.listen(this._options.port, this._options.host);
}
this._addError(err, 'server_ip', 'Please provide a value.');
} else {
if (!is.ip(attrs.server_ip)) {
this._addError(err, 'server_ip', 'This does not appear to be a valid IP address.');
}
}
if (!is.number(attrs.rest_api_port)) {
this._addError(err, 'rest_api_port', 'Please provide a number.');
} else {
if (!is.within(attrs.rest_api_port, -1, 65536)) {
this._addError(err, 'rest_api_port', 'Please provide a number between 0 and 65535.');
}
}
if (!is.number(attrs.api_socket_port)) {
this._addError(err, 'api_socket_port', 'Please provide a number.');
} else {
if (!is.within(attrs.api_socket_port, -1, 65536)) {
this._addError(err, 'api_socket_port', 'Please provide a number between 0 and 65535.');
}
}
if (!is.number(attrs.heartbeat_socket_port)) {
this._addError(err, 'heartbeat_socket_port', 'Please provide a number.');
} else {
if (!is.within(attrs.heartbeat_socket_port, -1, 65536)) {
this._addError(err, 'heartbeat_socket_port', 'Please provide a number between 0 and 65535.');
}
}
if (!this.isLocalServer()) {
models = this.__collection.where({ name: attrs.name });
if (models && models.length && (models.length > 1 || models[0].id !== attrs.id)) {
this._addError(err, 'name', 'Configuration name is already in use.');
}
}
}
if (!is.existy(attrs.server_ip) || is.empty(attrs.server_ip)) {
this._addError(err, 'server_ip', 'Please provide a value.');
} else {
if (!is.ip(attrs.server_ip)) {
this._addError(err, 'server_ip', 'This does not appear to be a valid IP address.');
}
}
if (!is.number(attrs.rest_api_port)) {
this._addError(err, 'rest_api_port', 'Please provide a number.');
} else {
if (!is.within(attrs.rest_api_port, -1, 65536)) {
this._addError(err, 'rest_api_port', 'Please provide a number between 0 and 65535.');
}
}
if (!is.number(attrs.api_socket_port)) {
this._addError(err, 'api_socket_port', 'Please provide a number.');
} else {
if (!is.within(attrs.api_socket_port, -1, 65536)) {
this._addError(err, 'api_socket_port', 'Please provide a number between 0 and 65535.');
}
}
if (!is.number(attrs.heartbeat_socket_port)) {
this._addError(err, 'rest_api_port', 'Please provide a number.');
} else {
if (!is.within(attrs.rest_api_port, -1, 65536)) {
this._addError(err, 'rest_api_port', 'Please provide a number between 0 and 65535.');
}
}
if (!is.number(attrs.api_socket_port)) {
this._addError(err, 'api_socket_port', 'Please provide a number.');
} else {
if (!is.within(attrs.api_socket_port, -1, 65536)) {
this._addError(err, 'api_socket_port', 'Please provide a number between 0 and 65535.');
}
}
if (!is.number(attrs.heartbeat_socket_port)) {
this._addError(err, 'heartbeat_socket_port', 'Please provide a number.');
} else {
if (!is.within(attrs.heartbeat_socket_port, -1, 65536)) {
this._addError(err, 'heartbeat_socket_port', 'Please provide a number between 0 and 65535.');
}
}
if (!this.isLocalServer()) {
if (!is.existy(attrs.username) || is.empty(attrs.username)) {
this._addError(err, 'username', 'Please provide a value.');
}
if (!is.existy(attrs.password) || is.empty(attrs.password)) {
this._addError(err, 'password', 'Please provide a value.');
}
}
start(cbErr) {
if (this._flag.s) cbErr(new Error('already started'));
this._flag.s = true;
portfinder.getPortPromise({
port: is.number(this.options.port) && this.options.port > 0 ? this.options.port : undefined
}).then(port => {
this.options.port = port;
this._socket.bind(this.options.port);
}).catch(error => {
if (is.function(cbErr)) cbErr(error);
});
}