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

54 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict'
2011-08-04 20:32:01 +00:00
const { test } = require('tap')
2022-03-27 14:13:16 +00:00
const { BerReader, BerWriter } = require('@ldapjs/asn1')
const { Control, getControl } = require('../../lib')
2011-08-04 20:32:01 +00:00
test('new no args', function (t) {
t.ok(new Control())
t.end()
})
2011-08-04 20:32:01 +00:00
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()
})
2011-08-04 20:32:01 +00:00
test('parse', function (t) {
const ber = new BerWriter()
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))
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')
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()
})