2019-08-27 21:11:49 +00:00
|
|
|
'use strict'
|
2012-03-26 19:30:23 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const { test } = require('tap')
|
|
|
|
const { BerReader, BerWriter } = require('asn1')
|
|
|
|
const { getControl, PagedResultsControl } = require('../../lib')
|
2012-03-26 19:30:23 +00:00
|
|
|
|
|
|
|
test('new no args', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(new PagedResultsControl())
|
|
|
|
t.end()
|
|
|
|
})
|
2012-03-26 19:30:23 +00:00
|
|
|
|
|
|
|
test('new with args', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const c = new PagedResultsControl({
|
2012-03-26 19:30:23 +00:00
|
|
|
type: '1.2.840.113556.1.4.319',
|
|
|
|
criticality: true,
|
|
|
|
value: {
|
|
|
|
size: 1000,
|
2019-08-27 18:17:33 +00:00
|
|
|
cookie: Buffer.from([1, 2, 3])
|
2012-03-26 19:30:23 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
t.ok(c)
|
|
|
|
t.equal(c.type, '1.2.840.113556.1.4.319')
|
|
|
|
t.ok(c.criticality)
|
|
|
|
t.equal(c.value.size, 1000)
|
2021-04-05 05:34:59 +00:00
|
|
|
t.equal(Buffer.compare(c.value.cookie, Buffer.from([1, 2, 3])), 0)
|
2012-03-26 19:30:23 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const writer = new BerWriter()
|
|
|
|
c.toBer(writer)
|
|
|
|
const reader = new BerReader(writer.buffer)
|
|
|
|
const psc = getControl(reader)
|
|
|
|
t.ok(psc)
|
|
|
|
t.equal(psc.type, '1.2.840.113556.1.4.319')
|
|
|
|
t.ok(psc.criticality)
|
|
|
|
t.equal(psc.value.size, 1000)
|
2021-04-05 05:34:59 +00:00
|
|
|
t.equal(Buffer.compare(psc.value.cookie, Buffer.from([1, 2, 3])), 0)
|
2012-03-26 19:30:23 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.end()
|
|
|
|
})
|
2012-03-26 19:30:23 +00:00
|
|
|
|
|
|
|
test('tober', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const psc = new PagedResultsControl({
|
2012-03-26 19:30:23 +00:00
|
|
|
type: '1.2.840.113556.1.4.319',
|
|
|
|
criticality: true,
|
|
|
|
value: {
|
|
|
|
size: 20,
|
2019-08-27 18:17:33 +00:00
|
|
|
cookie: Buffer.alloc(0)
|
2012-03-26 19:30:23 +00:00
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2012-03-26 19:30:23 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const ber = new BerWriter()
|
|
|
|
psc.toBer(ber)
|
2012-03-26 19:30:23 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const c = getControl(new BerReader(ber.buffer))
|
|
|
|
t.ok(c)
|
|
|
|
t.equal(c.type, '1.2.840.113556.1.4.319')
|
|
|
|
t.ok(c.criticality)
|
|
|
|
t.equal(c.value.size, 20)
|
2021-04-05 05:34:59 +00:00
|
|
|
t.equal(Buffer.compare(c.value.cookie, Buffer.alloc(0)), 0)
|
2012-03-26 19:30:23 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.end()
|
|
|
|
})
|