2011-08-26 15:29:57 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
|
|
|
var test = require('tap').test;
|
|
|
|
var uuid = require('node-uuid');
|
|
|
|
|
|
|
|
var ldap = require('../lib/index');
|
|
|
|
|
|
|
|
|
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var SOCKET = '/tmp/.' + uuid();
|
2012-01-19 23:39:16 +00:00
|
|
|
var SUFFIX = 'dc=' + uuid();
|
2011-08-26 15:29:57 +00:00
|
|
|
|
|
|
|
var client;
|
|
|
|
var server;
|
|
|
|
|
|
|
|
|
2012-01-19 23:39:16 +00:00
|
|
|
|
|
|
|
///--- Helper
|
|
|
|
|
|
|
|
function search(t, options, callback) {
|
2012-02-18 08:15:52 +00:00
|
|
|
client.search(SUFFIX, options, function (err, res) {
|
2012-01-19 23:39:16 +00:00
|
|
|
t.ifError(err);
|
|
|
|
t.ok(res);
|
|
|
|
var found = false;
|
2012-02-18 08:15:52 +00:00
|
|
|
res.on('searchEntry', function (entry) {
|
2012-01-19 23:39:16 +00:00
|
|
|
t.ok(entry);
|
|
|
|
found = true;
|
|
|
|
});
|
2012-02-18 08:15:52 +00:00
|
|
|
res.on('end', function () {
|
2012-01-19 23:39:16 +00:00
|
|
|
t.ok(found);
|
|
|
|
if (callback)
|
|
|
|
return callback();
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
return t.end();
|
2012-01-19 23:39:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-26 15:29:57 +00:00
|
|
|
///--- Tests
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('setup', function (t) {
|
2011-08-26 15:29:57 +00:00
|
|
|
server = ldap.createServer();
|
|
|
|
t.ok(server);
|
2012-02-18 08:15:52 +00:00
|
|
|
server.listen(SOCKET, function () {
|
2011-08-26 23:33:49 +00:00
|
|
|
client = ldap.createClient({
|
2011-08-26 15:29:57 +00:00
|
|
|
socketPath: SOCKET
|
|
|
|
});
|
|
|
|
t.ok(client);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
server.bind('cn=root', function (req, res, next) {
|
2012-01-30 16:45:01 +00:00
|
|
|
res.end();
|
|
|
|
return next();
|
|
|
|
});
|
2012-02-18 08:15:52 +00:00
|
|
|
server.search(SUFFIX, function (req, res, next) {
|
2012-01-19 23:39:16 +00:00
|
|
|
var entry = {
|
|
|
|
dn: 'cn=foo, ' + SUFFIX,
|
|
|
|
attributes: {
|
|
|
|
objectclass: ['person', 'top'],
|
|
|
|
cn: 'Pogo Stick',
|
|
|
|
sn: 'Stick',
|
|
|
|
givenname: 'ogo',
|
|
|
|
mail: uuid() + '@pogostick.org'
|
|
|
|
}
|
|
|
|
};
|
2012-01-20 02:02:10 +00:00
|
|
|
|
2011-08-26 15:29:57 +00:00
|
|
|
if (req.filter.matches(entry.attributes))
|
|
|
|
res.send(entry);
|
2012-01-19 23:39:16 +00:00
|
|
|
|
2011-08-26 15:29:57 +00:00
|
|
|
res.end();
|
|
|
|
});
|
2012-01-19 23:39:16 +00:00
|
|
|
});
|
2011-08-26 15:29:57 +00:00
|
|
|
|
2012-01-19 23:39:16 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('Evolution search filter (GH-3)', function (t) {
|
2011-08-26 15:29:57 +00:00
|
|
|
// This is what Evolution sends, when searching for a contact 'ogo'. Wow.
|
|
|
|
var filter =
|
|
|
|
'(|(cn=ogo*)(givenname=ogo*)(sn=ogo*)(mail=ogo*)(member=ogo*)' +
|
|
|
|
'(primaryphone=ogo*)(telephonenumber=ogo*)(homephone=ogo*)(mobile=ogo*)' +
|
|
|
|
'(carphone=ogo*)(facsimiletelephonenumber=ogo*)' +
|
|
|
|
'(homefacsimiletelephonenumber=ogo*)(otherphone=ogo*)' +
|
|
|
|
'(otherfacsimiletelephonenumber=ogo*)(internationalisdnnumber=ogo*)' +
|
|
|
|
'(pager=ogo*)(radio=ogo*)(telex=ogo*)(assistantphone=ogo*)' +
|
|
|
|
'(companyphone=ogo*)(callbackphone=ogo*)(tty=ogo*)(o=ogo*)(ou=ogo*)' +
|
|
|
|
'(roomnumber=ogo*)(title=ogo*)(businessrole=ogo*)(managername=ogo*)' +
|
|
|
|
'(assistantname=ogo*)(postaladdress=ogo*)(l=ogo*)(st=ogo*)' +
|
|
|
|
'(postofficebox=ogo*)(postalcode=ogo*)(c=ogo*)(homepostaladdress=ogo*)' +
|
|
|
|
'(mozillahomelocalityname=ogo*)(mozillahomestate=ogo*)' +
|
|
|
|
'(mozillahomepostalcode=ogo*)(mozillahomecountryname=ogo*)' +
|
|
|
|
'(otherpostaladdress=ogo*)(jpegphoto=ogo*)(usercertificate=ogo*)' +
|
|
|
|
'(labeleduri=ogo*)(displayname=ogo*)(spousename=ogo*)(note=ogo*)' +
|
|
|
|
'(anniversary=ogo*)(birthdate=ogo*)(mailer=ogo*)(fileas=ogo*)' +
|
|
|
|
'(category=ogo*)(calcaluri=ogo*)(calfburl=ogo*)(icscalendar=ogo*))';
|
|
|
|
|
2012-01-19 23:39:16 +00:00
|
|
|
return search(t, filter);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('GH-49 Client errors on bad attributes', function (t) {
|
2012-01-19 23:39:16 +00:00
|
|
|
var searchOpts = {
|
|
|
|
filter: 'cn=*ogo*',
|
|
|
|
scope: 'one',
|
|
|
|
attributes: 'dn'
|
|
|
|
};
|
|
|
|
return search(t, searchOpts);
|
2011-08-26 15:29:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('GH-55 Client emits connect multiple times', function (t) {
|
2012-01-30 16:45:01 +00:00
|
|
|
var c = ldap.createClient({
|
|
|
|
socketPath: SOCKET
|
|
|
|
});
|
|
|
|
|
|
|
|
var count = 0;
|
2012-02-18 08:15:52 +00:00
|
|
|
c.on('connect', function (socket) {
|
2012-01-30 16:45:01 +00:00
|
|
|
t.ok(socket);
|
|
|
|
count++;
|
2012-02-18 22:58:40 +00:00
|
|
|
c.bind('cn=root', 'secret', function (err, res) {
|
|
|
|
t.ifError(err);
|
|
|
|
c.unbind(function () {
|
|
|
|
t.equal(count, 1);
|
|
|
|
t.end();
|
|
|
|
});
|
2012-01-30 16:45:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('shutdown', function (t) {
|
|
|
|
client.unbind(function () {
|
|
|
|
server.on('close', function () {
|
2011-08-26 15:29:57 +00:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|