net-snmp 3.15.2 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +1 -1
- package/README.md +8 -0
- package/example/option-parser.js +3 -0
- package/index.js +143 -74
- package/package.json +5 -3
- package/test/objects.js +238 -0
package/.vscode/launch.json
CHANGED
package/README.md
CHANGED
@@ -3424,6 +3424,14 @@ Example programs are included under the module's `example` directory.
|
|
3424
3424
|
|
3425
3425
|
* Change return of non-existing OIDs under table from NoSuchObject to NoSuchInstance
|
3426
3426
|
|
3427
|
+
## Version 3.15.3 - 04/12/2024
|
3428
|
+
|
3429
|
+
* Fix agent SNMP SetRequest for OIDs
|
3430
|
+
|
3431
|
+
## Version 3.16.0 - 23/12/2024
|
3432
|
+
|
3433
|
+
* Add MIB object validation to set/add MIB API calls
|
3434
|
+
|
3427
3435
|
# License
|
3428
3436
|
|
3429
3437
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/example/option-parser.js
CHANGED
@@ -61,6 +61,9 @@ if ( command.includes('snmp-set') ) {
|
|
61
61
|
type: snmp.ObjectType[options._[2]],
|
62
62
|
value: options._[3]
|
63
63
|
}];
|
64
|
+
if ( varbinds[0].type == snmp.ObjectType.Integer ) {
|
65
|
+
varbinds[0].value = Number(varbinds[0].value);
|
66
|
+
}
|
64
67
|
} else if ( command.includes('snmp-table-columns') ) {
|
65
68
|
oids = [options._[1]];
|
66
69
|
columns = [];
|
package/index.js
CHANGED
@@ -585,6 +585,106 @@ function writeVarbinds (buffer, varbinds) {
|
|
585
585
|
buffer.endSequence ();
|
586
586
|
}
|
587
587
|
|
588
|
+
const ObjectTypeUtil = {};
|
589
|
+
|
590
|
+
ObjectTypeUtil.castSetValue = function (type, value) {
|
591
|
+
|
592
|
+
switch (type) {
|
593
|
+
case ObjectType.Boolean:
|
594
|
+
return !! value;
|
595
|
+
|
596
|
+
case ObjectType.Integer:
|
597
|
+
if ( typeof value != "number" && typeof value != "string" ) {
|
598
|
+
throw new Error("Invalid Integer", value);
|
599
|
+
}
|
600
|
+
return typeof value == "number" ? value : parseInt(value, 10);
|
601
|
+
|
602
|
+
case ObjectType.OctetString:
|
603
|
+
if ( value instanceof Buffer) {
|
604
|
+
return value.toString();
|
605
|
+
} else if ( typeof value != "string" ) {
|
606
|
+
throw new Error("Invalid OctetString", value);
|
607
|
+
} else {
|
608
|
+
return value;
|
609
|
+
}
|
610
|
+
|
611
|
+
case ObjectType.OID:
|
612
|
+
if ( typeof value != "string" || ! value.match(/^([0-9]+)(\.[0-9]+)+$/) ) {
|
613
|
+
throw new Error("Invalid OID", value);
|
614
|
+
}
|
615
|
+
return value;
|
616
|
+
|
617
|
+
case ObjectType.Counter:
|
618
|
+
case ObjectType.Counter64:
|
619
|
+
// Counters should be initialized to 0 (RFC2578, end of section 7.9)
|
620
|
+
// We'll do so.
|
621
|
+
return 0;
|
622
|
+
|
623
|
+
case ObjectType.IpAddress:
|
624
|
+
// A 32-bit internet address represented as OCTET STRING of length 4
|
625
|
+
var bytes = value.split(".");
|
626
|
+
if ( typeof value != "string" || bytes.length != 4 ) {
|
627
|
+
throw new Error("Invalid IpAddress", value);
|
628
|
+
}
|
629
|
+
return value;
|
630
|
+
|
631
|
+
default :
|
632
|
+
// Assume the caller knows what he's doing
|
633
|
+
return value;
|
634
|
+
}
|
635
|
+
|
636
|
+
};
|
637
|
+
|
638
|
+
ObjectTypeUtil.isValid = function (type, value) {
|
639
|
+
|
640
|
+
switch (type) {
|
641
|
+
case ObjectType.Boolean: {
|
642
|
+
return typeof value == "boolean";
|
643
|
+
}
|
644
|
+
case ObjectType.Integer: {
|
645
|
+
// Allow strings that can be parsed as integers
|
646
|
+
const parsed = Number(value);
|
647
|
+
return ! isNaN (parsed) && Number.isInteger (parsed) && parsed >= MIN_SIGNED_INT32 && parsed <= MAX_SIGNED_INT32;
|
648
|
+
}
|
649
|
+
case ObjectType.OctetString: {
|
650
|
+
// Allow string or buffer
|
651
|
+
return typeof value == "string" || value instanceof Buffer;
|
652
|
+
}
|
653
|
+
case ObjectType.OID: {
|
654
|
+
return typeof value == "string" && value.match (/^([0-9]+)(\.[0-9]+)+$/);
|
655
|
+
}
|
656
|
+
case ObjectType.Counter: {
|
657
|
+
// Allow strings that can be parsed as integers
|
658
|
+
const parsed = Number(value);
|
659
|
+
return ! isNaN (parsed) && Number.isInteger (parsed) && parsed >= 0 && parsed <= MAX_UNSIGNED_INT32;
|
660
|
+
}
|
661
|
+
case ObjectType.Counter64: {
|
662
|
+
// Allow strings that can be parsed as integers
|
663
|
+
const parsed = Number(value);
|
664
|
+
return ! isNaN (parsed) && Number.isInteger (parsed) && parsed >= 0;
|
665
|
+
}
|
666
|
+
case ObjectType.IpAddress: {
|
667
|
+
const octets = value.split(".");
|
668
|
+
if ( octets.length !== 4 ) {
|
669
|
+
return false;
|
670
|
+
}
|
671
|
+
for ( const octet of octets ) {
|
672
|
+
if ( isNaN (octet) ) {
|
673
|
+
return false;
|
674
|
+
}
|
675
|
+
if ( parseInt (octet) < 0 || parseInt (octet) > 255) {
|
676
|
+
return false;
|
677
|
+
}
|
678
|
+
}
|
679
|
+
return true;
|
680
|
+
}
|
681
|
+
default: {
|
682
|
+
return false;
|
683
|
+
}
|
684
|
+
}
|
685
|
+
|
686
|
+
};
|
687
|
+
|
588
688
|
/*****************************************************************************
|
589
689
|
** PDU class definitions
|
590
690
|
**/
|
@@ -3966,14 +4066,8 @@ Mib.prototype.getProviderNodeForInstance = function (instanceNode) {
|
|
3966
4066
|
};
|
3967
4067
|
|
3968
4068
|
Mib.prototype.addProviderToNode = function (provider) {
|
3969
|
-
|
3970
|
-
|
4069
|
+
const node = this.addNodesForOid (provider.oid);
|
3971
4070
|
node.provider = provider;
|
3972
|
-
if ( provider.type == MibProviderType.Table ) {
|
3973
|
-
if ( ! provider.tableIndex ) {
|
3974
|
-
provider.tableIndex = [1];
|
3975
|
-
}
|
3976
|
-
}
|
3977
4071
|
this.providerNodes[provider.name] = node;
|
3978
4072
|
return node;
|
3979
4073
|
};
|
@@ -4183,8 +4277,11 @@ Mib.prototype.setScalarValue = function (scalarName, newValue) {
|
|
4183
4277
|
instanceNode = this.lookup (instanceAddress);
|
4184
4278
|
instanceNode.valueType = provider.scalarType;
|
4185
4279
|
}
|
4280
|
+
const isValidValue = ObjectTypeUtil.isValid(instanceNode.valueType, newValue);
|
4281
|
+
if ( ! isValidValue ) {
|
4282
|
+
throw new TypeError(`Invalid value for ${scalarName} of type ${instanceNode.valueType}: ${newValue}`);
|
4283
|
+
}
|
4186
4284
|
instanceNode.value = newValue;
|
4187
|
-
// return instanceNode.setValue (newValue);
|
4188
4285
|
};
|
4189
4286
|
|
4190
4287
|
Mib.prototype.getProviderNodeForTable = function (table) {
|
@@ -4312,6 +4409,23 @@ Mib.prototype.getTableRowInstanceFromRowIndex = function (provider, rowIndex) {
|
|
4312
4409
|
return rowIndexOid;
|
4313
4410
|
};
|
4314
4411
|
|
4412
|
+
Mib.prototype.validateTableRow = function (table, row) {
|
4413
|
+
const provider = this.providers[table];
|
4414
|
+
const tableIndex = provider.tableIndex;
|
4415
|
+
const foreignIndexOffset = tableIndex.filter ( indexPart => indexPart.foreign ).length;
|
4416
|
+
for ( let i = 0; i < provider.tableColumns.length ; i++ ) {
|
4417
|
+
const column = provider.tableColumns[i];
|
4418
|
+
const isColumnIndex = tableIndex.some ( indexPart => indexPart.columnNumber == column.number );
|
4419
|
+
if ( ! isColumnIndex || ! (column.maxAccess === MaxAccess['not-accessible'] || column.maxAccess === MaxAccess['accessible-for-notify']) ) {
|
4420
|
+
const rowValueIndex = foreignIndexOffset + i;
|
4421
|
+
const isValidValue = ObjectTypeUtil.isValid(column.type, row[rowValueIndex]);
|
4422
|
+
if ( ! isValidValue ) {
|
4423
|
+
throw new TypeError(`Invalid value for ${table} column ${column.name} (index ${rowValueIndex}): ${row[rowValueIndex]} (in row [${row}])`);
|
4424
|
+
}
|
4425
|
+
}
|
4426
|
+
}
|
4427
|
+
};
|
4428
|
+
|
4315
4429
|
Mib.prototype.addTableRow = function (table, row) {
|
4316
4430
|
var providerNode;
|
4317
4431
|
var provider;
|
@@ -4320,7 +4434,11 @@ Mib.prototype.addTableRow = function (table, row) {
|
|
4320
4434
|
var instanceNode;
|
4321
4435
|
var rowValueOffset;
|
4322
4436
|
|
4323
|
-
if (
|
4437
|
+
if ( ! this.providers[table] ) {
|
4438
|
+
throw new ReferenceError ("Provider " + table + " not registered with this MIB");
|
4439
|
+
}
|
4440
|
+
this.validateTableRow (table, row);
|
4441
|
+
if ( ! this.providerNodes[table] ) {
|
4324
4442
|
this.addProviderToNode (this.providers[table]);
|
4325
4443
|
}
|
4326
4444
|
providerNode = this.getProviderNodeForTable (table);
|
@@ -4450,19 +4568,16 @@ Mib.prototype.getTableSingleCell = function (table, columnNumber, rowIndex) {
|
|
4450
4568
|
};
|
4451
4569
|
|
4452
4570
|
Mib.prototype.setTableSingleCell = function (table, columnNumber, rowIndex, value) {
|
4453
|
-
|
4454
|
-
|
4455
|
-
|
4456
|
-
|
4457
|
-
|
4458
|
-
|
4459
|
-
|
4460
|
-
|
4461
|
-
|
4462
|
-
columnNode = providerNode.children[columnNumber];
|
4463
|
-
instanceNode = columnNode.getInstanceNodeForTableRowIndex (instanceAddress);
|
4571
|
+
const provider = this.providers[table];
|
4572
|
+
const providerNode = this.getProviderNodeForTable (table);
|
4573
|
+
const instanceAddress = this.getTableRowInstanceFromRowIndex (provider, rowIndex);
|
4574
|
+
const columnNode = providerNode.children[columnNumber];
|
4575
|
+
const instanceNode = columnNode.getInstanceNodeForTableRowIndex (instanceAddress);
|
4576
|
+
const isValidValue = ObjectTypeUtil.isValid(instanceNode.valueType, value);
|
4577
|
+
if ( ! isValidValue ) {
|
4578
|
+
throw new TypeError(`Invalid value for ${table} column ${columnNumber} of type ${instanceNode.valueType}: ${value}`);
|
4579
|
+
}
|
4464
4580
|
instanceNode.value = value;
|
4465
|
-
// return instanceNode.setValue (value);
|
4466
4581
|
};
|
4467
4582
|
|
4468
4583
|
Mib.prototype.deleteTableRow = function (table, rowIndex) {
|
@@ -4742,53 +4857,6 @@ Agent.prototype.onMsg = function (socket, buffer, rinfo) {
|
|
4742
4857
|
}
|
4743
4858
|
};
|
4744
4859
|
|
4745
|
-
Agent.prototype.castSetValue = function ( type, value ) {
|
4746
|
-
switch (type) {
|
4747
|
-
case ObjectType.Boolean:
|
4748
|
-
return !! value;
|
4749
|
-
|
4750
|
-
case ObjectType.Integer:
|
4751
|
-
if ( typeof value != "number" && typeof value != "string" ) {
|
4752
|
-
throw new Error("Invalid Integer", value);
|
4753
|
-
}
|
4754
|
-
return typeof value == "number" ? value : parseInt(value, 10);
|
4755
|
-
|
4756
|
-
case ObjectType.OctetString:
|
4757
|
-
if ( value instanceof Buffer) {
|
4758
|
-
return value.toString();
|
4759
|
-
} else if ( typeof value != "string" ) {
|
4760
|
-
throw new Error("Invalid OctetString", value);
|
4761
|
-
} else {
|
4762
|
-
return value;
|
4763
|
-
}
|
4764
|
-
|
4765
|
-
case ObjectType.OID:
|
4766
|
-
if ( typeof value != "string" || ! value.match(/[0-9]+\([.][0-9]+\)+/) ) {
|
4767
|
-
throw new Error("Invalid OID", value);
|
4768
|
-
}
|
4769
|
-
return value;
|
4770
|
-
|
4771
|
-
case ObjectType.Counter:
|
4772
|
-
case ObjectType.Counter64:
|
4773
|
-
// Counters should be initialized to 0 (RFC2578, end of section 7.9)
|
4774
|
-
// We'll do so.
|
4775
|
-
return 0;
|
4776
|
-
|
4777
|
-
case ObjectType.IpAddress:
|
4778
|
-
// A 32-bit internet address represented as OCTET STRING of length 4
|
4779
|
-
var bytes = value.split(".");
|
4780
|
-
if ( typeof value != "string" || bytes.length != 4 ) {
|
4781
|
-
throw new Error("Invalid IpAddress", value);
|
4782
|
-
}
|
4783
|
-
return value;
|
4784
|
-
|
4785
|
-
default :
|
4786
|
-
// Assume the caller knows what he's doing
|
4787
|
-
return value;
|
4788
|
-
}
|
4789
|
-
};
|
4790
|
-
|
4791
|
-
|
4792
4860
|
Agent.prototype.tryCreateInstance = function (varbind, requestType) {
|
4793
4861
|
var row;
|
4794
4862
|
var column;
|
@@ -4841,7 +4909,7 @@ Agent.prototype.tryCreateInstance = function (varbind, requestType) {
|
|
4841
4909
|
}
|
4842
4910
|
|
4843
4911
|
// Ensure the value is of the correct type, and save it
|
4844
|
-
value =
|
4912
|
+
value = ObjectTypeUtil.castSetValue ( provider.scalarType, value );
|
4845
4913
|
this.mib.setScalarValue ( provider.name, value );
|
4846
4914
|
|
4847
4915
|
// Now there should be an instanceNode available.
|
@@ -4901,7 +4969,7 @@ Agent.prototype.tryCreateInstance = function (varbind, requestType) {
|
|
4901
4969
|
}
|
4902
4970
|
|
4903
4971
|
// Map each column's value to the appropriate type
|
4904
|
-
value = value.map( (v, i) =>
|
4972
|
+
value = value.map( (v, i) => ObjectTypeUtil.castSetValue ( provider.tableColumns[i].type, v ) );
|
4905
4973
|
|
4906
4974
|
// Add the table row
|
4907
4975
|
this.mib.addTableRow ( provider.name, value );
|
@@ -5078,7 +5146,7 @@ Agent.prototype.request = function (socket, requestMessage, rinfo) {
|
|
5078
5146
|
});
|
5079
5147
|
};
|
5080
5148
|
|
5081
|
-
requestPdu.varbinds[i].requestValue =
|
5149
|
+
requestPdu.varbinds[i].requestValue = ObjectTypeUtil.castSetValue (requestPdu.varbinds[i].type, requestPdu.varbinds[i].value);
|
5082
5150
|
switch ( requestPdu.varbinds[i].value ) {
|
5083
5151
|
case RowStatus["active"]:
|
5084
5152
|
case RowStatus["notInService"]:
|
@@ -5218,7 +5286,7 @@ Agent.prototype.request = function (socket, requestMessage, rinfo) {
|
|
5218
5286
|
|
5219
5287
|
} else {
|
5220
5288
|
// No special handling required. Just save the new value.
|
5221
|
-
let setResult = mibRequests[savedIndex].instanceNode.setValue (
|
5289
|
+
let setResult = mibRequests[savedIndex].instanceNode.setValue (ObjectTypeUtil.castSetValue (
|
5222
5290
|
requestPdu.varbinds[savedIndex].type,
|
5223
5291
|
requestPdu.varbinds[savedIndex].value
|
5224
5292
|
));
|
@@ -5254,9 +5322,9 @@ Agent.prototype.request = function (socket, requestMessage, rinfo) {
|
|
5254
5322
|
}
|
5255
5323
|
responseVarbind.requestType = requestPdu.varbinds[savedIndex].type;
|
5256
5324
|
if ( requestPdu.varbinds[savedIndex].requestValue ) {
|
5257
|
-
responseVarbind.requestValue =
|
5325
|
+
responseVarbind.requestValue = ObjectTypeUtil.castSetValue (requestPdu.varbinds[savedIndex].type, requestPdu.varbinds[savedIndex].requestValue);
|
5258
5326
|
} else {
|
5259
|
-
responseVarbind.requestValue =
|
5327
|
+
responseVarbind.requestValue = ObjectTypeUtil.castSetValue (requestPdu.varbinds[savedIndex].type, requestPdu.varbinds[savedIndex].value);
|
5260
5328
|
}
|
5261
5329
|
}
|
5262
5330
|
if ( createResult[savedIndex] ) {
|
@@ -6425,5 +6493,6 @@ exports.ObjectParser = {
|
|
6425
6493
|
readUint32: readUint32,
|
6426
6494
|
readVarbindValue: readVarbindValue
|
6427
6495
|
};
|
6496
|
+
exports.ObjectTypeUtil = ObjectTypeUtil;
|
6428
6497
|
exports.Authentication = Authentication;
|
6429
6498
|
exports.Encryption = Encryption;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "net-snmp",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.16.0",
|
4
4
|
"description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
|
5
5
|
"main": "index.js",
|
6
6
|
"directories": {
|
@@ -12,7 +12,8 @@
|
|
12
12
|
},
|
13
13
|
"devDependencies": {
|
14
14
|
"eslint": "^9.9.1",
|
15
|
-
"getopts": "
|
15
|
+
"getopts": "^2.3.0",
|
16
|
+
"mocha": "^11.0.1"
|
16
17
|
},
|
17
18
|
"contributors": [
|
18
19
|
{
|
@@ -47,6 +48,7 @@
|
|
47
48
|
"author": "Mark Abrahams <mark@abrahams.co.nz>",
|
48
49
|
"license": "MIT",
|
49
50
|
"scripts": {
|
50
|
-
"lint": "
|
51
|
+
"lint": "eslint . ./**/*.js",
|
52
|
+
"test": "./node_modules/mocha/bin/mocha.js"
|
51
53
|
}
|
52
54
|
}
|
package/test/objects.js
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
const assert = require('assert');
|
2
|
+
const snmp = require('../');
|
3
|
+
|
4
|
+
describe('isValid() - Boolean', function() {
|
5
|
+
describe('JS true is a Boolean type', function() {
|
6
|
+
it('returns true', function() {
|
7
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Boolean, true), true);
|
8
|
+
});
|
9
|
+
});
|
10
|
+
describe('JS false is a Boolean type', function() {
|
11
|
+
it('returns true', function() {
|
12
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Boolean, false), true);
|
13
|
+
});
|
14
|
+
});
|
15
|
+
});
|
16
|
+
|
17
|
+
describe('isValid() - Integer', function() {
|
18
|
+
describe('Zero is an Integer type', function() {
|
19
|
+
it('returns true', function() {
|
20
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, 0), true);
|
21
|
+
});
|
22
|
+
});
|
23
|
+
describe('An positive integer number is an Integer type', function() {
|
24
|
+
it('returns true', function() {
|
25
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, 44), true);
|
26
|
+
});
|
27
|
+
});
|
28
|
+
describe('An positive integer string is an Integer type', function() {
|
29
|
+
it('returns true', function() {
|
30
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, "44"), true);
|
31
|
+
});
|
32
|
+
});
|
33
|
+
describe('An negative integer number is an Integer type', function() {
|
34
|
+
it('returns true', function() {
|
35
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, -24), true);
|
36
|
+
});
|
37
|
+
});
|
38
|
+
describe('A negative integer string is an Integer type', function() {
|
39
|
+
it('returns true', function() {
|
40
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, "-24"), true);
|
41
|
+
});
|
42
|
+
});
|
43
|
+
describe('A non-integer decimal number is not an Integer type', function() {
|
44
|
+
it('returns false', function() {
|
45
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, 45.2), false);
|
46
|
+
});
|
47
|
+
});
|
48
|
+
describe('A non-integer decimal string is not an Integer type', function() {
|
49
|
+
it('returns false', function() {
|
50
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, "45.2"), false);
|
51
|
+
});
|
52
|
+
});
|
53
|
+
describe('An integer at the bottom of the valid range is an Integer type', function() {
|
54
|
+
it('returns true', function() {
|
55
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, -2147483648), true);
|
56
|
+
});
|
57
|
+
});
|
58
|
+
describe('An integer just lower than the valid range is not an Integer type', function() {
|
59
|
+
it('returns false', function() {
|
60
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, -2147483649), false);
|
61
|
+
});
|
62
|
+
});
|
63
|
+
describe('An integer at the top of the valid range is an Integer type', function() {
|
64
|
+
it('returns true', function() {
|
65
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, 2147483647), true);
|
66
|
+
});
|
67
|
+
});
|
68
|
+
describe('An integer just higher than the valid range is not an Integer type', function() {
|
69
|
+
it('returns false', function() {
|
70
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Integer, 2147483648), false);
|
71
|
+
});
|
72
|
+
});
|
73
|
+
});
|
74
|
+
|
75
|
+
describe('isValid() - OctetString', function() {
|
76
|
+
describe('A string is an OctetString type', function() {
|
77
|
+
it('returns true', function() {
|
78
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, 'Better late than never'), true);
|
79
|
+
});
|
80
|
+
});
|
81
|
+
describe('A buffer is an OctetString type', function() {
|
82
|
+
it('returns true', function() {
|
83
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, Buffer.from('1.3.6.1.2.3.4.5')), true);
|
84
|
+
});
|
85
|
+
});
|
86
|
+
});
|
87
|
+
|
88
|
+
describe('isValid() - OID', function() {
|
89
|
+
describe('A string OID is an OID type', function() {
|
90
|
+
it('returns true', function() {
|
91
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, '1.3.6.1.2.33.4.5'), true);
|
92
|
+
});
|
93
|
+
});
|
94
|
+
describe('A string non-OID is not an OID type', function() {
|
95
|
+
it('returns true', function() {
|
96
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, 'dog'), true);
|
97
|
+
});
|
98
|
+
});
|
99
|
+
describe('An OID string with a double-dot is not an OID type', function() {
|
100
|
+
it('returns true', function() {
|
101
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, '1.3.6.1..2.33.4.5'), true);
|
102
|
+
});
|
103
|
+
});
|
104
|
+
describe('An OID string with a leading dot is not an OID type', function() {
|
105
|
+
it('returns true', function() {
|
106
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, '.1.3.6.1..2.33.4.5'), true);
|
107
|
+
});
|
108
|
+
});
|
109
|
+
describe('An OID string with a trailing dot is not an OID type', function() {
|
110
|
+
it('returns true', function() {
|
111
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, '1.3.6.1.2.33.4.5.'), true);
|
112
|
+
});
|
113
|
+
});
|
114
|
+
});
|
115
|
+
|
116
|
+
describe('isValid() - Counter', function() {
|
117
|
+
describe('Zero is a Counter type', function() {
|
118
|
+
it('returns true', function() {
|
119
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, 0), true);
|
120
|
+
});
|
121
|
+
});
|
122
|
+
describe('An positive integer number is a Counter type', function() {
|
123
|
+
it('returns true', function() {
|
124
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, 44), true);
|
125
|
+
});
|
126
|
+
});
|
127
|
+
describe('An positive integer string is a Counter type', function() {
|
128
|
+
it('returns true', function() {
|
129
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, "44"), true);
|
130
|
+
});
|
131
|
+
});
|
132
|
+
describe('An negative integer number is not a Counter type', function() {
|
133
|
+
it('returns false', function() {
|
134
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, -24), false);
|
135
|
+
});
|
136
|
+
});
|
137
|
+
describe('A negative integer string is not a Counter type', function() {
|
138
|
+
it('returns false', function() {
|
139
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, "-24"), false);
|
140
|
+
});
|
141
|
+
});
|
142
|
+
describe('A non-integer decimal number is not a Counter type', function() {
|
143
|
+
it('returns false', function() {
|
144
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, 45.2), false);
|
145
|
+
});
|
146
|
+
});
|
147
|
+
describe('A non-integer decimal string is not a Counter type', function() {
|
148
|
+
it('returns false', function() {
|
149
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, "45.2"), false);
|
150
|
+
});
|
151
|
+
});
|
152
|
+
describe('An integer at the bottom of the valid range is a Counter type', function() {
|
153
|
+
it('returns true', function() {
|
154
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, 0), true);
|
155
|
+
});
|
156
|
+
});
|
157
|
+
describe('An integer just lower than the valid range is not a Counter type', function() {
|
158
|
+
it('returns false', function() {
|
159
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, -1), false);
|
160
|
+
});
|
161
|
+
});
|
162
|
+
describe('An integer at the top of the valid range is a Counter type', function() {
|
163
|
+
it('returns true', function() {
|
164
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, 4294967295), true);
|
165
|
+
});
|
166
|
+
});
|
167
|
+
describe('An integer just higher than the valid range is not a Counter type', function() {
|
168
|
+
it('returns false', function() {
|
169
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter, 4294967296), false);
|
170
|
+
});
|
171
|
+
});
|
172
|
+
});
|
173
|
+
|
174
|
+
describe('isValid() - Counter64', function() {
|
175
|
+
describe('Zero is a Counter64 type', function() {
|
176
|
+
it('returns true', function() {
|
177
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, 0), true);
|
178
|
+
});
|
179
|
+
});
|
180
|
+
describe('An positive integer number is a Counter64 type', function() {
|
181
|
+
it('returns true', function() {
|
182
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, 44), true);
|
183
|
+
});
|
184
|
+
});
|
185
|
+
describe('An positive integer string is a Counter64 type', function() {
|
186
|
+
it('returns true', function() {
|
187
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, "44"), true);
|
188
|
+
});
|
189
|
+
});
|
190
|
+
describe('An negative integer number is not a Counter64 type', function() {
|
191
|
+
it('returns false', function() {
|
192
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, -24), false);
|
193
|
+
});
|
194
|
+
});
|
195
|
+
describe('A negative integer string is not a Counter64 type', function() {
|
196
|
+
it('returns false', function() {
|
197
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, "-24"), false);
|
198
|
+
});
|
199
|
+
});
|
200
|
+
describe('A non-integer decimal number is not a Counter64 type', function() {
|
201
|
+
it('returns false', function() {
|
202
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, 45.2), false);
|
203
|
+
});
|
204
|
+
});
|
205
|
+
describe('A non-integer decimal string is not a Counter64 type', function() {
|
206
|
+
it('returns false', function() {
|
207
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, "45.2"), false);
|
208
|
+
});
|
209
|
+
});
|
210
|
+
describe('An integer at the bottom of the valid range is a Counter64 type', function() {
|
211
|
+
it('returns true', function() {
|
212
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, 0), true);
|
213
|
+
});
|
214
|
+
});
|
215
|
+
describe('An integer just lower than the valid range is not a Counter64 type', function() {
|
216
|
+
it('returns false', function() {
|
217
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.Counter64, -1), false);
|
218
|
+
});
|
219
|
+
});
|
220
|
+
});
|
221
|
+
|
222
|
+
describe('isValid() - IPAddress', function() {
|
223
|
+
describe('Dotted quad of numbers is an IpAddress type', function() {
|
224
|
+
it('returns true', function() {
|
225
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.IpAddress, '10.3.147.4'), true);
|
226
|
+
});
|
227
|
+
});
|
228
|
+
describe('Dotted quin of numbers is not an IpAddress type', function() {
|
229
|
+
it('returns false', function() {
|
230
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.IpAddress, '10.3.147.22.4'), false);
|
231
|
+
});
|
232
|
+
});
|
233
|
+
describe('Dotted quad containing non-numbers is not an IpAddress type', function() {
|
234
|
+
it('returns false', function() {
|
235
|
+
assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.IpAddress, '10.word.147.4'), false);
|
236
|
+
});
|
237
|
+
});
|
238
|
+
});
|