Commit 208dc94b authored by Ray Bellis's avatar Ray Bellis

add Packet#has method

parent 3608e8cd
......@@ -159,6 +159,22 @@ class RadiusPacket {
return this;
}
/**
* Check whether an attribute with the given ID exists.
*
* @param {(number|string)} id - the attribute ID or name
* @return {boolean}
*/
has(id) {
const dict = Dictionary.get(id);
for (let attr of this.attributes) {
if (attr.dict === dict) {
return true;
}
}
return false;
}
/**
* Get an attribute's value out of the packet. If multiple attributes
* with the same ID exist, only the first is returned.
......
......@@ -15,10 +15,10 @@ const logic = {
const defaults = {
auth: function(req, res) {
if (res.code.toString() === 'Access-Accept') {
if (res.get('Framed-IP-Address') === undefined) {
if (!res.has('Framed-IP-Address')) {
res.add('Framed-IP-Address', '255.255.255.254');
}
if (res.get('Framed-IP-Netmask') === undefined) {
if (!res.has('Framed-IP-Netmask')) {
res.add('Framed-IP-Netmask', [255, 255, 255, 255]);
}
}
......
......@@ -50,6 +50,9 @@ describe('Packet', () => {
describe('#add', () => {
});
describe('#has', () => {
});
describe('#get', () => {
});
......
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