From 3e3fa4ba1218cb21236714fffee2b716cc55be14 Mon Sep 17 00:00:00 2001 From: John Johnston Date: Thu, 29 Jul 2021 08:58:08 -0700 Subject: [PATCH 1/3] fix: client.add not adding buffers properly Fixed while getting AD thumbnailPhoto to work. --- lib/client/client.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/client/client.js b/lib/client/client.js index b982c3a..4f52dde 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -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()) } From fc0346bce1f3708bf819e07c94517687ddcaa318 Mon Sep 17 00:00:00 2001 From: John Johnston Date: Thu, 29 Jul 2021 10:13:47 -0700 Subject: [PATCH 2/3] fix: lint fix --- lib/client/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client/client.js b/lib/client/client.js index 4f52dde..9d5a638 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -239,7 +239,7 @@ Client.prototype.add = function add (name, entry, controls, callback) { attr.addValue(v.toString()) }) } else if (Buffer.isBuffer(save[k])) { - attr.addValue(save[k]); + attr.addValue(save[k]) } else { attr.addValue(save[k].toString()) } From b6d60b90101171a8b5ad3b3eeda3cd8440f927fc Mon Sep 17 00:00:00 2001 From: John Johnston Date: Sun, 1 Aug 2021 12:38:00 -0700 Subject: [PATCH 3/3] chore: 'add buffer' unit test --- test/client.test.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/client.test.js b/test/client.test.js index 7d27a86..e05a0bf 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -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)