GH-21: Write attribute values as raw binary, rather than as strings
This commit is contained in:
parent
c20030f5bb
commit
2a41abbff8
|
@ -118,15 +118,19 @@ Attribute.prototype.parse = function(ber) {
|
||||||
Attribute.prototype.toBer = function(ber) {
|
Attribute.prototype.toBer = function(ber) {
|
||||||
assert.ok(ber);
|
assert.ok(ber);
|
||||||
|
|
||||||
var vals = [];
|
|
||||||
this._vals.forEach(function(v) {
|
|
||||||
vals.push(v.toString('utf8'));
|
|
||||||
});
|
|
||||||
|
|
||||||
ber.startSequence();
|
ber.startSequence();
|
||||||
ber.writeString(this.type);
|
ber.writeString(this.type);
|
||||||
ber.startSequence(Protocol.LBER_SET);
|
ber.startSequence(Protocol.LBER_SET);
|
||||||
ber.writeStringArray(vals);
|
if (this._vals.length) {
|
||||||
|
this._vals.forEach(function(b) {
|
||||||
|
ber.writeByte(asn1.Ber.OctetString);
|
||||||
|
ber.writeLength(b.length);
|
||||||
|
for (var i = 0; i < b.length; i++)
|
||||||
|
ber.writeByte(b[i]);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ber.writeStringArray([]);
|
||||||
|
}
|
||||||
ber.endSequence();
|
ber.endSequence();
|
||||||
ber.endSequence();
|
ber.endSequence();
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ test('setup', function(t) {
|
||||||
objectName: req.dn,
|
objectName: req.dn,
|
||||||
attributes: {
|
attributes: {
|
||||||
'foo;binary': 'wr0gKyDCvCA9IMK+',
|
'foo;binary': 'wr0gKyDCvCA9IMK+',
|
||||||
|
'gb18030': new Buffer([0xB5, 0xE7, 0xCA, 0xD3, 0xBB, 0xFA]),
|
||||||
'objectclass': 'binary'
|
'objectclass': 'binary'
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -438,6 +439,7 @@ test('GH-21 binary attributes', function(t) {
|
||||||
t.ok(res);
|
t.ok(res);
|
||||||
var gotEntry = 0;
|
var gotEntry = 0;
|
||||||
var expect = new Buffer('\u00bd + \u00bc = \u00be', 'utf8');
|
var expect = new Buffer('\u00bd + \u00bc = \u00be', 'utf8');
|
||||||
|
var expect2 = new Buffer([0xB5, 0xE7, 0xCA, 0xD3, 0xBB, 0xFA]);
|
||||||
res.on('searchEntry', function(entry) {
|
res.on('searchEntry', function(entry) {
|
||||||
t.ok(entry);
|
t.ok(entry);
|
||||||
t.ok(entry instanceof ldap.SearchEntry);
|
t.ok(entry instanceof ldap.SearchEntry);
|
||||||
|
@ -448,6 +450,13 @@ test('GH-21 binary attributes', function(t) {
|
||||||
t.equal(entry.attributes[0].vals[0], expect.toString('base64'));
|
t.equal(entry.attributes[0].vals[0], expect.toString('base64'));
|
||||||
t.equal(entry.attributes[0].buffers[0].toString('base64'),
|
t.equal(entry.attributes[0].buffers[0].toString('base64'),
|
||||||
expect.toString('base64'));
|
expect.toString('base64'));
|
||||||
|
|
||||||
|
t.ok(entry.attributes[1].type, 'gb18030');
|
||||||
|
t.equal(entry.attributes[1].buffers.length, 1);
|
||||||
|
t.equal(expect2.length, entry.attributes[1].buffers[0].length);
|
||||||
|
for (var i = 0; i < expect2.length; i++)
|
||||||
|
t.equal(expect2[i], entry.attributes[1].buffers[0][i]);
|
||||||
|
|
||||||
t.ok(entry.object);
|
t.ok(entry.object);
|
||||||
gotEntry++;
|
gotEntry++;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue