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

77 lines
1.4 KiB
JavaScript
Raw Normal View History

2011-08-04 20:32:01 +00:00
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var Control;
var getControl;
2011-08-04 20:32:01 +00:00
///--- Tests
test('load library', function (t) {
2011-12-09 21:59:17 +00:00
Control = require('../../lib/index').Control;
2011-08-04 20:32:01 +00:00
t.ok(Control);
2011-12-09 21:59:17 +00:00
getControl = require('../../lib/index').getControl;
t.ok(getControl);
2011-08-04 20:32:01 +00:00
t.end();
});
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) {
2011-08-04 20:32:01 +00:00
var c = new Control({
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) {
2011-08-04 20:32:01 +00:00
var ber = new BerWriter();
ber.startSequence();
ber.writeString('2.16.840.1.113730.3.4.2');
ber.writeBoolean(true);
ber.writeString('foo');
ber.endSequence();
var 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, 'foo');
t.end();
});
test('parse no value', function (t) {
var ber = new BerWriter();
ber.startSequence();
ber.writeString('2.16.840.1.113730.3.4.2');
ber.endSequence();
var 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();
});