diff --git a/lib/change.js b/lib/change.js index 1805b4d..e65c45e 100644 --- a/lib/change.js +++ b/lib/change.js @@ -81,6 +81,8 @@ Object.defineProperties(Change.prototype, { val[k].forEach(function (v) { _attr.addValue(v.toString()) }) + } else if (Buffer.isBuffer(val[k])) { + _attr.addValue(val[k]) } else if (val[k] !== undefined && val[k] !== null) { _attr.addValue(val[k].toString()) } diff --git a/test/change.test.js b/test/change.test.js index 6dd1576..829b8b6 100644 --- a/test/change.test.js +++ b/test/change.test.js @@ -1,5 +1,7 @@ 'use strict' +const fs = require('fs') +const path = require('path') const { test } = require('tap') const { BerReader, BerWriter } = require('asn1') const { Attribute, Change } = require('../lib') @@ -28,6 +30,26 @@ test('new with args', function (t) { t.end() }) +test('new with args and buffer', function (t) { + var img = fs.readFileSync(path.join(__dirname, '/imgs/test.jpg')) + + var change = new Change({ + operation: 'add', + modification: { + thumbnailPhoto: img + } + }) + + t.ok(change) + + t.equal(change.operation, 'add') + t.equal(change.modification.type, 'thumbnailPhoto') + t.equal(change.modification.vals.length, 1) + t.equal(change.modification.buffers[0].compare(img), 0) + + t.end() +}) + test('validate fields', function (t) { const c = new Change() t.ok(c) diff --git a/test/imgs/test.jpg b/test/imgs/test.jpg new file mode 100644 index 0000000..97ce548 Binary files /dev/null and b/test/imgs/test.jpg differ