2011-12-08 01:02:17 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const test = require('tap').test
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const asn1 = require('asn1')
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const BerReader = asn1.BerReader
|
|
|
|
const BerWriter = asn1.BerWriter
|
|
|
|
let getControl
|
|
|
|
let PersistentSearchControl
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
/// --- Tests
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('load library', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
PersistentSearchControl = require('../../lib').PersistentSearchControl
|
|
|
|
t.ok(PersistentSearchControl)
|
|
|
|
getControl = require('../../lib').getControl
|
|
|
|
t.ok(getControl)
|
|
|
|
t.end()
|
|
|
|
})
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new no args', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(new PersistentSearchControl())
|
|
|
|
t.end()
|
|
|
|
})
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new with args', function (t) {
|
2020-10-31 21:07:32 +00:00
|
|
|
const c = new PersistentSearchControl({
|
2011-12-08 01:02:17 +00:00
|
|
|
type: '2.16.840.1.113730.3.4.3',
|
|
|
|
criticality: true,
|
|
|
|
value: {
|
|
|
|
changeTypes: 15,
|
|
|
|
changesOnly: false,
|
|
|
|
returnECs: false
|
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
t.ok(c)
|
|
|
|
t.equal(c.type, '2.16.840.1.113730.3.4.3')
|
|
|
|
t.ok(c.criticality)
|
|
|
|
|
|
|
|
t.equal(c.value.changeTypes, 15)
|
|
|
|
t.equal(c.value.changesOnly, false)
|
|
|
|
t.equal(c.value.returnECs, false)
|
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const writer = new BerWriter()
|
2019-08-27 21:11:49 +00:00
|
|
|
c.toBer(writer)
|
2020-10-31 21:07:32 +00:00
|
|
|
const reader = new BerReader(writer.buffer)
|
|
|
|
const psc = getControl(reader)
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(psc)
|
|
|
|
t.equal(psc.type, '2.16.840.1.113730.3.4.3')
|
|
|
|
t.ok(psc.criticality)
|
|
|
|
t.equal(psc.value.changeTypes, 15)
|
|
|
|
t.equal(psc.value.changesOnly, false)
|
|
|
|
t.equal(psc.value.returnECs, false)
|
|
|
|
|
|
|
|
t.end()
|
|
|
|
})
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('getControl with args', function (t) {
|
2020-10-31 21:07:32 +00:00
|
|
|
const buf = Buffer.from([
|
2011-12-08 01:02:17 +00:00
|
|
|
0x30, 0x26, 0x04, 0x17, 0x32, 0x2e, 0x31, 0x36, 0x2e, 0x38, 0x34, 0x30,
|
|
|
|
0x2e, 0x31, 0x2e, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2e, 0x33, 0x2e,
|
|
|
|
0x34, 0x2e, 0x33, 0x04, 0x0b, 0x30, 0x09, 0x02, 0x01, 0x0f, 0x01, 0x01,
|
2019-08-27 21:11:49 +00:00
|
|
|
0xff, 0x01, 0x01, 0xff])
|
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const ber = new BerReader(buf)
|
|
|
|
const psc = getControl(ber)
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(psc)
|
|
|
|
t.equal(psc.type, '2.16.840.1.113730.3.4.3')
|
|
|
|
t.equal(psc.criticality, false)
|
|
|
|
t.equal(psc.value.changeTypes, 15)
|
|
|
|
t.equal(psc.value.changesOnly, true)
|
|
|
|
t.equal(psc.value.returnECs, true)
|
|
|
|
t.end()
|
|
|
|
})
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('tober', function (t) {
|
2020-10-31 21:07:32 +00:00
|
|
|
const psc = new PersistentSearchControl({
|
2011-12-08 01:02:17 +00:00
|
|
|
type: '2.16.840.1.113730.3.4.3',
|
|
|
|
criticality: true,
|
|
|
|
value: {
|
|
|
|
changeTypes: 15,
|
|
|
|
changesOnly: false,
|
|
|
|
returnECs: false
|
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const ber = new BerWriter()
|
2019-08-27 21:11:49 +00:00
|
|
|
psc.toBer(ber)
|
|
|
|
|
2020-10-31 21:07:32 +00:00
|
|
|
const c = getControl(new BerReader(ber.buffer))
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(c)
|
|
|
|
t.equal(c.type, '2.16.840.1.113730.3.4.3')
|
|
|
|
t.ok(c.criticality)
|
|
|
|
t.equal(c.value.changeTypes, 15)
|
|
|
|
t.equal(c.value.changesOnly, false)
|
|
|
|
t.equal(c.value.returnECs, false)
|
|
|
|
t.end()
|
|
|
|
})
|