Comparing version 0.1.9 to 0.2.0
@@ -5,2 +5,4 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
var asn1 = require('asn1'); | ||
var Protocol = require('./protocol'); | ||
@@ -18,10 +20,2 @@ | ||
throw new TypeError('options.type must be a string'); | ||
if (options.vals && !Array.isArray(options.vals)) | ||
throw new TypeErrr('options.vals must be an array[string]'); | ||
if (options.vals && options.vals.length) { | ||
options.vals.forEach(function(v) { | ||
if (typeof(v) !== 'string') | ||
throw new TypeErrr('options.vals must be an array[string]'); | ||
}); | ||
} | ||
} else { | ||
@@ -31,6 +25,35 @@ options = {}; | ||
var self = this; | ||
this.type = options.type || ''; | ||
this.vals = options.vals ? options.vals.slice(0) : []; | ||
this._vals = []; | ||
var self = this; | ||
this.__defineGetter__('vals', function() { | ||
var _vals = []; | ||
self._vals.forEach(function(v) { | ||
if (/;binary$/.test(self.type)) { | ||
_vals.push(v.toString('base64')); | ||
} else { | ||
_vals.push(v.toString('utf8')); | ||
} | ||
}); | ||
return _vals; | ||
}); | ||
this.__defineSetter__('vals', function(vals) { | ||
if (Array.isArray(vals)) { | ||
vals.forEach(function(v) { | ||
self.addValue(v); | ||
}); | ||
} else { | ||
self.addValue(vals); | ||
} | ||
}); | ||
this.__defineGetter__('buffers', function() { | ||
return self._vals; | ||
}); | ||
this.__defineGetter__('json', function() { | ||
@@ -42,2 +65,6 @@ return { | ||
}); | ||
if (options.vals) | ||
this.vals = options.vals; | ||
} | ||
@@ -47,2 +74,14 @@ module.exports = Attribute; | ||
Attribute.prototype.addValue = function(val) { | ||
if (Buffer.isBuffer(val)) { | ||
this._vals.push(val); | ||
} else { | ||
var encoding = 'utf8'; | ||
if (/;binary$/.test(this.type)) | ||
encoding = 'base64'; | ||
this._vals.push(new Buffer(val + '', encoding)); | ||
} | ||
}; | ||
Attribute.compare = function(a, b) { | ||
@@ -65,10 +104,3 @@ if (!(a instanceof Attribute) || !(b instanceof Attribute)) | ||
Attribute.prototype.addValue = function(val) { | ||
if (typeof(val) !== 'string') | ||
throw new TypeError('val (string) required'); | ||
this.vals.push(val); | ||
}; | ||
Attribute.prototype.parse = function(ber) { | ||
@@ -78,3 +110,3 @@ assert.ok(ber); | ||
ber.readSequence(); | ||
this.type = ber.readString().toLowerCase(); | ||
this.type = ber.readString(); | ||
@@ -85,3 +117,3 @@ if (ber.peek() === Protocol.LBER_SET) { | ||
while (ber.offset < end) | ||
this.vals.push(ber.readString()); | ||
this._vals.push(ber.readString(asn1.Ber.OctetString, true)); | ||
} | ||
@@ -100,3 +132,12 @@ } | ||
ber.startSequence(Protocol.LBER_SET); | ||
ber.writeStringArray(this.vals && this.vals.length ? this.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(); | ||
@@ -120,3 +161,4 @@ ber.endSequence(); | ||
for (var i = 0; i < attr.vals.length; i++) | ||
if (typeof(attr.vals[i]) !== 'string') return false; | ||
if (typeof(attr.vals[i]) !== 'string' && !Buffer.isBuffer(attr.vals[i])) | ||
return false; | ||
@@ -123,0 +165,0 @@ return true; |
@@ -66,2 +66,3 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
a.parse(ber); | ||
a.type = a.type.toLowerCase(); | ||
if (a.type === 'objectclass') { | ||
@@ -131,3 +132,3 @@ for (var i = 0; i < a.vals.length; i++) | ||
if (!name || typeof(name) !== 'string') | ||
throw new TypeEroror('attribute name (string) required'); | ||
throw new TypeError('attribute name (string) required'); | ||
@@ -134,0 +135,0 @@ name = name.toLowerCase(); |
@@ -10,3 +10,2 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
var dn = require('../dn'); | ||
var Attribute = require('../attribute'); | ||
var Protocol = require('../protocol'); | ||
@@ -13,0 +12,0 @@ |
@@ -12,3 +12,2 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
var dn = require('../dn'); | ||
var Attribute = require('../attribute'); | ||
var Protocol = require('../protocol'); | ||
@@ -15,0 +14,0 @@ |
@@ -12,3 +12,2 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
var dn = require('../dn'); | ||
var Attribute = require('../attribute'); | ||
var Protocol = require('../protocol'); | ||
@@ -15,0 +14,0 @@ |
@@ -59,2 +59,3 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
c.parse(ber); | ||
c.modification.type = c.modification.type.toLowerCase(); | ||
this.changes.push(c); | ||
@@ -61,0 +62,0 @@ } |
@@ -90,16 +90,3 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
Object.keys(obj).forEach(function(k) { | ||
var attr = new Attribute({type: k, vals: []}); | ||
if (Array.isArray(obj[k])) { | ||
obj[k].forEach(function(v) { | ||
if (typeof(v) !== 'string') | ||
v = '' + v; | ||
attr.vals.push(v); | ||
}); | ||
} else { | ||
attr.vals.push(obj[k] + ''); | ||
} | ||
self.attributes.push(attr); | ||
self.attributes.push(new Attribute({type: k, vals: obj[k]})); | ||
}); | ||
@@ -106,0 +93,0 @@ |
@@ -63,9 +63,13 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
// wants to strip, or 'private' vars that are prefixed with '_' | ||
if (!nofiltering) { | ||
if (!nofiltering && | ||
self.attributes && | ||
self.attributes.length && | ||
self.attributes.indexOf('*') === -1) { | ||
Object.keys(entry.attributes).forEach(function(a) { | ||
if ((self.attributes.length && | ||
self.attributes.indexOf(a) === -1) || | ||
var _a = a.toLowerCase(); | ||
if (self.attributes.indexOf(_a) === -1 || | ||
(self.notAttributes.length && | ||
self.notAttributes.indexOf(a) !== -1) || | ||
(a.length && a.charAt(0) === '_')) { | ||
self.notAttributes.indexOf(_a) !== -1) || | ||
(_a.length && _a.charAt(0) === '_')) { | ||
delete entry.attributes[a]; | ||
@@ -75,2 +79,3 @@ } | ||
} | ||
entry = new SearchEntry({ | ||
@@ -77,0 +82,0 @@ objectName: typeof(save.dn) === 'string' ? parseDN(save.dn) : save.dn, |
@@ -6,3 +6,3 @@ { | ||
"description": "LDAP client and server APIs", | ||
"version": "0.1.9", | ||
"version": "0.2.0", | ||
"repository": { | ||
@@ -17,3 +17,3 @@ "type": "git", | ||
"dependencies": { | ||
"asn1": "~0.1.5", | ||
"asn1": "~0.1.6", | ||
"buffertools": "~1.0.3", | ||
@@ -20,0 +20,0 @@ "dtrace-provider": "~0.0.3", |
@@ -80,3 +80,14 @@ // Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
if (!req.dn.equals('cn=ref,' + SUFFIX)) { | ||
if (req.dn.equals('cn=ref,' + SUFFIX)) { | ||
res.send(res.createSearchReference('ldap://localhost')); | ||
} else if (req.dn.equals('cn=bin,' + SUFFIX)) { | ||
res.send(res.createSearchEntry({ | ||
objectName: req.dn, | ||
attributes: { | ||
'foo;binary': 'wr0gKyDCvCA9IMK+', | ||
'gb18030': new Buffer([0xB5, 0xE7, 0xCA, 0xD3, 0xBB, 0xFA]), | ||
'objectclass': 'binary' | ||
} | ||
})); | ||
} else { | ||
var e = res.createSearchEntry({ | ||
@@ -86,3 +97,3 @@ objectName: req.dn, | ||
cn: ['unit', 'test'], | ||
sn: 'testy' | ||
SN: 'testy' | ||
} | ||
@@ -92,6 +103,5 @@ }); | ||
res.send(e); | ||
} else { | ||
res.send(res.createSearchReference('ldap://localhost')); | ||
} | ||
res.end(); | ||
@@ -351,2 +361,4 @@ return next(); | ||
t.ok(entry.attributes.length); | ||
t.equal(entry.attributes[0].type, 'cn'); | ||
t.equal(entry.attributes[1].type, 'SN'); | ||
t.ok(entry.object); | ||
@@ -428,2 +440,110 @@ gotEntry++; | ||
test('GH-21 binary attributes', function(t) { | ||
client.search('cn=bin, ' + SUFFIX, '(objectclass=*)', function(err, res) { | ||
t.ifError(err); | ||
t.ok(res); | ||
var gotEntry = 0; | ||
var expect = new Buffer('\u00bd + \u00bc = \u00be', 'utf8'); | ||
var expect2 = new Buffer([0xB5, 0xE7, 0xCA, 0xD3, 0xBB, 0xFA]); | ||
res.on('searchEntry', function(entry) { | ||
t.ok(entry); | ||
t.ok(entry instanceof ldap.SearchEntry); | ||
t.equal(entry.dn.toString(), 'cn=bin, ' + SUFFIX); | ||
t.ok(entry.attributes); | ||
t.ok(entry.attributes.length); | ||
t.equal(entry.attributes[0].type, 'foo;binary'); | ||
t.equal(entry.attributes[0].vals[0], expect.toString('base64')); | ||
t.equal(entry.attributes[0].buffers[0].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); | ||
gotEntry++; | ||
}); | ||
res.on('error', function(err) { | ||
t.fail(err); | ||
}); | ||
res.on('end', function(res) { | ||
t.ok(res); | ||
t.ok(res instanceof ldap.SearchResponse); | ||
t.equal(res.status, 0); | ||
t.equal(gotEntry, 1); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
test('GH-23 case insensitive attribute filtering', function(t) { | ||
var opts = { | ||
filter: '(objectclass=*)', | ||
attributes: ['Cn'] | ||
}; | ||
client.search('cn=test, ' + SUFFIX, opts, function(err, res) { | ||
t.ifError(err); | ||
t.ok(res); | ||
var gotEntry = 0; | ||
res.on('searchEntry', function(entry) { | ||
t.ok(entry); | ||
t.ok(entry instanceof ldap.SearchEntry); | ||
t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX); | ||
t.ok(entry.attributes); | ||
t.ok(entry.attributes.length); | ||
t.equal(entry.attributes[0].type, 'cn'); | ||
t.ok(entry.object); | ||
gotEntry++; | ||
}); | ||
res.on('error', function(err) { | ||
t.fail(err); | ||
}); | ||
res.on('end', function(res) { | ||
t.ok(res); | ||
t.ok(res instanceof ldap.SearchResponse); | ||
t.equal(res.status, 0); | ||
t.equal(gotEntry, 2); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
test('GH-24 attribute selection of *', function(t) { | ||
var opts = { | ||
filter: '(objectclass=*)', | ||
attributes: ['*'] | ||
}; | ||
client.search('cn=test, ' + SUFFIX, opts, function(err, res) { | ||
t.ifError(err); | ||
t.ok(res); | ||
var gotEntry = 0; | ||
res.on('searchEntry', function(entry) { | ||
t.ok(entry); | ||
t.ok(entry instanceof ldap.SearchEntry); | ||
t.equal(entry.dn.toString(), 'cn=test, ' + SUFFIX); | ||
t.ok(entry.attributes); | ||
t.ok(entry.attributes.length); | ||
t.equal(entry.attributes[0].type, 'cn'); | ||
t.equal(entry.attributes[1].type, 'SN'); | ||
t.ok(entry.object); | ||
gotEntry++; | ||
}); | ||
res.on('error', function(err) { | ||
t.fail(err); | ||
}); | ||
res.on('end', function(res) { | ||
t.ok(res); | ||
t.ok(res instanceof ldap.SearchResponse); | ||
t.equal(res.status, 0); | ||
t.equal(gotEntry, 2); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
test('shutdown', function(t) { | ||
@@ -430,0 +550,0 @@ client.unbind(function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1623278
371
28094
2
80
16
18
Updatedasn1@~0.1.6