net-snmp 3.26.3 → 3.28.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/test/TEST-MIB.mib DELETED
@@ -1,210 +0,0 @@
1
- TEST-MIB DEFINITIONS ::= BEGIN
2
-
3
- IMPORTS
4
- MODULE-IDENTITY, OBJECT-TYPE, Integer32, IpAddress, TimeTicks
5
- FROM SNMPv2-SMI
6
- DisplayString, TEXTUAL-CONVENTION
7
- FROM SNMPv2-TC;
8
-
9
- testMIB MODULE-IDENTITY
10
- LAST-UPDATED "202501060000Z"
11
- ORGANIZATION "Example Organization"
12
- CONTACT-INFO "support@example.org"
13
- DESCRIPTION "A test MIB for node-net-snmp library"
14
- REVISION "202501060000Z"
15
- DESCRIPTION "Initial version of the test MIB"
16
- ::= { enterprises 99999 }
17
-
18
- -- Scalars
19
- testScalarInteger OBJECT-TYPE
20
- SYNTAX Integer32
21
- MAX-ACCESS read-write
22
- STATUS current
23
- DESCRIPTION "An integer scalar"
24
- ::= { testMIB 1 }
25
-
26
- testScalarEnum OBJECT-TYPE
27
- SYNTAX INTEGER { up(1), down(2), unknown(3) }
28
- MAX-ACCESS read-write
29
- STATUS current
30
- DESCRIPTION "An integer scalar with enumerated type"
31
- ::= { testMIB 2 }
32
-
33
- testScalarRange OBJECT-TYPE
34
- SYNTAX Integer32 (1..100)
35
- MAX-ACCESS read-write
36
- STATUS current
37
- DESCRIPTION "An integer scalar with a range constraint"
38
- ::= { testMIB 3 }
39
-
40
- testScalarString OBJECT-TYPE
41
- SYNTAX DisplayString
42
- MAX-ACCESS read-write
43
- STATUS current
44
- DESCRIPTION "A string scalar"
45
- ::= { testMIB 4 }
46
-
47
- testScalarStringSize OBJECT-TYPE
48
- SYNTAX OCTET STRING (SIZE(1..32))
49
- MAX-ACCESS read-write
50
- STATUS current
51
- DESCRIPTION "A string scalar with a size constraint"
52
- ::= { testMIB 5 }
53
-
54
- testScalarIntegerDefval OBJECT-TYPE
55
- SYNTAX Integer32
56
- MAX-ACCESS read-write
57
- STATUS current
58
- DESCRIPTION "An integer scalar"
59
- DEFVAL { 49 }
60
- ::= { testMIB 6 }
61
-
62
-
63
- -- Tables
64
- testTable1 OBJECT-TYPE
65
- SYNTAX SEQUENCE OF TestEntry1
66
- MAX-ACCESS not-accessible
67
- STATUS current
68
- DESCRIPTION "A table with a single integer index"
69
- ::= { testMIB 10 }
70
-
71
- testEntry1 OBJECT-TYPE
72
- SYNTAX TestEntry1
73
- MAX-ACCESS not-accessible
74
- STATUS current
75
- DESCRIPTION "An entry in testTable1"
76
- INDEX { testTable1Index }
77
- ::= { testTable1 1 }
78
-
79
- TestEntry1 ::= SEQUENCE {
80
- testTable1Index Integer32,
81
- testTable1Value DisplayString
82
- }
83
-
84
- testTable1Index OBJECT-TYPE
85
- SYNTAX Integer32
86
- MAX-ACCESS not-accessible
87
- STATUS current
88
- DESCRIPTION "Index for testTable1"
89
- ::= { testEntry1 1 }
90
-
91
- testTable1Value OBJECT-TYPE
92
- SYNTAX DisplayString
93
- MAX-ACCESS read-write
94
- STATUS current
95
- DESCRIPTION "Value in testTable1"
96
- ::= { testEntry1 2 }
97
-
98
- testTable2 OBJECT-TYPE
99
- SYNTAX SEQUENCE OF TestEntry2
100
- MAX-ACCESS not-accessible
101
- STATUS current
102
- DESCRIPTION "A table with a string index"
103
- ::= { testMIB 11 }
104
-
105
- testEntry2 OBJECT-TYPE
106
- SYNTAX TestEntry2
107
- MAX-ACCESS not-accessible
108
- STATUS current
109
- DESCRIPTION "An entry in testTable2"
110
- INDEX { testTable2Index }
111
- ::= { testTable2 1 }
112
-
113
- TestEntry2 ::= SEQUENCE {
114
- testTable2Index DisplayString,
115
- testTable2Value Integer32
116
- }
117
-
118
- testTable2Index OBJECT-TYPE
119
- SYNTAX DisplayString
120
- MAX-ACCESS not-accessible
121
- STATUS current
122
- DESCRIPTION "String index for testTable2"
123
- ::= { testEntry2 1 }
124
-
125
- testTable2Value OBJECT-TYPE
126
- SYNTAX Integer32
127
- MAX-ACCESS read-write
128
- STATUS current
129
- DESCRIPTION "Value in testTable2"
130
- ::= { testEntry2 2 }
131
-
132
- testTableForeignKey OBJECT-TYPE
133
- SYNTAX SEQUENCE OF TestEntryForeignKey
134
- MAX-ACCESS not-accessible
135
- STATUS current
136
- DESCRIPTION "A table with a foreign key"
137
- ::= { testMIB 12 }
138
-
139
- testEntryForeignKey OBJECT-TYPE
140
- SYNTAX TestEntryForeignKey
141
- MAX-ACCESS not-accessible
142
- STATUS current
143
- DESCRIPTION "An entry with a foreign key"
144
- INDEX { testTable1Index }
145
- ::= { testTableForeignKey 1 }
146
-
147
- TestEntryForeignKey ::= SEQUENCE {
148
- testForeignKeyValue DisplayString
149
- }
150
-
151
- testForeignKeyValue OBJECT-TYPE
152
- SYNTAX DisplayString
153
- MAX-ACCESS read-write
154
- STATUS current
155
- DESCRIPTION "Foreign key value"
156
- ::= { testEntryForeignKey 2 }
157
-
158
- testTableComposite OBJECT-TYPE
159
- SYNTAX SEQUENCE OF TestEntryComposite
160
- MAX-ACCESS not-accessible
161
- STATUS current
162
- DESCRIPTION "A table with a composite key"
163
- ::= { testMIB 13 }
164
-
165
- testEntryComposite OBJECT-TYPE
166
- SYNTAX TestEntryComposite
167
- MAX-ACCESS not-accessible
168
- STATUS current
169
- DESCRIPTION "An entry in the composite key table"
170
- INDEX { testTable1Index, testTable2Index }
171
- ::= { testTableComposite 1 }
172
-
173
- TestEntryComposite ::= SEQUENCE {
174
- testCompositeValue Integer32
175
- }
176
-
177
- testCompositeValue OBJECT-TYPE
178
- SYNTAX Integer32
179
- MAX-ACCESS read-write
180
- STATUS current
181
- DESCRIPTION "Composite key value"
182
- ::= { testEntryComposite 2 }
183
-
184
- testTableAugment OBJECT-TYPE
185
- SYNTAX SEQUENCE OF TestEntryAugment
186
- MAX-ACCESS not-accessible
187
- STATUS current
188
- DESCRIPTION "A table that augments testTable1"
189
- ::= { testMIB 14 }
190
-
191
- testEntryAugment OBJECT-TYPE
192
- SYNTAX TestEntryAugment
193
- MAX-ACCESS not-accessible
194
- STATUS current
195
- DESCRIPTION "An augmented entry"
196
- AUGMENTS { testEntry1 }
197
- ::= { testTableAugment 1 }
198
-
199
- TestEntryAugment ::= SEQUENCE {
200
- testAugmentValue TimeTicks
201
- }
202
-
203
- testAugmentValue OBJECT-TYPE
204
- SYNTAX TimeTicks
205
- MAX-ACCESS read-write
206
- STATUS current
207
- DESCRIPTION "Augmented value"
208
- ::= { testEntryAugment 2 }
209
-
210
- END
@@ -1,200 +0,0 @@
1
- const assert = require('assert');
2
- const snmp = require('..');
3
-
4
- describe('Cast Set Value', function() {
5
-
6
- describe('Boolean', function() {
7
- it('casts truthy values to true', function() {
8
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Boolean, 1), true);
9
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Boolean, "true"), true);
10
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Boolean, {}), true);
11
- });
12
-
13
- it('casts falsy values to false', function() {
14
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Boolean, 0), false);
15
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Boolean, ""), false);
16
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Boolean, null), false);
17
- });
18
- });
19
-
20
- describe('Integer', function() {
21
- it('accepts valid integers', function() {
22
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, 42), 42);
23
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, -42), -42);
24
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, "42"), 42);
25
- });
26
-
27
- it('throws on invalid integers', function() {
28
- assert.throws(() => {
29
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, "not a number");
30
- }, /Invalid Integer/);
31
-
32
- assert.throws(() => {
33
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, {});
34
- }, /Invalid Integer/);
35
- });
36
-
37
- it('respects enumeration constraints', function() {
38
- const constraints = {
39
- enumeration: {
40
- 1: 'one',
41
- 2: 'two'
42
- }
43
- };
44
-
45
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, 1, constraints), 1);
46
-
47
- assert.throws(() => {
48
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, 3, constraints);
49
- }, /Integer does not meet constraints/);
50
- });
51
-
52
- it('respects range constraints', function() {
53
- const constraints = {
54
- ranges: [
55
- { min: 0, max: 10 }
56
- ]
57
- };
58
-
59
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, 5, constraints), 5);
60
-
61
- assert.throws(() => {
62
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Integer, 11, constraints);
63
- }, /Integer does not meet constraints/);
64
- });
65
- });
66
-
67
- describe('OctetString', function() {
68
- it('accepts strings', function() {
69
- assert.strictEqual(
70
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.OctetString, "test string"),
71
- "test string"
72
- );
73
- });
74
-
75
- it('converts buffers to strings', function() {
76
- const buf = Buffer.from("test buffer");
77
- assert.strictEqual(
78
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.OctetString, buf),
79
- buf.toString()
80
- );
81
- });
82
-
83
- it('throws on invalid types', function() {
84
- assert.throws(() => {
85
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.OctetString, 123);
86
- }, /Invalid OctetString/);
87
- });
88
-
89
- it('respects size constraints', function() {
90
- const constraints = {
91
- sizes: [
92
- { min: 2, max: 5 }
93
- ]
94
- };
95
-
96
- assert.strictEqual(
97
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.OctetString, "123", constraints),
98
- "123"
99
- );
100
-
101
- assert.throws(() => {
102
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.OctetString, "too long", constraints);
103
- }, /OctetString does not meet constraints/);
104
- });
105
- });
106
-
107
- describe('OID', function() {
108
- it('accepts valid OIDs', function() {
109
- assert.strictEqual(
110
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.OID, "1.3.6.1.2.1"),
111
- "1.3.6.1.2.1"
112
- );
113
- });
114
-
115
- it('throws on invalid OIDs', function() {
116
- assert.throws(() => {
117
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.OID, "not.an.oid");
118
- }, /Invalid OID/);
119
-
120
- assert.throws(() => {
121
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.OID, "1.2.3.");
122
- }, /Invalid OID/);
123
- });
124
- });
125
-
126
- describe('Counter/Gauge/Unsigned32', function() {
127
- const types = [
128
- snmp.ObjectType.Counter,
129
- snmp.ObjectType.Counter32,
130
- snmp.ObjectType.Gauge,
131
- snmp.ObjectType.Gauge32,
132
- snmp.ObjectType.Unsigned32
133
- ];
134
-
135
- types.forEach(type => {
136
- it(`accepts valid unsigned integers for ${type}`, function() {
137
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(type, 42), 42);
138
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(type, "42"), 42);
139
- });
140
-
141
- it(`throws on negative numbers for ${type}`, function() {
142
- assert.throws(() => {
143
- snmp.ObjectTypeUtil.castSetValue(type, -1);
144
- }, /Integer is negative/);
145
- });
146
-
147
- it(`throws on values exceeding unsigned 32-bit max for ${type}`, function() {
148
- assert.throws(() => {
149
- snmp.ObjectTypeUtil.castSetValue(type, 4294967296); // MAX_UNSIGNED_INT32 + 1
150
- }, /Integer is greater than max unsigned int32/);
151
- });
152
- });
153
- });
154
-
155
- describe('Counter64', function() {
156
- it('accepts valid unsigned integers', function() {
157
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Counter64, 42), 42);
158
- assert.strictEqual(snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Counter64, "42"), 42);
159
- });
160
-
161
- it('accepts valid 8-byte buffers', function() {
162
- const buf = Buffer.alloc(8);
163
- assert.strictEqual(
164
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Counter64, buf),
165
- buf
166
- );
167
- });
168
-
169
- it('throws on invalid buffer length', function() {
170
- assert.throws(() => {
171
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Counter64, Buffer.alloc(7));
172
- }, /Counter64 buffer is not 8 bytes/);
173
- });
174
-
175
- it('throws on negative numbers', function() {
176
- assert.throws(() => {
177
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.Counter64, -1);
178
- }, /Integer is negative for Counter64/);
179
- });
180
- });
181
-
182
- describe('IpAddress', function() {
183
- it('accepts valid IP addresses', function() {
184
- assert.strictEqual(
185
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.IpAddress, "192.168.1.1"),
186
- "192.168.1.1"
187
- );
188
- });
189
-
190
- it('throws on invalid IP addresses', function() {
191
- assert.throws(() => {
192
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.IpAddress, "not.an.ip.address");
193
- }, /Invalid IpAddress/);
194
-
195
- assert.throws(() => {
196
- snmp.ObjectTypeUtil.castSetValue(snmp.ObjectType.IpAddress, "192.168.1");
197
- }, /Invalid IpAddress/);
198
- });
199
- });
200
- });