2019-08-27 21:11:49 +00:00
|
|
|
'use strict'
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const { test } = require('tap')
|
|
|
|
const { BerReader, BerWriter } = require('asn1')
|
|
|
|
const { SearchRequest, EqualityFilter, dn } = require('../../lib')
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new no args', function (t) {
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(new SearchRequest())
|
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('new with args', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new SearchRequest({
|
2011-08-04 20:32:01 +00:00
|
|
|
baseObject: dn.parse('cn=foo, o=test'),
|
|
|
|
filter: new EqualityFilter({
|
|
|
|
attribute: 'email',
|
|
|
|
value: 'foo@bar.com'
|
|
|
|
}),
|
|
|
|
attributes: ['cn', 'sn']
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
|
|
|
t.ok(req)
|
|
|
|
t.equal(req.dn.toString(), 'cn=foo, o=test')
|
|
|
|
t.equal(req.filter.toString(), '(email=foo@bar.com)')
|
|
|
|
t.equal(req.attributes.length, 2)
|
|
|
|
t.equal(req.attributes[0], 'cn')
|
|
|
|
t.equal(req.attributes[1], 'sn')
|
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const f = new EqualityFilter({
|
2011-08-04 20:32:01 +00:00
|
|
|
attribute: 'email',
|
|
|
|
value: 'foo@bar.com'
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
let ber = new BerWriter()
|
|
|
|
ber.writeString('cn=foo, o=test')
|
|
|
|
ber.writeEnumeration(0)
|
|
|
|
ber.writeEnumeration(0)
|
|
|
|
ber.writeInt(1)
|
|
|
|
ber.writeInt(2)
|
|
|
|
ber.writeBoolean(false)
|
|
|
|
ber = f.toBer(ber)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const req = new SearchRequest()
|
|
|
|
t.ok(req._parse(new BerReader(ber.buffer)))
|
|
|
|
t.equal(req.dn.toString(), 'cn=foo, o=test')
|
|
|
|
t.equal(req.scope, 'base')
|
|
|
|
t.equal(req.derefAliases, 0)
|
|
|
|
t.equal(req.sizeLimit, 1)
|
|
|
|
t.equal(req.timeLimit, 2)
|
|
|
|
t.equal(req.typesOnly, false)
|
|
|
|
t.equal(req.filter.toString(), '(email=foo@bar.com)')
|
|
|
|
t.equal(req.attributes.length, 0)
|
|
|
|
t.end()
|
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('toBer', function (t) {
|
2019-08-27 18:17:33 +00:00
|
|
|
const req = new SearchRequest({
|
2011-08-04 20:32:01 +00:00
|
|
|
messageID: 123,
|
|
|
|
baseObject: dn.parse('cn=foo, o=test'),
|
|
|
|
scope: 1,
|
|
|
|
derefAliases: 2,
|
|
|
|
sizeLimit: 10,
|
|
|
|
timeLimit: 20,
|
|
|
|
typesOnly: true,
|
|
|
|
filter: new EqualityFilter({
|
|
|
|
attribute: 'email',
|
|
|
|
value: 'foo@bar.com'
|
|
|
|
}),
|
|
|
|
attributes: ['cn', 'sn']
|
2019-08-27 21:11:49 +00:00
|
|
|
})
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.ok(req)
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
const ber = new BerReader(req.toBer())
|
|
|
|
t.ok(ber)
|
|
|
|
t.equal(ber.readSequence(), 0x30)
|
|
|
|
t.equal(ber.readInt(), 123)
|
|
|
|
t.equal(ber.readSequence(), 0x63)
|
2020-05-13 15:01:00 +00:00
|
|
|
// Make sure we've removed spaces from between RDNs:
|
|
|
|
t.equal(ber.readString(), 'cn=foo,o=test')
|
2019-08-27 21:11:49 +00:00
|
|
|
t.equal(ber.readEnumeration(), 1)
|
|
|
|
t.equal(ber.readEnumeration(), 2)
|
|
|
|
t.equal(ber.readInt(), 10)
|
|
|
|
t.equal(ber.readInt(), 20)
|
|
|
|
t.ok(ber.readBoolean())
|
|
|
|
t.equal(ber.readSequence(), 0xa3)
|
|
|
|
t.equal(ber.readString(), 'email')
|
|
|
|
t.equal(ber.readString(), 'foo@bar.com')
|
|
|
|
t.ok(ber.readSequence())
|
|
|
|
t.equal(ber.readString(), 'cn')
|
|
|
|
t.equal(ber.readString(), 'sn')
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2019-08-27 21:11:49 +00:00
|
|
|
t.end()
|
|
|
|
})
|