2019-08-27 21:11:49 +00:00
|
|
|
'use strict'
|
2011-08-26 15:29:57 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const tap = require('tap')
|
2020-07-22 15:11:48 +00:00
|
|
|
const { getSock, uuid } = require('./utils')
|
2019-08-27 21:11:49 +00:00
|
|
|
const ldap = require('../lib')
|
2012-01-19 23:39:16 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
function search (t, options, callback) {
|
2019-08-27 18:17:33 +00:00
|
|
|
t.context.client.search(t.context.suffix, options, function (err, res) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.error(err)
|
|
|
|
t.ok(res)
|
|
|
|
let found = false
|
2012-02-18 08:15:52 +00:00
|
|
|
res.on('searchEntry', function (entry) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(entry)
|
|
|
|
found = true
|
|
|
|
})
|
2012-02-18 08:15:52 +00:00
|
|
|
res.on('end', function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.true(found)
|
|
|
|
if (callback) return callback()
|
|
|
|
return t.end()
|
|
|
|
})
|
|
|
|
})
|
2012-01-19 23:39:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
tap.beforeEach((done, t) => {
|
2019-08-27 21:11:49 +00:00
|
|
|
const suffix = `dc=${uuid()}`
|
|
|
|
const server = ldap.createServer()
|
2012-01-19 23:39:16 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.context.server = server
|
|
|
|
t.context.socketPath = getSock()
|
|
|
|
t.context.suffix = suffix
|
2011-08-26 15:29:57 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
server.bind('cn=root', function (req, res, next) {
|
2019-08-27 21:11:49 +00:00
|
|
|
res.end()
|
|
|
|
return next()
|
|
|
|
})
|
2019-08-27 18:17:33 +00:00
|
|
|
|
2020-12-07 01:26:27 +00:00
|
|
|
server.search(suffix, function (req, res) {
|
2020-10-31 21:07:32 +00:00
|
|
|
const entry = {
|
2019-08-27 18:17:33 +00:00
|
|
|
dn: 'cn=foo, ' + suffix,
|
2012-01-19 23:39:16 +00:00
|
|
|
attributes: {
|
|
|
|
objectclass: ['person', 'top'],
|
|
|
|
cn: 'Pogo Stick',
|
|
|
|
sn: 'Stick',
|
|
|
|
givenname: 'ogo',
|
|
|
|
mail: uuid() + '@pogostick.org'
|
|
|
|
}
|
2019-08-27 21:11:49 +00:00
|
|
|
}
|
2012-01-20 02:02:10 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
if (req.filter.matches(entry.attributes)) { res.send(entry) }
|
2012-01-19 23:39:16 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
res.end()
|
|
|
|
})
|
2011-08-26 15:29:57 +00:00
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
server.listen(t.context.socketPath, function () {
|
|
|
|
t.context.client = ldap.createClient({
|
|
|
|
socketPath: t.context.socketPath
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2012-01-19 23:39:16 +00:00
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
t.context.client.on('connectError', (err) => {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.context.server.close(() => done(err))
|
2019-08-27 18:17:33 +00:00
|
|
|
})
|
|
|
|
t.context.client.on('connect', (socket) => {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.context.socket = socket
|
|
|
|
done()
|
2019-08-27 18:17:33 +00:00
|
|
|
})
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2019-08-27 18:17:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
tap.afterEach((done, t) => {
|
|
|
|
if (!t.context.client) return done()
|
|
|
|
t.context.client.unbind(() => {
|
|
|
|
t.context.server.close(done)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.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.
|
2019-08-27 18:17:33 +00:00
|
|
|
const filter =
|
2011-08-26 15:29:57 +00:00
|
|
|
'(|(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*)' +
|
2019-08-27 21:11:49 +00:00
|
|
|
'(category=ogo*)(calcaluri=ogo*)(calfburl=ogo*)(icscalendar=ogo*))'
|
2011-08-26 15:29:57 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
return search(t, filter)
|
|
|
|
})
|
2012-01-19 23:39:16 +00:00
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
tap.test('GH-49 Client errors on bad attributes', function (t) {
|
|
|
|
const searchOpts = {
|
2012-01-19 23:39:16 +00:00
|
|
|
filter: 'cn=*ogo*',
|
|
|
|
scope: 'one',
|
|
|
|
attributes: 'dn'
|
2019-08-27 21:11:49 +00:00
|
|
|
}
|
|
|
|
return search(t, searchOpts)
|
|
|
|
})
|
2011-08-26 15:29:57 +00:00
|
|
|
|
2019-08-27 18:17:33 +00:00
|
|
|
tap.test('GH-55 Client emits connect multiple times', function (t) {
|
|
|
|
const c = ldap.createClient({
|
|
|
|
socketPath: t.context.socketPath
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2012-01-30 16:45:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
let count = 0
|
2012-02-18 08:15:52 +00:00
|
|
|
c.on('connect', function (socket) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(socket)
|
|
|
|
count++
|
2019-08-27 18:17:33 +00:00
|
|
|
c.bind('cn=root', 'secret', function (err) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ifError(err)
|
2012-02-18 22:58:40 +00:00
|
|
|
c.unbind(function () {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.equal(count, 1)
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|