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/README.md +26 -2
- package/index.js +142 -12
- package/package.json +10 -1
- package/.claude/skills/git-commit/SKILL.md +0 -54
- package/.claude/skills/prepare-release/SKILL.md +0 -97
- package/.claude/skills/propose-action/SKILL.md +0 -111
- package/.claude/skills/publish-release/SKILL.md +0 -68
- package/.github/FUNDING.yml +0 -1
- package/.travis.yml +0 -13
- package/.vscode/launch.json +0 -249
- package/eslint.config.js +0 -98
- package/example/test.js +0 -70
- package/test/README-test-coverage.md +0 -76
- package/test/TEST-MIB.mib +0 -210
- package/test/cast-set-value.test.js +0 -200
- package/test/crypto.test.js +0 -384
- package/test/dgram-module.test.js +0 -71
- package/test/mib.test.js +0 -139
- package/test/object-types.test.js +0 -269
- package/test/oid-in-subtree.test.js +0 -36
- package/test/receiver-test.sh +0 -83
- package/test/snmp-test.sh +0 -122
- package/test/snmpv3-auth-failures.test.js +0 -331
- package/test/strict-int-range-checks.test.js +0 -337
- package/test/subagent.test.js +0 -477
- package/test/transport-option.test.js +0 -53
- package/test/varbinds.test.js +0 -53
package/test/subagent.test.js
DELETED
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const net = require('net');
|
|
3
|
-
const snmp = require('..');
|
|
4
|
-
|
|
5
|
-
describe('Subagent', function() {
|
|
6
|
-
let subagent;
|
|
7
|
-
let mockSocket;
|
|
8
|
-
let originalSocket;
|
|
9
|
-
|
|
10
|
-
function MockSocket() {
|
|
11
|
-
this.connect = () => {};
|
|
12
|
-
this.on = () => this;
|
|
13
|
-
this.write = () => {};
|
|
14
|
-
this.end = () => {};
|
|
15
|
-
this.destroy = () => {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
beforeEach(function() {
|
|
19
|
-
// Stub net.Socket so createSubagent does not open a real TCP connection
|
|
20
|
-
originalSocket = net.Socket;
|
|
21
|
-
net.Socket = MockSocket;
|
|
22
|
-
|
|
23
|
-
mockSocket = {
|
|
24
|
-
connect: () => {},
|
|
25
|
-
on: () => {},
|
|
26
|
-
write: () => {},
|
|
27
|
-
end: () => {}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
subagent = snmp.createSubagent({
|
|
31
|
-
master: 'localhost',
|
|
32
|
-
masterPort: 705,
|
|
33
|
-
timeout: 5,
|
|
34
|
-
description: 'Test Subagent'
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
subagent.socket = mockSocket;
|
|
38
|
-
subagent.sessionID = 123;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
afterEach(function() {
|
|
42
|
-
if (subagent && typeof subagent.close === 'function') {
|
|
43
|
-
subagent.close();
|
|
44
|
-
}
|
|
45
|
-
if (originalSocket) {
|
|
46
|
-
net.Socket = originalSocket;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('Constructor', function() {
|
|
51
|
-
it('creates subagent with default options', function() {
|
|
52
|
-
const sub = snmp.createSubagent({});
|
|
53
|
-
// Prevent actual network connection
|
|
54
|
-
sub.connectSocket = () => {};
|
|
55
|
-
|
|
56
|
-
assert.equal(sub.master, 'localhost');
|
|
57
|
-
assert.equal(sub.masterPort, 705);
|
|
58
|
-
assert.equal(sub.timeout, 0);
|
|
59
|
-
assert.equal(sub.descr, "Node net-snmp AgentX sub-agent");
|
|
60
|
-
assert(sub.mib);
|
|
61
|
-
|
|
62
|
-
// Clean up
|
|
63
|
-
if (typeof sub.close === 'function') {
|
|
64
|
-
sub.close();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('creates subagent with custom options', function() {
|
|
69
|
-
const sub = snmp.createSubagent({
|
|
70
|
-
master: '192.168.1.1',
|
|
71
|
-
masterPort: 8080,
|
|
72
|
-
timeout: 10,
|
|
73
|
-
description: 'Custom Subagent'
|
|
74
|
-
});
|
|
75
|
-
// Prevent actual network connection
|
|
76
|
-
sub.connectSocket = () => {};
|
|
77
|
-
|
|
78
|
-
assert.equal(sub.master, '192.168.1.1');
|
|
79
|
-
assert.equal(sub.masterPort, 8080);
|
|
80
|
-
assert.equal(sub.timeout, 10);
|
|
81
|
-
assert.equal(sub.descr, 'Custom Subagent');
|
|
82
|
-
|
|
83
|
-
// Clean up
|
|
84
|
-
if (typeof sub.close === 'function') {
|
|
85
|
-
sub.close();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('Provider Management', function() {
|
|
91
|
-
let scalarProvider, tableProvider;
|
|
92
|
-
|
|
93
|
-
beforeEach(function() {
|
|
94
|
-
scalarProvider = {
|
|
95
|
-
name: "testScalar",
|
|
96
|
-
type: snmp.MibProviderType.Scalar,
|
|
97
|
-
oid: "1.3.6.1.4.1.8072.9999.1",
|
|
98
|
-
scalarType: snmp.ObjectType.Integer,
|
|
99
|
-
maxAccess: snmp.MaxAccess['read-write']
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
tableProvider = {
|
|
103
|
-
name: "testTable",
|
|
104
|
-
type: snmp.MibProviderType.Table,
|
|
105
|
-
oid: "1.3.6.1.4.1.8072.9999.2",
|
|
106
|
-
maxAccess: snmp.MaxAccess['not-accessible'],
|
|
107
|
-
tableColumns: [
|
|
108
|
-
{
|
|
109
|
-
number: 1,
|
|
110
|
-
name: "testIndex",
|
|
111
|
-
type: snmp.ObjectType.Integer,
|
|
112
|
-
maxAccess: snmp.MaxAccess['not-accessible']
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
number: 2,
|
|
116
|
-
name: "testValue",
|
|
117
|
-
type: snmp.ObjectType.OctetString,
|
|
118
|
-
maxAccess: snmp.MaxAccess['read-write']
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
number: 3,
|
|
122
|
-
name: "testReadOnly",
|
|
123
|
-
type: snmp.ObjectType.Integer,
|
|
124
|
-
maxAccess: snmp.MaxAccess['read-only']
|
|
125
|
-
}
|
|
126
|
-
],
|
|
127
|
-
tableIndex: [{ columnName: "testIndex" }]
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('registers scalar provider', function() {
|
|
132
|
-
let pduSent = null;
|
|
133
|
-
subagent.sendPdu = (pdu, callback) => {
|
|
134
|
-
pduSent = pdu;
|
|
135
|
-
if (callback) callback(null, { error: 0 });
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
subagent.registerProvider(scalarProvider);
|
|
139
|
-
|
|
140
|
-
assert(pduSent);
|
|
141
|
-
assert.equal(pduSent.pduType, snmp.AgentXPduType.Register);
|
|
142
|
-
assert.equal(pduSent.oid, scalarProvider.oid);
|
|
143
|
-
assert(subagent.getProvider('testScalar'));
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('registers table provider', function() {
|
|
147
|
-
let pduSent = null;
|
|
148
|
-
subagent.sendPdu = (pdu, callback) => {
|
|
149
|
-
pduSent = pdu;
|
|
150
|
-
if (callback) callback(null, { error: 0 });
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
subagent.registerProvider(tableProvider);
|
|
154
|
-
|
|
155
|
-
assert(pduSent);
|
|
156
|
-
assert.equal(pduSent.pduType, snmp.AgentXPduType.Register);
|
|
157
|
-
assert.equal(pduSent.oid, tableProvider.oid);
|
|
158
|
-
assert(subagent.getProvider('testTable'));
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('unregisters provider', function() {
|
|
162
|
-
subagent.getMib().registerProvider(scalarProvider);
|
|
163
|
-
|
|
164
|
-
let pduSent = null;
|
|
165
|
-
subagent.sendPdu = (pdu, callback) => {
|
|
166
|
-
pduSent = pdu;
|
|
167
|
-
if (callback) callback(null, { error: 0 });
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
subagent.unregisterProvider('testScalar');
|
|
171
|
-
|
|
172
|
-
assert(pduSent);
|
|
173
|
-
assert.equal(pduSent.pduType, snmp.AgentXPduType.Unregister);
|
|
174
|
-
assert.equal(pduSent.oid, scalarProvider.oid);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('Administrative PDUs', function() {
|
|
179
|
-
it('sends ping PDU', function() {
|
|
180
|
-
let pduSent = null;
|
|
181
|
-
subagent.sendPdu = (pdu, callback) => {
|
|
182
|
-
pduSent = pdu;
|
|
183
|
-
if (callback) callback(null, { error: 0 });
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
subagent.ping();
|
|
187
|
-
|
|
188
|
-
assert(pduSent);
|
|
189
|
-
assert.equal(pduSent.pduType, snmp.AgentXPduType.Ping);
|
|
190
|
-
assert.equal(pduSent.sessionID, 123);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('sends notify PDU', function() {
|
|
194
|
-
let pduSent = null;
|
|
195
|
-
subagent.sendPdu = (pdu, callback) => {
|
|
196
|
-
pduSent = pdu;
|
|
197
|
-
if (callback) callback(null, { error: 0 });
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const varbinds = [
|
|
201
|
-
{
|
|
202
|
-
oid: '1.3.6.1.2.1.1.1.0',
|
|
203
|
-
type: snmp.ObjectType.OctetString,
|
|
204
|
-
value: 'test notification'
|
|
205
|
-
}
|
|
206
|
-
];
|
|
207
|
-
|
|
208
|
-
subagent.notify('1.3.6.1.6.3.1.1.5.1', varbinds);
|
|
209
|
-
|
|
210
|
-
assert(pduSent);
|
|
211
|
-
assert.equal(pduSent.pduType, snmp.AgentXPduType.Notify);
|
|
212
|
-
assert(Array.isArray(pduSent.varbinds));
|
|
213
|
-
assert.equal(pduSent.varbinds.length, 3); // sysUpTime + snmpTrapOID + user varbinds
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('adds agent capabilities', function() {
|
|
217
|
-
let pduSent = null;
|
|
218
|
-
subagent.sendPdu = (pdu, callback) => {
|
|
219
|
-
pduSent = pdu;
|
|
220
|
-
if (callback) callback(null, { error: 0 });
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
subagent.addAgentCaps('1.3.6.1.2.1.1', 'Test capability');
|
|
224
|
-
|
|
225
|
-
assert(pduSent);
|
|
226
|
-
assert.equal(pduSent.pduType, snmp.AgentXPduType.AddAgentCaps);
|
|
227
|
-
assert.equal(pduSent.oid, '1.3.6.1.2.1.1');
|
|
228
|
-
assert.equal(pduSent.descr, 'Test capability');
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('removes agent capabilities', function() {
|
|
232
|
-
let pduSent = null;
|
|
233
|
-
subagent.sendPdu = (pdu, callback) => {
|
|
234
|
-
pduSent = pdu;
|
|
235
|
-
if (callback) callback(null, { error: 0 });
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
subagent.removeAgentCaps('1.3.6.1.2.1.1');
|
|
239
|
-
|
|
240
|
-
assert(pduSent);
|
|
241
|
-
assert.equal(pduSent.pduType, snmp.AgentXPduType.RemoveAgentCaps);
|
|
242
|
-
assert.equal(pduSent.oid, '1.3.6.1.2.1.1');
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
describe('Utility Methods', function() {
|
|
247
|
-
it('returns correct MIB instance', function() {
|
|
248
|
-
assert(subagent.getMib());
|
|
249
|
-
assert.equal(typeof subagent.getMib().registerProvider, 'function');
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('emits close event', function(done) {
|
|
253
|
-
subagent.on('close', () => {
|
|
254
|
-
done();
|
|
255
|
-
});
|
|
256
|
-
subagent.onClose();
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('emits error event', function(done) {
|
|
260
|
-
const testError = new Error('Test error');
|
|
261
|
-
subagent.on('error', (error) => {
|
|
262
|
-
assert.equal(error, testError);
|
|
263
|
-
done();
|
|
264
|
-
});
|
|
265
|
-
subagent.onError(testError);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
describe('Subagent Enhanced Tests for PR #280', function() {
|
|
270
|
-
// Tests for new functionality from PR #280
|
|
271
|
-
|
|
272
|
-
describe('isAllowed Method (Access Control)', function() {
|
|
273
|
-
let scalarProvider, tableProvider;
|
|
274
|
-
|
|
275
|
-
beforeEach(function() {
|
|
276
|
-
scalarProvider = {
|
|
277
|
-
name: "testScalar",
|
|
278
|
-
type: snmp.MibProviderType.Scalar,
|
|
279
|
-
oid: "1.3.6.1.4.1.8072.9999.1",
|
|
280
|
-
scalarType: snmp.ObjectType.Integer,
|
|
281
|
-
maxAccess: snmp.MaxAccess['read-write']
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
tableProvider = {
|
|
285
|
-
name: "testTable",
|
|
286
|
-
type: snmp.MibProviderType.Table,
|
|
287
|
-
oid: "1.3.6.1.4.1.8072.9999.2",
|
|
288
|
-
maxAccess: snmp.MaxAccess['not-accessible'],
|
|
289
|
-
tableColumns: [
|
|
290
|
-
{
|
|
291
|
-
number: 1,
|
|
292
|
-
name: "testIndex",
|
|
293
|
-
type: snmp.ObjectType.Integer,
|
|
294
|
-
maxAccess: snmp.MaxAccess['not-accessible']
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
number: 2,
|
|
298
|
-
name: "testValue",
|
|
299
|
-
type: snmp.ObjectType.OctetString,
|
|
300
|
-
maxAccess: snmp.MaxAccess['read-write']
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
number: 3,
|
|
304
|
-
name: "testReadOnly",
|
|
305
|
-
type: snmp.ObjectType.Integer,
|
|
306
|
-
maxAccess: snmp.MaxAccess['read-only']
|
|
307
|
-
}
|
|
308
|
-
],
|
|
309
|
-
tableIndex: [{ columnName: "testIndex" }]
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
subagent.getMib().registerProvider(scalarProvider);
|
|
313
|
-
subagent.getMib().registerProvider(tableProvider);
|
|
314
|
-
subagent.getMib().addTableRow('testTable', [1, 'test', 42]);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('allows read access to read-write scalar', function() {
|
|
318
|
-
if (typeof subagent.isAllowed === 'function') {
|
|
319
|
-
const result = subagent.isAllowed(snmp.AgentXPduType.Get, scalarProvider, null);
|
|
320
|
-
assert.equal(result, true);
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it('allows write access to read-write scalar', function() {
|
|
325
|
-
if (typeof subagent.isAllowed === 'function') {
|
|
326
|
-
const result = subagent.isAllowed(snmp.AgentXPduType.TestSet, scalarProvider, null);
|
|
327
|
-
assert.equal(result, true);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it('allows read access to read-only table column', function() {
|
|
332
|
-
if (typeof subagent.isAllowed === 'function') {
|
|
333
|
-
const instanceNode = subagent.getMib().lookup('1.3.6.1.4.1.8072.9999.2.3.1');
|
|
334
|
-
if (instanceNode) {
|
|
335
|
-
const result = subagent.isAllowed(snmp.AgentXPduType.Get, tableProvider, instanceNode);
|
|
336
|
-
assert.equal(result, true);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('denies write access to read-only table column', function() {
|
|
342
|
-
if (typeof subagent.isAllowed === 'function') {
|
|
343
|
-
const instanceNode = subagent.getMib().lookup('1.3.6.1.4.1.8072.9999.2.3.1');
|
|
344
|
-
if (instanceNode) {
|
|
345
|
-
const result = subagent.isAllowed(snmp.AgentXPduType.TestSet, tableProvider, instanceNode);
|
|
346
|
-
assert.equal(result, false);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
describe('Set Operations Transaction Management', function() {
|
|
353
|
-
let scalarProvider;
|
|
354
|
-
|
|
355
|
-
beforeEach(function() {
|
|
356
|
-
scalarProvider = {
|
|
357
|
-
name: "testScalar",
|
|
358
|
-
type: snmp.MibProviderType.Scalar,
|
|
359
|
-
oid: "1.3.6.1.4.1.8072.9999.1",
|
|
360
|
-
scalarType: snmp.ObjectType.Integer,
|
|
361
|
-
maxAccess: snmp.MaxAccess['read-write']
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
subagent.getMib().registerProvider(scalarProvider);
|
|
365
|
-
subagent.getMib().setScalarValue('testScalar', 100);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it('manages set transactions correctly', function() {
|
|
369
|
-
// Create proper AgentXPdu objects using createFromVariables
|
|
370
|
-
const testSetPdu = snmp.AgentXPdu.createFromVariables({
|
|
371
|
-
pduType: snmp.AgentXPduType.TestSet,
|
|
372
|
-
sessionID: subagent.sessionID,
|
|
373
|
-
transactionID: 123,
|
|
374
|
-
varbinds: [{
|
|
375
|
-
oid: '1.3.6.1.4.1.8072.9999.1.0',
|
|
376
|
-
type: snmp.ObjectType.Integer,
|
|
377
|
-
value: 200
|
|
378
|
-
}]
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
subagent.testSet(testSetPdu);
|
|
382
|
-
assert(subagent.setTransactions[123]);
|
|
383
|
-
|
|
384
|
-
const cleanupSetPdu = snmp.AgentXPdu.createFromVariables({
|
|
385
|
-
pduType: snmp.AgentXPduType.CleanupSet,
|
|
386
|
-
sessionID: subagent.sessionID,
|
|
387
|
-
transactionID: 123
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
subagent.cleanupSet(cleanupSetPdu);
|
|
391
|
-
assert(!subagent.setTransactions[123]);
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
it('handles unexpected transaction IDs', function() {
|
|
395
|
-
const commitSetPdu = snmp.AgentXPdu.createFromVariables({
|
|
396
|
-
pduType: snmp.AgentXPduType.CommitSet,
|
|
397
|
-
sessionID: subagent.sessionID,
|
|
398
|
-
transactionID: 999
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
assert.throws(() => {
|
|
402
|
-
subagent.commitSet(commitSetPdu);
|
|
403
|
-
}, /Unexpected CommitSet PDU/);
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
describe('Bulk Set Handler', function() {
|
|
408
|
-
let scalarProvider1, scalarProvider2;
|
|
409
|
-
|
|
410
|
-
beforeEach(function() {
|
|
411
|
-
scalarProvider1 = {
|
|
412
|
-
name: "testScalar1",
|
|
413
|
-
type: snmp.MibProviderType.Scalar,
|
|
414
|
-
oid: "1.3.6.1.4.1.8072.9999.1",
|
|
415
|
-
scalarType: snmp.ObjectType.Integer,
|
|
416
|
-
maxAccess: snmp.MaxAccess['read-write']
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
scalarProvider2 = {
|
|
420
|
-
name: "testScalar2",
|
|
421
|
-
type: snmp.MibProviderType.Scalar,
|
|
422
|
-
oid: "1.3.6.1.4.1.8072.9999.2",
|
|
423
|
-
scalarType: snmp.ObjectType.Integer,
|
|
424
|
-
maxAccess: snmp.MaxAccess['read-write']
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
subagent.getMib().registerProvider(scalarProvider1);
|
|
428
|
-
subagent.getMib().registerProvider(scalarProvider2);
|
|
429
|
-
subagent.getMib().setScalarValue('testScalar1', 100);
|
|
430
|
-
subagent.getMib().setScalarValue('testScalar2', 200);
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it('sets bulk set handler correctly', function() {
|
|
434
|
-
const handler = (mibRequests, mib, testSet) => {
|
|
435
|
-
return snmp.ErrorStatus.NoError;
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
if (typeof subagent.setBulkSetHandler === 'function') {
|
|
439
|
-
subagent.setBulkSetHandler(handler);
|
|
440
|
-
assert.equal(subagent.bulkSetHandler, handler);
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
describe('Value Validation', function() {
|
|
446
|
-
let scalarProvider;
|
|
447
|
-
|
|
448
|
-
beforeEach(function() {
|
|
449
|
-
scalarProvider = {
|
|
450
|
-
name: "testScalar",
|
|
451
|
-
type: snmp.MibProviderType.Scalar,
|
|
452
|
-
oid: "1.3.6.1.4.1.8072.9999.1",
|
|
453
|
-
scalarType: snmp.ObjectType.Integer,
|
|
454
|
-
maxAccess: snmp.MaxAccess['read-write'],
|
|
455
|
-
constraints: {
|
|
456
|
-
ranges: [{ min: 1, max: 100 }]
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
subagent.getMib().registerProvider(scalarProvider);
|
|
461
|
-
subagent.getMib().setScalarValue('testScalar', 50);
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it('validates integer constraints', function() {
|
|
465
|
-
// This tests the underlying validation that would be used in set operations
|
|
466
|
-
const instanceNode = subagent.getMib().lookup('1.3.6.1.4.1.8072.9999.1.0');
|
|
467
|
-
if (instanceNode && typeof instanceNode.validateValue === 'function') {
|
|
468
|
-
const validResult = instanceNode.validateValue(snmp.ObjectType.Integer, 75);
|
|
469
|
-
assert.equal(validResult, true);
|
|
470
|
-
|
|
471
|
-
const invalidResult = instanceNode.validateValue(snmp.ObjectType.Integer, 150);
|
|
472
|
-
assert.equal(invalidResult, false);
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const snmp = require('../index.js');
|
|
3
|
-
|
|
4
|
-
describe('Transport Option Handling in createV3Session', function() {
|
|
5
|
-
const user = {
|
|
6
|
-
name: "testuser",
|
|
7
|
-
level: snmp.SecurityLevel.noAuthNoPriv
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
afterEach(function() {
|
|
11
|
-
// Clean up any open sessions
|
|
12
|
-
// Note: sessions are closed in individual tests
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should use default transport when not specified', function() {
|
|
16
|
-
const session = snmp.createV3Session("127.0.0.1", user);
|
|
17
|
-
assert.strictEqual(session.transport, "udp4");
|
|
18
|
-
session.close();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should use default transport when options is empty object', function() {
|
|
22
|
-
const session = snmp.createV3Session("127.0.0.1", user, {});
|
|
23
|
-
assert.strictEqual(session.transport, "udp4");
|
|
24
|
-
session.close();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should preserve explicit udp4 transport', function() {
|
|
28
|
-
const session = snmp.createV3Session("127.0.0.1", user, { transport: "udp4" });
|
|
29
|
-
assert.strictEqual(session.transport, "udp4");
|
|
30
|
-
session.close();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should preserve udp6 transport', function() {
|
|
34
|
-
const session = snmp.createV3Session("127.0.0.1", user, { transport: "udp6" });
|
|
35
|
-
assert.strictEqual(session.transport, "udp6");
|
|
36
|
-
session.close();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should handle null transport by using default', function() {
|
|
40
|
-
const session = snmp.createV3Session("127.0.0.1", user, { transport: null });
|
|
41
|
-
assert.strictEqual(session.transport, "udp4");
|
|
42
|
-
session.close();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should preserve invalid transport values (let Node.js validate)', function() {
|
|
46
|
-
assert.throws(function() {
|
|
47
|
-
snmp.createV3Session("127.0.0.1", user, { transport: "invalid" });
|
|
48
|
-
}, function(err) {
|
|
49
|
-
return err.code === 'ERR_SOCKET_BAD_TYPE';
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
});
|
package/test/varbinds.test.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const ber = require ('asn1-ber').Ber;
|
|
3
|
-
const snmp = require('..');
|
|
4
|
-
|
|
5
|
-
describe('Varbinds', function() {
|
|
6
|
-
|
|
7
|
-
describe('parseInt()', function() {
|
|
8
|
-
describe('given a negative integer', function() {
|
|
9
|
-
const writer = new ber.Writer();
|
|
10
|
-
writer.writeInt(-3);
|
|
11
|
-
const reader = new ber.Reader(writer.buffer);
|
|
12
|
-
it('returns a negative integer', function() {
|
|
13
|
-
assert.equal(snmp.ObjectParser.readInt32(reader), -3);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
describe('given a positive integer', function() {
|
|
17
|
-
const writer = new ber.Writer();
|
|
18
|
-
writer.writeInt(3245689);
|
|
19
|
-
const reader = new ber.Reader(writer.buffer);
|
|
20
|
-
it('returns a positive integer', function() {
|
|
21
|
-
assert.equal(snmp.ObjectParser.readInt32(reader), 3245689);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('parseUint()', function() {
|
|
27
|
-
describe('given a positive integer', function() {
|
|
28
|
-
const writer = new ber.Writer();
|
|
29
|
-
writer.writeInt(3242425);
|
|
30
|
-
const reader = new ber.Reader(writer.buffer);
|
|
31
|
-
it('returns a positive integer', function() {
|
|
32
|
-
assert.equal(snmp.ObjectParser.readUint32(reader), 3242425);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe('given a negative integer', function() {
|
|
36
|
-
const writer = new ber.Writer();
|
|
37
|
-
writer.writeInt(-3);
|
|
38
|
-
const reader = new ber.Reader(writer.buffer);
|
|
39
|
-
it('returns a positive integer', function() {
|
|
40
|
-
assert.equal(snmp.ObjectParser.readUint32(reader), 4294967293);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe('given a large integer', function() {
|
|
44
|
-
const writer = new ber.Writer();
|
|
45
|
-
writer.writeInt(4294967294);
|
|
46
|
-
const reader = new ber.Reader(writer.buffer);
|
|
47
|
-
it('returns a positive integer', function() {
|
|
48
|
-
assert.equal(snmp.ObjectParser.readUint32(reader), 4294967294);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
});
|