2019-08-27 18:17:33 +00:00
|
|
|
'use strict';
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
const { test } = require('tap');
|
|
|
|
const { BerReader, BerWriter } = require('asn1');
|
|
|
|
const { ExtendedRequest } = require('../../lib');
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new no args', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
t.ok(new ExtendedRequest());
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new with args', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ExtendedRequest({
|
2011-08-04 20:32:01 +00:00
|
|
|
requestName: '1.2.3.4',
|
|
|
|
requestValue: 'test'
|
|
|
|
});
|
|
|
|
t.ok(req);
|
|
|
|
t.equal(req.requestName, '1.2.3.4');
|
|
|
|
t.equal(req.requestValue, 'test');
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
t.equal(req.value, 'test');
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('new with buffer args', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ExtendedRequest({
|
2019-08-27 12:04:45 +00:00
|
|
|
requestName: '1.2.3.4',
|
2019-08-27 18:17:33 +00:00
|
|
|
requestValue: Buffer.from('test', 'utf8')
|
2019-08-27 12:04:45 +00:00
|
|
|
});
|
|
|
|
t.ok(req);
|
|
|
|
t.equal(req.requestName, '1.2.3.4');
|
|
|
|
t.equal(req.requestValue, req.requestValueBuffer);
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
t.equal(req.value, req.valueBuffer);
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('new no args set args', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ExtendedRequest();
|
2019-08-27 12:04:45 +00:00
|
|
|
t.ok(req);
|
|
|
|
|
|
|
|
req.name = '1.2.3.4';
|
|
|
|
t.equal(req.requestName, '1.2.3.4');
|
|
|
|
|
|
|
|
req.value = 'test';
|
|
|
|
t.equal(req.requestValue, 'test');
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
t.equal(req.value, 'test');
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('new no args set args buffer', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ExtendedRequest();
|
2019-08-27 12:04:45 +00:00
|
|
|
t.ok(req);
|
|
|
|
|
|
|
|
req.name = '1.2.3.4';
|
|
|
|
t.equal(req.requestName, '1.2.3.4');
|
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
req.value = Buffer.from('test', 'utf8');
|
2019-08-27 12:04:45 +00:00
|
|
|
t.equal(req.requestValue, req.requestValueBuffer);
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
t.equal(req.value, req.valueBuffer);
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
|
2011-08-04 20:32:01 +00:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const ber = new BerWriter();
|
2011-08-04 20:32:01 +00:00
|
|
|
ber.writeString('1.2.3.4', 0x80);
|
|
|
|
ber.writeString('test', 0x81);
|
|
|
|
|
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ExtendedRequest();
|
2011-08-04 20:32:01 +00:00
|
|
|
t.ok(req._parse(new BerReader(ber.buffer)));
|
|
|
|
t.equal(req.requestName, '1.2.3.4');
|
|
|
|
t.equal(req.requestValue, 'test');
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
|
2019-08-27 12:04:45 +00:00
|
|
|
t.equal(req.value, 'test');
|
2019-08-27 18:17:33 +00:00
|
|
|
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
|
2011-08-04 20:32:01 +00:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('toBer', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ExtendedRequest({
|
2011-08-04 20:32:01 +00:00
|
|
|
messageID: 123,
|
|
|
|
requestName: '1.2.3.4',
|
|
|
|
requestValue: 'test'
|
|
|
|
});
|
|
|
|
|
|
|
|
t.ok(req);
|
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
const ber = new BerReader(req.toBer());
|
2011-08-04 20:32:01 +00:00
|
|
|
t.ok(ber);
|
|
|
|
t.equal(ber.readSequence(), 0x30);
|
|
|
|
t.equal(ber.readInt(), 123);
|
|
|
|
t.equal(ber.readSequence(), 0x77);
|
|
|
|
t.equal(ber.readString(0x80), '1.2.3.4');
|
|
|
|
t.equal(ber.readString(0x81), 'test');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
2019-08-27 12:04:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
test('toBer from buffer', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new ExtendedRequest({
|
2019-08-27 12:04:45 +00:00
|
|
|
messageID: 123,
|
|
|
|
requestName: '1.2.3.4',
|
2019-08-27 18:17:33 +00:00
|
|
|
requestValue: Buffer.from('test', 'utf8')
|
2019-08-27 12:04:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
t.ok(req);
|
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
const ber = new BerReader(req.toBer());
|
2019-08-27 12:04:45 +00:00
|
|
|
t.ok(ber);
|
|
|
|
t.equal(ber.readSequence(), 0x30);
|
|
|
|
t.equal(ber.readInt(), 123);
|
|
|
|
t.equal(ber.readSequence(), 0x77);
|
|
|
|
t.equal(ber.readString(0x80), '1.2.3.4');
|
|
|
|
t.equal(ber.readString(0x81), 'test');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|