node-ldapjs/test/controls/control.test.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
2011-08-04 20:32:01 +00:00
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { Control, getControl } = require('../../lib');
2011-08-04 20:32:01 +00:00
test('new no args', function (t) {
2011-08-04 20:32:01 +00:00
t.ok(new Control());
t.end();
});
test('new with args', function (t) {
const c = new Control({
2011-08-04 20:32:01 +00:00
type: '2.16.840.1.113730.3.4.2',
criticality: true
});
t.ok(c);
t.equal(c.type, '2.16.840.1.113730.3.4.2');
t.ok(c.criticality);
t.end();
});
test('parse', function (t) {
const ber = new BerWriter();
2011-08-04 20:32:01 +00:00
ber.startSequence();
ber.writeString('2.16.840.1.113730.3.4.2');
ber.writeBoolean(true);
ber.writeString('foo');
ber.endSequence();
const c = getControl(new BerReader(ber.buffer));
2011-08-04 20:32:01 +00:00
t.ok(c);
t.equal(c.type, '2.16.840.1.113730.3.4.2');
t.ok(c.criticality);
t.equal(c.value.toString('utf8'), 'foo');
2011-08-04 20:32:01 +00:00
t.end();
});
test('parse no value', function (t) {
const ber = new BerWriter();
ber.startSequence();
ber.writeString('2.16.840.1.113730.3.4.2');
ber.endSequence();
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '2.16.840.1.113730.3.4.2');
t.equal(c.criticality, false);
t.notOk(c.value, null);
t.end();
});