Merge pull request #754 from JohnTJohnston/clientFix

This commit is contained in:
Tony Brix 2021-08-03 11:35:22 -05:00 committed by GitHub
commit b9712046f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -238,6 +238,8 @@ Client.prototype.add = function add (name, entry, controls, callback) {
save[k].forEach(function (v) {
attr.addValue(v.toString())
})
} else if (Buffer.isBuffer(save[k])) {
attr.addValue(save[k])
} else {
attr.addValue(save[k].toString())
}

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)