chore: 'add buffer' unit test

This commit is contained in:
John Johnston 2021-08-01 12:38:00 -07:00
parent fc0346bce1
commit b6d60b9010
1 changed files with 34 additions and 0 deletions

View File

@ -508,6 +508,40 @@ tap.test('add success with object', function (t) {
})
})
tap.test('add buffer', function (t) {
const { BerReader } = require('asn1')
const dn = `cn=add, ${SUFFIX}`
const attribute = 'thumbnailPhoto'
const binary = 0xa5
const entry = {
[attribute]: Buffer.from([binary])
}
const write = t.context.client._socket.write
t.context.client._socket.write = (data, encoding, cb) => {
const reader = new BerReader(data)
t.equal(data.byteLength, 49)
t.ok(reader.readSequence())
t.equal(reader.readInt(), 0x1)
t.equal(reader.readSequence(), 0x68)
t.equal(reader.readString(), dn)
t.ok(reader.readSequence())
t.ok(reader.readSequence())
t.equal(reader.readString(), attribute)
t.equal(reader.readSequence(), 0x31)
t.equal(reader.readByte(), 0x4)
t.equal(reader.readByte(), 1)
t.equal(reader.readByte(), binary)
t.context.client._socket.write = write
t.context.client._socket.write(data, encoding, cb)
}
t.context.client.add(dn, entry, function (err, res) {
t.error(err)
t.ok(res)
t.equal(res.status, 0)
t.end()
})
})
tap.test('compare success', function (t) {
t.context.client.compare('cn=compare, ' + SUFFIX, 'cn', 'test', function (err, matched, res) {
t.error(err)