Commit 90f69f8f authored by Ray Bellis's avatar Ray Bellis

add more parameter checking

parent 1a1774bf
......@@ -153,7 +153,17 @@ class RadiusServer {
*/
constructor({ auth = 1812, acct = 1813 } = {}) {
// @FIXME type checking
// type checking
if (!Number.isInteger(auth) || !Number.isInteger(acct)) {
throw new TypeError('RadiusPacket ports must be integer values');
}
// range checking
if (auth < 1 || acct < 1 || auth > 65535 || acct > 65535) {
throw new RangeError('RadiusPacket ports must be between 1 and 65535');
}
// internal state for passing around
const state = {
clients: new Map(),
handlers: [],
......@@ -168,16 +178,42 @@ class RadiusServer {
* @return {RadiusServer} - the current server object
*/
this.addClient = function(client, secret) {
// @FIXME type checking
// type checking
if (typeof client !== 'string') {
throw new TypeError('client parameter must be a string');
}
if (typeof secret !== 'string') {
throw new TypeError('secret parameter must be a string');
}
state.clients.set(client, secret);
return this;
}
/**
* @param {Handler} handler - a function to be added to the request processing chain
* @param {Object} handler - an object containing functions to be added to the request processing chain
* @param {Handler} [handler.auth] - the authentication handler
* @param {Handler} [handler.acct] - the accounting handler
* @return {RadiusServer} - the current server object
*/
this.use = function(handler) {
// type checking
if (typeof handler !== 'function' && typeof handler !== 'object') {
return new TypeError('handler must be a function or object');
}
if (('auth' in handler) && typeof handler.auth !== 'function') {
return new TypeError('handler.auth must be a function or undefined');
}
if (('acct' in handler) && typeof handler.acct !== 'function') {
return new TypeError('handler.acct must be a function or undefined');
}
// remember the list
state.handlers.push(handler);
return this;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment