modifyDN touchups

This commit is contained in:
Mark Cavage 2011-08-15 13:50:15 -07:00
parent 17d2d4e5cb
commit c8ea58fc60
4 changed files with 50 additions and 12 deletions

View File

@ -1,4 +1,44 @@
Docs coming soon.
ldapjs makes the LDAP protocol a first class citizen in node.js.
## Usage
For full docs, head on over to <http://ldapjs.org>.
var ldap = require('ldapjs');
var server = ldap.createServer();
server.bind('cn=root', function(req, res, next) {
if (req.credentials !== 'secret')
return next(new ldap.InvalidCredentialsError());
res.end();
});
server.search('dc=example', function(req, res, next) {
var obj = {
dn: req.dn.toString(),
attributes: {
objectclass: 'helloworld',
cn: 'hello',
sn: 'world'
}
};
if (req.filter.matches(obj))
res.send(obj);
res.end();
});
server.listen(1389, function() {
console.log('ldapjs listening at ' + server.url);
});
To run that, assuming you've got the [OpenLDAP](http://www.openldap.org/) client on
your system:
$ ldapsearch -H ldap://localhost:1389 -x -D cn=root -w secret -b dc=example objectclass=*
## Installation

View File

@ -52,7 +52,7 @@ Then there's a few things to note:
name_, or _dn_ for short. A dn is comprised of attributes that lead to that
node in the tree, as shown above (the syntax is foo=bar, ...).
* The root of the tree is at the right of the _dn_, which is inverted from a
filesystem hierarchy, if that wasn't already obvious.
filesystem hierarchy.
* Every entry in the tree is an _instance of_ an _objectclass_.
* An _objectclass_ is a schema concept; think of it like a table in a
traditional ORM.
@ -501,16 +501,16 @@ Here's a few new things:
extend this little project with groups? We probably want those under a
different part of the tree.
* We did some really minimal schema enforcement by:
** Checking that the leaf RDN (relative distinguished name) was a _cn_
+ Checking that the leaf RDN (relative distinguished name) was a _cn_
attribute.
** We then did `req.toObject()`. As mentioned before, each of the req/res
+ We then did `req.toObject()`. As mentioned before, each of the req/res
objects have special APIs that make sense for that operation. Without getting
into the details, the LDAP add operation on the wire doesn't look like a JS
object, and we want to support both the LDAP nerd that wants to see what
got sent, and the "easy" case. So use `.toObject()`. Note we also filtered
out to the `attributes` portion of the object since that's all we're really
looking at.
** Lastly, we did a super minimal check to see if the entry was of type
+ Lastly, we did a super minimal check to see if the entry was of type
`unixUser`. Frankly for this case, it's kind of useless, but it does illustrate
one point: attribute names are case-insensitive, so ldapjs converts them all to
lower case (note the client sent _objectClass_ over the wire).

View File

@ -49,9 +49,7 @@ function ModifyDNRequest(options) {
var self = this;
this.__defineGetter__('type', function() { return 'ModifyDNRequest'; });
this.__defineGetter__('_dn', function() {
return self.entry ? self.entry.toString() : '';
});
this.__defineGetter__('_dn', function() { return self.entry; });
}
util.inherits(ModifyDNRequest, LDAPMessage);
module.exports = ModifyDNRequest;
@ -63,8 +61,8 @@ ModifyDNRequest.prototype._parse = function(ber) {
this.entry = dn.parse(ber.readString());
this.newRdn = dn.parse(ber.readString());
this.deleteOldRdn = ber.readBoolean();
if (ber.peek() === Ber.OctetString)
this.newSuperior = ber.readString();
if (ber.peek() === 0x80)
this.newSuperior = dn.parse(ber.readString(0x80));
return true;
};

View File

@ -36,7 +36,7 @@ test('new with args', function(t) {
deleteOldRdn: true
});
t.ok(req);
t.equal(req.dn, 'cn=foo, o=test');
t.equal(req.dn.toString(), 'cn=foo, o=test');
t.equal(req.newRdn.toString(), 'cn=foo2');
t.equal(req.deleteOldRdn, true);
t.end();
@ -51,7 +51,7 @@ test('parse', function(t) {
var req = new ModifyDNRequest();
t.ok(req._parse(new BerReader(ber.buffer)));
t.equal(req.dn, 'cn=foo, o=test');
t.equal(req.dn.toString(), 'cn=foo, o=test');
t.equal(req.newRdn.toString(), 'cn=foo2');
t.equal(req.deleteOldRdn, true);