Refactor tests to be independent of each other

This commit is contained in:
James Sumners 2019-08-27 14:17:33 -04:00
parent b13e50aa4b
commit 6b514b97df
No known key found for this signature in database
GPG Key ID: DD9AAE30F864776B
54 changed files with 983 additions and 1996 deletions

View File

@ -71,7 +71,7 @@ Attribute.prototype.addValue = function addValue(val) {
if (Buffer.isBuffer(val)) {
this._vals.push(val);
} else {
this._vals.push(new Buffer(val + '', _bufferEncoding(this.type)));
this._vals.push(Buffer.from(val + '', _bufferEncoding(this.type)));
}
};

View File

@ -1,8 +1,7 @@
// Copyright 2012 Mark Cavage, Inc. All rights reserved.
var logger = Object.create(require('abstract-logging'));
var Client = require('./client');
const logger = require('../logger');
const Client = require('./client');

View File

@ -48,7 +48,7 @@ PagedResultsControl.prototype.parse = function parse(buffer) {
this._value.cookie = ber.readString(asn1.Ber.OctetString, true);
//readString returns '' instead of a zero-length buffer
if (!this._value.cookie)
this._value.cookie = new Buffer(0);
this._value.cookie = Buffer.alloc(0);
return true;
}

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var logger = Object.create(require('abstract-logging'));
var logger = require('./logger');
var client = require('./client');
var Attribute = require('./attribute');

6
lib/logger.js Normal file
View File

@ -0,0 +1,6 @@
'use strict';
const logger = Object.create(require('abstract-logging'))
logger.child = function () { return logger }
module.exports = logger

View File

@ -44,7 +44,7 @@ DeleteRequest.prototype._parse = function (ber, length) {
DeleteRequest.prototype._toBer = function (ber) {
assert.ok(ber);
var buf = new Buffer(this.entry.toString());
var buf = Buffer.from(this.entry.toString());
for (var i = 0; i < buf.length; i++)
ber.writeByte(buf[i]);

View File

@ -28,7 +28,7 @@ function ExtendedRequest(options) {
if(Buffer.isBuffer(this.requestValue)) {
this.requestValueBuffer = this.requestValue;
} else {
this.requestValueBuffer = new Buffer(this.requestValue || '', 'utf8');
this.requestValueBuffer = Buffer.from(this.requestValue || '', 'utf8');
}
}
util.inherits(ExtendedRequest, LDAPMessage);
@ -58,7 +58,7 @@ Object.defineProperties(ExtendedRequest.prototype, {
if(Buffer.isBuffer(val)) {
this.requestValueBuffer = val;
} else {
this.requestValueBuffer = new Buffer(val, 'utf8');
this.requestValueBuffer = Buffer.from(val, 'utf8');
}
this.requestValue = val;

View File

@ -5,6 +5,7 @@ var util = require('util');
var asn1 = require('asn1');
var logger = require('../logger')
var Control = require('../controls').Control;
var Protocol = require('../protocol');
@ -32,7 +33,7 @@ function LDAPMessage(options) {
this.protocolOp = options.protocolOp || undefined;
this.controls = options.controls ? options.controls.slice(0) : [];
this.log = options.log;
this.log = options.log || logger;
}
Object.defineProperties(LDAPMessage.prototype, {
id: {

View File

@ -6,6 +6,7 @@ var util = require('util');
var assert = require('assert-plus');
var asn1 = require('asn1');
var VError = require('verror').VError;
var logger = require('../logger')
var AbandonRequest = require('./abandon_request');
var AddRequest = require('./add_request');
@ -43,14 +44,13 @@ var BerReader = asn1.BerReader;
///--- API
function Parser(options) {
function Parser(options = {}) {
assert.object(options);
assert.object(options.log);
EventEmitter.call(this);
this.buffer = null;
this.log = options.log;
this.log = options.log || logger;
}
util.inherits(Parser, EventEmitter);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var Attribute;
///--- Tests
test('load library', function (t) {
Attribute = require('../lib/index').Attribute;
t.ok(Attribute);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { Attribute } = require('../lib');
test('new no args', function (t) {
t.ok(new Attribute());
t.end();
});
test('new with args', function (t) {
var attr = new Attribute({
const attr = new Attribute({
type: 'cn',
vals: ['foo', 'bar']
});
@ -43,7 +25,7 @@ test('new with args', function (t) {
attr = new Attribute('not an object');
});
t.throws(function () {
var typeThatIsNotAString = 1;
const typeThatIsNotAString = 1;
attr = new Attribute({
type: typeThatIsNotAString
});
@ -51,16 +33,15 @@ test('new with args', function (t) {
t.end();
});
test('toBer', function (t) {
var attr = new Attribute({
const attr = new Attribute({
type: 'cn',
vals: ['foo', 'bar']
});
t.ok(attr);
var ber = new BerWriter();
const ber = new BerWriter();
attr.toBer(ber);
var reader = new BerReader(ber.buffer);
const reader = new BerReader(ber.buffer);
t.ok(reader.readSequence());
t.equal(reader.readString(), 'cn');
t.equal(reader.readSequence(), 0x31); // lber set
@ -69,9 +50,8 @@ test('toBer', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.startSequence();
ber.writeString('cn');
ber.startSequence(0x31);
@ -79,7 +59,7 @@ test('parse', function (t) {
ber.endSequence();
ber.endSequence();
var attr = new Attribute();
const attr = new Attribute();
t.ok(attr);
t.ok(attr.parse(new BerReader(ber.buffer)));
@ -91,12 +71,12 @@ test('parse', function (t) {
});
test('parse - without 0x31', function (t) {
var ber = new BerWriter;
const ber = new BerWriter;
ber.startSequence();
ber.writeString('sn');
ber.endSequence();
var attr = new Attribute;
const attr = new Attribute;
t.ok(attr);
t.ok(attr.parse(new BerReader(ber.buffer)));
@ -107,18 +87,18 @@ test('parse - without 0x31', function (t) {
});
test('toString', function (t) {
var attr = new Attribute({
const attr = new Attribute({
type: 'foobar',
vals: ['asdf']
});
var expected = attr.toString();
var actual = JSON.stringify(attr.json);
const expected = attr.toString();
const actual = JSON.stringify(attr.json);
t.equal(actual, expected);
t.end();
});
test('isAttribute', function (t) {
var isA = Attribute.isAttribute;
const isA = Attribute.isAttribute;
t.notOk(isA(null));
t.notOk(isA('asdf'));
t.ok(isA(new Attribute({
@ -128,7 +108,7 @@ test('isAttribute', function (t) {
t.ok(isA({
type: 'foo',
vals: ['item', new Buffer(5)],
vals: ['item', Buffer.alloc(5)],
toBer: function () { /* placeholder */ }
}));
@ -142,18 +122,17 @@ test('isAttribute', function (t) {
t.end();
});
test('compare', function (t) {
var comp = Attribute.compare;
var a = new Attribute({
const comp = Attribute.compare;
const a = new Attribute({
type: 'foo',
vals: ['bar']
});
var b = new Attribute({
const b = new Attribute({
type: 'foo',
vals: ['bar']
});
var notAnAttribute = 'this is not an attribute';
const notAnAttribute = 'this is not an attribute';
t.throws(function () {
comp(a, notAnAttribute);

View File

@ -1,37 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var Attribute;
var Change;
///--- Tests
test('load library', function (t) {
Attribute = require('../lib/index').Attribute;
Change = require('../lib/index').Change;
t.ok(Attribute);
t.ok(Change);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { Attribute, Change } = require('../lib');
test('new no args', function (t) {
t.ok(new Change());
t.end();
});
test('new with args', function (t) {
var change = new Change({
const change = new Change({
operation: 'add',
modification: new Attribute({
type: 'cn',
@ -49,9 +28,8 @@ test('new with args', function (t) {
t.end();
});
test('validate fields', function (t) {
var c = new Change();
const c = new Change();
t.ok(c);
t.throws(function () {
c.operation = 'bogus';
@ -66,10 +44,9 @@ test('validate fields', function (t) {
t.end();
});
test('GH-31 (multiple attributes per Change)', function (t) {
t.throws(function () {
var c = new Change({
const c = new Change({
operation: 'replace',
modification: {
cn: 'foo',
@ -81,9 +58,8 @@ test('GH-31 (multiple attributes per Change)', function (t) {
t.end();
});
test('toBer', function (t) {
var change = new Change({
const change = new Change({
operation: 'Add',
modification: new Attribute({
type: 'cn',
@ -92,9 +68,9 @@ test('toBer', function (t) {
});
t.ok(change);
var ber = new BerWriter();
const ber = new BerWriter();
change.toBer(ber);
var reader = new BerReader(ber.buffer);
const reader = new BerReader(ber.buffer);
t.ok(reader.readSequence());
t.equal(reader.readEnumeration(), 0x00);
t.ok(reader.readSequence());
@ -105,9 +81,8 @@ test('toBer', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.startSequence();
ber.writeEnumeration(0x00);
ber.startSequence();
@ -118,7 +93,7 @@ test('parse', function (t) {
ber.endSequence();
ber.endSequence();
var change = new Change();
const change = new Change();
t.ok(change);
t.ok(change.parse(new BerReader(ber.buffer)));
@ -131,24 +106,23 @@ test('parse', function (t) {
t.end();
});
test('apply - replace', function (t) {
var res;
var single = new Change({
let res;
const single = new Change({
operation: 'replace',
modification: {
type: 'cn',
vals: ['new']
}
});
var twin = new Change({
const twin = new Change({
operation: 'replace',
modification: {
type: 'cn',
vals: ['new', 'two']
}
});
var empty = new Change({
const empty = new Change({
operation: 'replace',
modification: {
type: 'cn',
@ -184,10 +158,9 @@ test('apply - replace', function (t) {
t.end();
});
test('apply - add', function (t) {
var res;
var single = new Change({
let res;
const single = new Change({
operation: 'add',
modification: {
type: 'cn',
@ -222,10 +195,9 @@ test('apply - add', function (t) {
t.end();
});
test('apply - delete', function (t) {
var res;
var single = new Change({
let res;
const single = new Change({
operation: 'delete',
modification: {
type: 'cn',

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var Control;
var getControl;
///--- Tests
test('load library', function (t) {
Control = require('../../lib/index').Control;
t.ok(Control);
getControl = require('../../lib/index').getControl;
t.ok(getControl);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { Control, getControl } = require('../../lib');
test('new no args', function (t) {
t.ok(new Control());
t.end();
});
test('new with args', function (t) {
var c = new Control({
const c = new Control({
type: '2.16.840.1.113730.3.4.2',
criticality: true
});
@ -41,16 +20,15 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.startSequence();
ber.writeString('2.16.840.1.113730.3.4.2');
ber.writeBoolean(true);
ber.writeString('foo');
ber.endSequence();
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '2.16.840.1.113730.3.4.2');
@ -59,14 +37,13 @@ test('parse', function (t) {
t.end();
});
test('parse no value', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.startSequence();
ber.writeString('2.16.840.1.113730.3.4.2');
ber.endSequence();
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '2.16.840.1.113730.3.4.2');

View File

@ -1,36 +1,16 @@
'use strict';
var test = require('tap').test;
var asn1 = require('asn1');
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var getControl;
var EntryChangeNotificationControl;
///--- Tests
test('load library', function (t) {
EntryChangeNotificationControl =
require('../../lib').EntryChangeNotificationControl;
t.ok(EntryChangeNotificationControl);
getControl = require('../../lib').getControl;
t.ok(getControl);
t.end();
});
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { getControl, EntryChangeNotificationControl } = require('../../lib');
test('new no args', function (t) {
t.ok(new EntryChangeNotificationControl());
t.end();
});
test('new with args', function (t) {
var c = new EntryChangeNotificationControl({
const c = new EntryChangeNotificationControl({
type: '2.16.840.1.113730.3.4.7',
criticality: true,
value: {
@ -46,13 +26,11 @@ test('new with args', function (t) {
t.equal(c.value.previousDN, 'cn=foobarbazcar');
t.equal(c.value.changeNumber, 123456789);
var writer = new BerWriter();
const writer = new BerWriter();
c.toBer(writer);
var reader = new BerReader(writer.buffer);
var psc = getControl(reader);
const reader = new BerReader(writer.buffer);
const psc = getControl(reader);
t.ok(psc);
console.log('psc', psc.value);
t.equal(psc.type, '2.16.840.1.113730.3.4.7');
t.ok(psc.criticality);
t.equal(psc.value.changeType, 8);
@ -63,7 +41,7 @@ test('new with args', function (t) {
});
test('tober', function (t) {
var psc = new EntryChangeNotificationControl({
const psc = new EntryChangeNotificationControl({
type: '2.16.840.1.113730.3.4.7',
criticality: true,
value: {
@ -73,10 +51,10 @@ test('tober', function (t) {
}
});
var ber = new BerWriter();
const ber = new BerWriter();
psc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '2.16.840.1.113730.3.4.7');
t.ok(c.criticality);

View File

@ -1,86 +1,61 @@
'use strict';
var test = require('tap').test;
var asn1 = require('asn1');
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var getControl;
var PagedResultsControl;
function bufferEqual(t, a, b) {
t.equal(a.toString('hex'), b.toString('hex'));
}
///--- Tests
test('load library', function (t) {
PagedResultsControl =
require('../../lib').PagedResultsControl;
t.ok(PagedResultsControl);
getControl = require('../../lib').getControl;
t.ok(getControl);
t.end();
});
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { getControl, PagedResultsControl } = require('../../lib');
test('new no args', function (t) {
t.ok(new PagedResultsControl());
t.end();
});
test('new with args', function (t) {
var c = new PagedResultsControl({
const c = new PagedResultsControl({
type: '1.2.840.113556.1.4.319',
criticality: true,
value: {
size: 1000,
cookie: new Buffer([1, 2, 3])
cookie: Buffer.from([1, 2, 3])
}
});
t.ok(c);
t.equal(c.type, '1.2.840.113556.1.4.319');
t.ok(c.criticality);
t.equal(c.value.size, 1000);
bufferEqual(t, c.value.cookie, new Buffer([1, 2, 3]));
t.is(Buffer.compare(c.value.cookie, Buffer.from([1, 2, 3])), 0)
var writer = new BerWriter();
const writer = new BerWriter();
c.toBer(writer);
var reader = new BerReader(writer.buffer);
var psc = getControl(reader);
const reader = new BerReader(writer.buffer);
const psc = getControl(reader);
t.ok(psc);
console.log('psc', psc.value);
t.equal(psc.type, '1.2.840.113556.1.4.319');
t.ok(psc.criticality);
t.equal(psc.value.size, 1000);
bufferEqual(t, psc.value.cookie, new Buffer([1, 2, 3]));
t.is(Buffer.compare(psc.value.cookie, Buffer.from([1, 2, 3])), 0)
t.end();
});
test('tober', function (t) {
var psc = new PagedResultsControl({
const psc = new PagedResultsControl({
type: '1.2.840.113556.1.4.319',
criticality: true,
value: {
size: 20,
cookie: new Buffer(0)
cookie: Buffer.alloc(0)
}
});
var ber = new BerWriter();
const ber = new BerWriter();
psc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '1.2.840.113556.1.4.319');
t.ok(c.criticality);
t.equal(c.value.size, 20);
bufferEqual(t, c.value.cookie, new Buffer(0));
t.is(Buffer.compare(c.value.cookie, Buffer.alloc(0)), 0)
t.end();
});

View File

@ -62,7 +62,7 @@ test('new with args', function (t) {
});
test('getControl with args', function (t) {
var buf = new Buffer([
var buf = Buffer.from([
0x30, 0x26, 0x04, 0x17, 0x32, 0x2e, 0x31, 0x36, 0x2e, 0x38, 0x34, 0x30,
0x2e, 0x31, 0x2e, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2e, 0x33, 0x2e,
0x34, 0x2e, 0x33, 0x04, 0x0b, 0x30, 0x09, 0x02, 0x01, 0x0f, 0x01, 0x01,

View File

@ -1,23 +1,8 @@
'use strict';
var test = require('tap').test;
var asn1 = require('asn1');
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var getControl;
var SSSRControl;
///--- Tests
test('load library', function (t) {
SSSRControl = require('../../lib').ServerSideSortingRequestControl;
t.ok(SSSRControl);
getControl = require('../../lib').getControl;
t.ok(getControl);
t.end();
});
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { getControl, ServerSideSortingRequestControl: SSSRControl } = require('../../lib');
test('new no args', function (t) {
t.ok(new SSSRControl());
@ -25,7 +10,7 @@ test('new no args', function (t) {
});
test('new with args', function (t) {
var c = new SSSRControl({
const c = new SSSRControl({
criticality: true,
value: {
attributeType: 'sn'
@ -41,7 +26,7 @@ test('new with args', function (t) {
});
test('toBer - object', function (t) {
var sssc = new SSSRControl({
const sssc = new SSSRControl({
criticality: true,
value: {
attributeType: 'sn',
@ -49,10 +34,10 @@ test('toBer - object', function (t) {
reverseOrder: true
}});
var ber = new BerWriter();
const ber = new BerWriter();
sssc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '1.2.840.113556.1.4.473');
t.ok(c.criticality);
@ -64,7 +49,7 @@ test('toBer - object', function (t) {
});
test('toBer - array', function (t) {
var sssc = new SSSRControl({
const sssc = new SSSRControl({
criticality: true,
value: [
{
@ -79,10 +64,10 @@ test('toBer - array', function (t) {
]
});
var ber = new BerWriter();
const ber = new BerWriter();
sssc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '1.2.840.113556.1.4.473');
t.ok(c.criticality);
@ -97,11 +82,11 @@ test('toBer - array', function (t) {
});
test('toBer - empty', function (t) {
var sssc = new SSSRControl();
var ber = new BerWriter();
const sssc = new SSSRControl();
const ber = new BerWriter();
sssc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '1.2.840.113556.1.4.473');
t.equal(c.value.length, 0);

View File

@ -1,28 +1,13 @@
var test = require('tap').test;
'use strict';
var asn1 = require('asn1');
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var ldap;
var getControl;
var SSSResponseControl;
var OID = '1.2.840.113556.1.4.474';
///--- Tests
test('load library', function (t) {
ldap = require('../../lib');
SSSResponseControl = ldap.ServerSideSortingResponseControl;
t.ok(SSSResponseControl);
getControl = ldap.getControl;
t.ok(getControl);
t.end();
});
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const ldap = require('../../lib');
const { getControl, ServerSideSortingResponseControl: SSSResponseControl } = ldap
const OID = '1.2.840.113556.1.4.474';
test('new no args', function (t) {
var c = new SSSResponseControl();
const c = new SSSResponseControl();
t.ok(c);
t.equal(c.type, OID);
t.equal(c.criticality, false);
@ -30,7 +15,7 @@ test('new no args', function (t) {
});
test('new with args', function (t) {
var c = new SSSResponseControl({
const c = new SSSResponseControl({
criticality: true,
value: {
result: ldap.LDAP_SUCCESS,
@ -47,16 +32,16 @@ test('new with args', function (t) {
});
test('toBer - success', function (t) {
var sssc = new SSSResponseControl({
const sssc = new SSSResponseControl({
value: {
result: ldap.LDAP_SUCCESS,
failedAttribute: 'foobar'
}});
var ber = new BerWriter();
const ber = new BerWriter();
sssc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, '1.2.840.113556.1.4.474');
t.equal(c.criticality, false);
@ -66,15 +51,15 @@ test('toBer - success', function (t) {
});
test('toBer - simple failure', function (t) {
var sssc = new SSSResponseControl({
const sssc = new SSSResponseControl({
value: {
result: ldap.LDAP_NO_SUCH_ATTRIBUTE
}});
var ber = new BerWriter();
const ber = new BerWriter();
sssc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, OID);
t.equal(c.criticality, false);
@ -84,16 +69,16 @@ test('toBer - simple failure', function (t) {
});
test('toBer - detailed failure', function (t) {
var sssc = new SSSResponseControl({
const sssc = new SSSResponseControl({
value: {
result: ldap.LDAP_NO_SUCH_ATTRIBUTE,
failedAttribute: 'foobar'
}});
var ber = new BerWriter();
const ber = new BerWriter();
sssc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, OID);
t.equal(c.criticality, false);
@ -103,11 +88,11 @@ test('toBer - detailed failure', function (t) {
});
test('toBer - empty', function (t) {
var sssc = new SSSResponseControl();
var ber = new BerWriter();
const sssc = new SSSResponseControl();
const ber = new BerWriter();
sssc.toBer(ber);
var c = getControl(new BerReader(ber.buffer));
const c = getControl(new BerReader(ber.buffer));
t.ok(c);
t.equal(c.type, OID);
t.equal(c.criticality, false);

View File

@ -1,25 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
///--- Globals
var dn;
///--- Tests
test('load library', function (t) {
dn = require('../lib/index').dn;
t.ok(dn);
t.end();
});
'use strict';
const { test } = require('tap');
const { dn } = require('../lib');
test('parse basic', function (t) {
var DN_STR = 'cn=mark, ou=people, o=joyent';
var name = dn.parse(DN_STR);
const DN_STR = 'cn=mark, ou=people, o=joyent';
const name = dn.parse(DN_STR);
t.ok(name);
t.ok(name.rdns);
t.ok(Array.isArray(name.rdns));
@ -31,10 +17,9 @@ test('parse basic', function (t) {
t.end();
});
test('parse escaped', function (t) {
var DN_STR = 'cn=m\\,ark, ou=people, o=joyent';
var name = dn.parse(DN_STR);
const DN_STR = 'cn=m\\,ark, ou=people, o=joyent';
const name = dn.parse(DN_STR);
t.ok(name);
t.ok(name.rdns);
t.ok(Array.isArray(name.rdns));
@ -46,10 +31,9 @@ test('parse escaped', function (t) {
t.end();
});
test('parse compound', function (t) {
var DN_STR = 'cn=mark+sn=cavage, ou=people, o=joyent';
var name = dn.parse(DN_STR);
const DN_STR = 'cn=mark+sn=cavage, ou=people, o=joyent';
const name = dn.parse(DN_STR);
t.ok(name);
t.ok(name.rdns);
t.ok(Array.isArray(name.rdns));
@ -61,11 +45,10 @@ test('parse compound', function (t) {
t.end();
});
test('parse quoted', function (t) {
var DN_STR = 'cn="mark+sn=cavage", ou=people, o=joyent';
var ESCAPE_STR = 'cn=mark\\+sn\\=cavage, ou=people, o=joyent';
var name = dn.parse(DN_STR);
const DN_STR = 'cn="mark+sn=cavage", ou=people, o=joyent';
const ESCAPE_STR = 'cn=mark\\+sn\\=cavage, ou=people, o=joyent';
const name = dn.parse(DN_STR);
t.ok(name);
t.ok(name.rdns);
t.ok(Array.isArray(name.rdns));
@ -77,9 +60,8 @@ test('parse quoted', function (t) {
t.end();
});
test('equals', function (t) {
var dn1 = dn.parse('cn=foo,dc=bar');
const dn1 = dn.parse('cn=foo,dc=bar');
t.ok(dn1.equals('cn=foo,dc=bar'));
t.ok(!dn1.equals('cn=foo1,dc=bar'));
t.ok(dn1.equals(dn.parse('cn=foo,dc=bar')));
@ -87,9 +69,8 @@ test('equals', function (t) {
t.end();
});
test('child of', function (t) {
var dn1 = dn.parse('cn=foo,dc=bar');
const dn1 = dn.parse('cn=foo,dc=bar');
t.ok(dn1.childOf('dc=bar'));
t.ok(!dn1.childOf('dc=moo'));
t.ok(!dn1.childOf('dc=foo'));
@ -99,9 +80,8 @@ test('child of', function (t) {
t.end();
});
test('parent of', function (t) {
var dn1 = dn.parse('cn=foo,dc=bar');
const dn1 = dn.parse('cn=foo,dc=bar');
t.ok(dn1.parentOf('cn=moo,cn=foo,dc=bar'));
t.ok(!dn1.parentOf('cn=moo,cn=bar,dc=foo'));
t.ok(!dn1.parentOf('cn=foo,dc=bar'));
@ -110,21 +90,19 @@ test('parent of', function (t) {
t.end();
});
test('DN parent', function (t) {
var _dn = dn.parse('cn=foo,ou=bar');
var parent1 = _dn.parent();
var parent2 = parent1.parent();
const _dn = dn.parse('cn=foo,ou=bar');
const parent1 = _dn.parent();
const parent2 = parent1.parent();
t.ok(parent1.equals('ou=bar'));
t.ok(parent2.equals(''));
t.equal(parent2.parent(), null);
t.end();
});
test('empty DNs', function (t) {
var _dn = dn.parse('');
var _dn2 = dn.parse('cn=foo');
const _dn = dn.parse('');
const _dn2 = dn.parse('cn=foo');
t.ok(_dn.isEmpty());
t.notOk(_dn2.isEmpty());
t.notOk(_dn.equals('cn=foo'));
@ -136,22 +114,20 @@ test('empty DNs', function (t) {
t.end();
});
test('case insensitive attribute names', function (t) {
var dn1 = dn.parse('CN=foo,dc=bar');
const dn1 = dn.parse('CN=foo,dc=bar');
t.ok(dn1.equals('cn=foo,dc=bar'));
t.ok(dn1.equals(dn.parse('cn=foo,DC=bar')));
t.end();
});
test('format', function (t) {
var DN_ORDER = dn.parse('sn=bar+cn=foo,ou=test');
var DN_QUOTE = dn.parse('cn="foo",ou=test');
var DN_QUOTE2 = dn.parse('cn=" foo",ou=test');
var DN_SPACE = dn.parse('cn=foo,ou=test');
var DN_SPACE2 = dn.parse('cn=foo ,ou=test');
var DN_CASE = dn.parse('CN=foo,Ou=test');
const DN_ORDER = dn.parse('sn=bar+cn=foo,ou=test');
const DN_QUOTE = dn.parse('cn="foo",ou=test');
const DN_QUOTE2 = dn.parse('cn=" foo",ou=test');
const DN_SPACE = dn.parse('cn=foo,ou=test');
const DN_SPACE2 = dn.parse('cn=foo ,ou=test');
const DN_CASE = dn.parse('CN=foo,Ou=test');
t.equal(DN_ORDER.format({keepOrder: false}), 'cn=foo+sn=bar, ou=test');
t.equal(DN_ORDER.format({keepOrder: true}), 'sn=bar+cn=foo, ou=test');
@ -174,9 +150,8 @@ test('format', function (t) {
t.end();
});
test('set format', function (t) {
var _dn = dn.parse('uid="user", sn=bar+cn=foo, dc=test , DC=com');
const _dn = dn.parse('uid="user", sn=bar+cn=foo, dc=test , DC=com');
t.equal(_dn.toString(), 'uid=user, cn=foo+sn=bar, dc=test, dc=com');
_dn.setFormat({keepOrder: true});
t.equal(_dn.toString(), 'uid=user, sn=bar+cn=foo, dc=test, dc=com');
@ -191,29 +166,27 @@ test('set format', function (t) {
t.end();
});
test('format persists across clone', function (t) {
var _dn = dn.parse('uid="user", sn=bar+cn=foo, dc=test , DC=com');
var OUT = 'UID="user", CN=foo+SN=bar, DC=test, DC=com';
const _dn = dn.parse('uid="user", sn=bar+cn=foo, dc=test , DC=com');
const OUT = 'UID="user", CN=foo+SN=bar, DC=test, DC=com';
_dn.setFormat({keepQuote: true, upperName: true});
var clone = _dn.clone();
const clone = _dn.clone();
t.equals(_dn.toString(), OUT);
t.equals(clone.toString(), OUT);
t.end();
});
test('initialization', function (t) {
var dn1 = new dn.DN();
const dn1 = new dn.DN();
t.ok(dn1);
t.equals(dn1.toString(), '');
t.ok(dn1.isEmpty(), 'DN with no initializer defaults to null DN');
var data = [
const data = [
new dn.RDN({ foo: 'bar' }),
new dn.RDN({ o: 'base' })
];
var dn2 = new dn.DN(data);
const dn2 = new dn.DN(data);
t.ok(dn2);
t.equals(dn2.toString(), 'foo=bar, o=base');
t.ok(!dn2.isEmpty());
@ -221,16 +194,15 @@ test('initialization', function (t) {
t.end();
});
test('array functions', function (t) {
var dn1 = dn.parse('a=foo, b=bar, c=baz');
const dn1 = dn.parse('a=foo, b=bar, c=baz');
t.ok(dn1);
t.equal(dn1.toString(), 'a=foo, b=bar, c=baz');
t.ok(dn1.reverse());
t.equal(dn1.toString(), 'c=baz, b=bar, a=foo');
var rdn = dn1.pop();
let rdn = dn1.pop();
t.ok(rdn);
t.equal(dn1.toString(), 'c=baz, b=bar');
@ -247,14 +219,13 @@ test('array functions', function (t) {
t.end();
});
test('isDN duck-testing', function (t) {
var valid = dn.parse('cn=foo');
var isDN = dn.DN.isDN;
const valid = dn.parse('cn=foo');
const isDN = dn.DN.isDN;
t.notOk(isDN(null));
t.notOk(isDN('cn=foo'));
t.ok(isDN(valid));
var duck = {
const duck = {
rdns: [ {look: 'ma'}, {a: 'dn'} ],
toString: function () { return 'look=ma, a=dn'; }
};

View File

@ -1,36 +1,32 @@
// Copyright 2015 Joyent, Inc.
'use strict';
var test = require('tap').test;
var ldap = require('../lib/index');
///--- Tests
const { test } = require('tap');
const { LDAPError, ConnectionError, AbandonedError, TimeoutError, LDAP_OTHER } = require('../lib');
test('basic error', function (t) {
var msg = 'mymsg';
var err = new ldap.LDAPError(msg, null, null);
const msg = 'mymsg';
const err = new LDAPError(msg, null, null);
t.ok(err);
t.equal(err.name, 'LDAPError');
t.equal(err.code, ldap.LDAP_OTHER);
t.equal(err.code, LDAP_OTHER);
t.equal(err.dn, '');
t.equal(err.message, msg);
t.end();
});
test('"custom" errors', function (t) {
var errors = [
{ name: 'ConnectionError', func: ldap.ConnectionError },
{ name: 'AbandonedError', func: ldap.AbandonedError },
{ name: 'TimeoutError', func: ldap.TimeoutError }
const errors = [
{ name: 'ConnectionError', func: ConnectionError },
{ name: 'AbandonedError', func: AbandonedError },
{ name: 'TimeoutError', func: TimeoutError }
];
errors.forEach(function (entry) {
var msg = entry.name + 'msg';
var err = new entry.func(msg);
const msg = entry.name + 'msg';
const err = new entry.func(msg);
t.ok(err);
t.equal(err.name, entry.name);
t.equal(err.code, ldap.LDAP_OTHER);
t.equal(err.code, LDAP_OTHER);
t.equal(err.dn, '');
t.equal(err.message, msg);
});

View File

@ -1,28 +1,7 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
'use strict';
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var EqualityFilter;
var AndFilter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
EqualityFilter = filters.EqualityFilter;
AndFilter = filters.AndFilter;
t.ok(EqualityFilter);
t.ok(AndFilter);
t.end();
});
const { test } = require('tap');
const { filters: { EqualityFilter, AndFilter } } = require('../../lib');
test('Construct no args', function (t) {
@ -30,9 +9,8 @@ test('Construct no args', function (t) {
t.end();
});
test('Construct args', function (t) {
var f = new AndFilter();
const f = new AndFilter();
f.addFilter(new EqualityFilter({
attribute: 'foo',
value: 'bar'
@ -46,9 +24,8 @@ test('Construct args', function (t) {
t.end();
});
test('match true', function (t) {
var f = new AndFilter();
const f = new AndFilter();
f.addFilter(new EqualityFilter({
attribute: 'foo',
value: 'bar'
@ -62,9 +39,8 @@ test('match true', function (t) {
t.end();
});
test('match false', function (t) {
var f = new AndFilter();
const f = new AndFilter();
f.addFilter(new EqualityFilter({
attribute: 'foo',
value: 'bar'

View File

@ -1,40 +1,19 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var ApproximateFilter;
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
ApproximateFilter = filters.ApproximateFilter;
t.ok(ApproximateFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { filters: { ApproximateFilter } } = require('../../lib');
test('Construct no args', function (t) {
var f = new ApproximateFilter();
const f = new ApproximateFilter();
t.ok(f);
t.ok(!f.attribute);
t.ok(!f.value);
t.end();
});
test('Construct args', function (t) {
var f = new ApproximateFilter({
const f = new ApproximateFilter({
attribute: 'foo',
value: 'bar'
});
@ -45,9 +24,8 @@ test('Construct args', function (t) {
t.end();
});
test('GH-109 = escape value only in toString()', function (t) {
var f = new ApproximateFilter({
const f = new ApproximateFilter({
attribute: 'foo',
value: 'ba(r)'
});
@ -58,25 +36,23 @@ test('GH-109 = escape value only in toString()', function (t) {
t.end();
});
test('parse ok', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeString('bar');
var f = new ApproximateFilter();
const f = new ApproximateFilter();
t.ok(f);
t.ok(f.parse(new BerReader(writer.buffer)));
t.end();
});
test('parse bad', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeInt(20);
var f = new ApproximateFilter();
const f = new ApproximateFilter();
t.ok(f);
try {
f.parse(new BerReader(writer.buffer));
@ -87,20 +63,19 @@ test('parse bad', function (t) {
t.end();
});
test('GH-109 = to ber uses plain values', function (t) {
var f = new ApproximateFilter({
let f = new ApproximateFilter({
attribute: 'foo',
value: 'ba(r)'
});
t.ok(f);
var writer = new BerWriter();
const writer = new BerWriter();
f.toBer(writer);
f = new ApproximateFilter();
t.ok(f);
var reader = new BerReader(writer.buffer);
const reader = new BerReader(writer.buffer);
reader.readSequence();
t.ok(f.parse(reader));

View File

@ -1,40 +1,19 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var EqualityFilter;
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
EqualityFilter = filters.EqualityFilter;
t.ok(EqualityFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { filters: { EqualityFilter } } = require('../../lib');
test('Construct no args', function (t) {
var f = new EqualityFilter();
const f = new EqualityFilter();
t.ok(f);
t.ok(!f.attribute);
t.ok(!f.value);
t.end();
});
test('Construct args', function (t) {
var f = new EqualityFilter({
const f = new EqualityFilter({
attribute: 'foo',
value: 'bar'
});
@ -45,9 +24,8 @@ test('Construct args', function (t) {
t.end();
});
test('GH-109 = escape value only in toString()', function (t) {
var f = new EqualityFilter({
const f = new EqualityFilter({
attribute: 'foo',
value: 'ba(r)'
});
@ -58,9 +36,8 @@ test('GH-109 = escape value only in toString()', function (t) {
t.end();
});
test('match true', function (t) {
var f = new EqualityFilter({
const f = new EqualityFilter({
attribute: 'foo',
value: 'bar'
});
@ -69,9 +46,8 @@ test('match true', function (t) {
t.end();
});
test('match multiple', function (t) {
var f = new EqualityFilter({
const f = new EqualityFilter({
attribute: 'foo',
value: 'bar'
});
@ -80,9 +56,8 @@ test('match multiple', function (t) {
t.end();
});
test('match false', function (t) {
var f = new EqualityFilter({
const f = new EqualityFilter({
attribute: 'foo',
value: 'bar'
});
@ -91,13 +66,12 @@ test('match false', function (t) {
t.end();
});
test('parse ok', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeString('bar');
var f = new EqualityFilter();
const f = new EqualityFilter();
t.ok(f);
t.ok(f.parse(new BerReader(writer.buffer)));
t.ok(f.matches({ foo: 'bar' }));
@ -106,9 +80,8 @@ test('parse ok', function (t) {
t.end();
});
test('escape EqualityFilter inputs', function (t) {
var f = new EqualityFilter({
const f = new EqualityFilter({
attribute: '(|(foo',
value: 'bar))('
});
@ -119,13 +92,12 @@ test('escape EqualityFilter inputs', function (t) {
t.end();
});
test('parse bad', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeInt(20);
var f = new EqualityFilter();
const f = new EqualityFilter();
t.ok(f);
try {
f.parse(new BerReader(writer.buffer));
@ -136,20 +108,19 @@ test('parse bad', function (t) {
t.end();
});
test('GH-109 = to ber uses plain values', function (t) {
var f = new EqualityFilter({
let f = new EqualityFilter({
attribute: 'foo',
value: 'ba(r)'
});
t.ok(f);
var writer = new BerWriter();
const writer = new BerWriter();
f.toBer(writer);
f = new EqualityFilter();
t.ok(f);
var reader = new BerReader(writer.buffer);
const reader = new BerReader(writer.buffer);
reader.readSequence();
t.ok(f.parse(reader));
@ -158,34 +129,32 @@ test('GH-109 = to ber uses plain values', function (t) {
t.end();
});
test('handle values passed via buffer', function (t) {
var b = new Buffer([32, 64, 128, 254]);
var f = new EqualityFilter({
const b = Buffer.from([32, 64, 128, 254]);
const f = new EqualityFilter({
attribute: 'foo',
value: b
});
t.ok(f);
var writer = new BerWriter();
const writer = new BerWriter();
f.toBer(writer);
var reader = new BerReader(writer.buffer);
const reader = new BerReader(writer.buffer);
reader.readSequence();
var f2 = new EqualityFilter();
const f2 = new EqualityFilter();
t.ok(f2.parse(reader));
t.equal(f2.value, b.toString());
t.equal(f2.raw.length, b.length);
for (var i = 0; i < b.length; i++) {
for (let i = 0; i < b.length; i++) {
t.equal(f2.raw[i], b[i]);
}
t.end();
});
test('GH-277 objectClass should be case-insensitive', function (t) {
var f = new EqualityFilter({
const f = new EqualityFilter({
attribute: 'objectClass',
value: 'CaseInsensitiveObj'
});

View File

@ -1,38 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var ExtensibleFilter;
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var filters;
///--- Tests
test('load library', function (t) {
filters = require('../../lib/index').filters;
t.ok(filters);
ExtensibleFilter = filters.ExtensibleFilter;
t.ok(ExtensibleFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { filters: { parseString, ExtensibleFilter } } = require('../../lib');
test('Construct no args', function (t) {
var f = new ExtensibleFilter();
const f = new ExtensibleFilter();
t.ok(f);
t.end();
});
test('Construct args', function (t) {
var f = new ExtensibleFilter({
const f = new ExtensibleFilter({
matchType: 'foo',
value: 'bar'
});
@ -43,9 +21,8 @@ test('Construct args', function (t) {
t.end();
});
test('parse RFC example 1', function (t) {
var f = filters.parseString('(cn:caseExactMatch:=Fred Flintstone)');
const f = parseString('(cn:caseExactMatch:=Fred Flintstone)');
t.ok(f);
t.equal(f.matchType, 'cn');
t.equal(f.matchingRule, 'caseExactMatch');
@ -54,9 +31,8 @@ test('parse RFC example 1', function (t) {
t.end();
});
test('parse RFC example 2', function (t) {
var f = filters.parseString('(cn:=Betty Rubble)');
const f = parseString('(cn:=Betty Rubble)');
t.ok(f);
t.equal(f.matchType, 'cn');
t.equal(f.matchValue, 'Betty Rubble');
@ -65,9 +41,8 @@ test('parse RFC example 2', function (t) {
t.end();
});
test('parse RFC example 3', function (t) {
var f = filters.parseString('(sn:dn:2.4.6.8.10:=Barney Rubble)');
const f = parseString('(sn:dn:2.4.6.8.10:=Barney Rubble)');
t.ok(f);
t.equal(f.matchType, 'sn');
t.equal(f.matchingRule, '2.4.6.8.10');
@ -76,9 +51,8 @@ test('parse RFC example 3', function (t) {
t.end();
});
test('parse RFC example 3', function (t) {
var f = filters.parseString('(o:dn:=Ace Industry)');
const f = parseString('(o:dn:=Ace Industry)');
t.ok(f);
t.equal(f.matchType, 'o');
t.notOk(f.matchingRule);
@ -87,9 +61,8 @@ test('parse RFC example 3', function (t) {
t.end();
});
test('parse RFC example 4', function (t) {
var f = filters.parseString('(:1.2.3:=Wilma Flintstone)');
const f = parseString('(:1.2.3:=Wilma Flintstone)');
t.ok(f);
t.notOk(f.matchType);
t.equal(f.matchingRule, '1.2.3');
@ -98,9 +71,8 @@ test('parse RFC example 4', function (t) {
t.end();
});
test('parse RFC example 5', function (t) {
var f = filters.parseString('(:DN:2.4.6.8.10:=Dino)');
const f = parseString('(:DN:2.4.6.8.10:=Dino)');
t.ok(f);
t.notOk(f.matchType);
t.equal(f.matchingRule, '2.4.6.8.10');

View File

@ -1,40 +1,19 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var GreaterThanEqualsFilter;
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
GreaterThanEqualsFilter = filters.GreaterThanEqualsFilter;
t.ok(GreaterThanEqualsFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { filters: { GreaterThanEqualsFilter } } = require('../../lib');
test('Construct no args', function (t) {
var f = new GreaterThanEqualsFilter();
const f = new GreaterThanEqualsFilter();
t.ok(f);
t.ok(!f.attribute);
t.ok(!f.value);
t.end();
});
test('Construct args', function (t) {
var f = new GreaterThanEqualsFilter({
const f = new GreaterThanEqualsFilter({
attribute: 'foo',
value: 'bar'
});
@ -45,9 +24,8 @@ test('Construct args', function (t) {
t.end();
});
test('GH-109 = escape value only in toString()', function (t) {
var f = new GreaterThanEqualsFilter({
const f = new GreaterThanEqualsFilter({
attribute: 'foo',
value: 'ba(r)'
});
@ -58,9 +36,8 @@ test('GH-109 = escape value only in toString()', function (t) {
t.end();
});
test('match true', function (t) {
var f = new GreaterThanEqualsFilter({
const f = new GreaterThanEqualsFilter({
attribute: 'foo',
value: 'bar'
});
@ -69,9 +46,8 @@ test('match true', function (t) {
t.end();
});
test('match multiple', function (t) {
var f = new GreaterThanEqualsFilter({
const f = new GreaterThanEqualsFilter({
attribute: 'foo',
value: 'bar'
});
@ -81,7 +57,7 @@ test('match multiple', function (t) {
});
test('match false', function (t) {
var f = new GreaterThanEqualsFilter({
const f = new GreaterThanEqualsFilter({
attribute: 'foo',
value: 'bar'
});
@ -90,26 +66,24 @@ test('match false', function (t) {
t.end();
});
test('parse ok', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeString('bar');
var f = new GreaterThanEqualsFilter();
const f = new GreaterThanEqualsFilter();
t.ok(f);
t.ok(f.parse(new BerReader(writer.buffer)));
t.ok(f.matches({ foo: 'bar' }));
t.end();
});
test('parse bad', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeInt(20);
var f = new GreaterThanEqualsFilter();
const f = new GreaterThanEqualsFilter();
t.ok(f);
try {
f.parse(new BerReader(writer.buffer));
@ -120,20 +94,19 @@ test('parse bad', function (t) {
t.end();
});
test('GH-109 = to ber uses plain values', function (t) {
var f = new GreaterThanEqualsFilter({
let f = new GreaterThanEqualsFilter({
attribute: 'foo',
value: 'ba(r)'
});
t.ok(f);
var writer = new BerWriter();
const writer = new BerWriter();
f.toBer(writer);
f = new GreaterThanEqualsFilter();
t.ok(f);
var reader = new BerReader(writer.buffer);
const reader = new BerReader(writer.buffer);
reader.readSequence();
t.ok(f.parse(reader));

View File

@ -1,40 +1,19 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var LessThanEqualsFilter;
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
LessThanEqualsFilter = filters.LessThanEqualsFilter;
t.ok(LessThanEqualsFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { filters: { LessThanEqualsFilter } } = require('../../lib');
test('Construct no args', function (t) {
var f = new LessThanEqualsFilter();
const f = new LessThanEqualsFilter();
t.ok(f);
t.ok(!f.attribute);
t.ok(!f.value);
t.end();
});
test('Construct args', function (t) {
var f = new LessThanEqualsFilter({
const f = new LessThanEqualsFilter({
attribute: 'foo',
value: 'bar'
});
@ -45,9 +24,8 @@ test('Construct args', function (t) {
t.end();
});
test('GH-109 = escape value only in toString()', function (t) {
var f = new LessThanEqualsFilter({
const f = new LessThanEqualsFilter({
attribute: 'foo',
value: 'ba(r)'
});
@ -58,9 +36,8 @@ test('GH-109 = escape value only in toString()', function (t) {
t.end();
});
test('match true', function (t) {
var f = new LessThanEqualsFilter({
const f = new LessThanEqualsFilter({
attribute: 'foo',
value: 'bar'
});
@ -69,9 +46,8 @@ test('match true', function (t) {
t.end();
});
test('match multiple', function (t) {
var f = new LessThanEqualsFilter({
const f = new LessThanEqualsFilter({
attribute: 'foo',
value: 'bar'
});
@ -80,9 +56,8 @@ test('match multiple', function (t) {
t.end();
});
test('match false', function (t) {
var f = new LessThanEqualsFilter({
const f = new LessThanEqualsFilter({
attribute: 'foo',
value: 'bar'
});
@ -91,26 +66,24 @@ test('match false', function (t) {
t.end();
});
test('parse ok', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeString('bar');
var f = new LessThanEqualsFilter();
const f = new LessThanEqualsFilter();
t.ok(f);
t.ok(f.parse(new BerReader(writer.buffer)));
t.ok(f.matches({ foo: 'bar' }));
t.end();
});
test('parse bad', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeInt(20);
var f = new LessThanEqualsFilter();
const f = new LessThanEqualsFilter();
t.ok(f);
try {
f.parse(new BerReader(writer.buffer));
@ -121,20 +94,19 @@ test('parse bad', function (t) {
t.end();
});
test('GH-109 = to ber uses plain values', function (t) {
var f = new LessThanEqualsFilter({
let f = new LessThanEqualsFilter({
attribute: 'foo',
value: 'ba(r)'
});
t.ok(f);
var writer = new BerWriter();
const writer = new BerWriter();
f.toBer(writer);
f = new LessThanEqualsFilter();
t.ok(f);
var reader = new BerReader(writer.buffer);
const reader = new BerReader(writer.buffer);
reader.readSequence();
t.ok(f.parse(reader));

View File

@ -1,38 +1,15 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var EqualityFilter;
var NotFilter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
EqualityFilter = filters.EqualityFilter;
NotFilter = filters.NotFilter;
t.ok(EqualityFilter);
t.ok(NotFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { filters: { EqualityFilter, NotFilter } } = require('../../lib');
test('Construct no args', function (t) {
t.ok(new NotFilter());
t.end();
});
test('Construct args', function (t) {
var f = new NotFilter({
const f = new NotFilter({
filter: new EqualityFilter({
attribute: 'foo',
value: 'bar'
@ -43,9 +20,8 @@ test('Construct args', function (t) {
t.end();
});
test('match true', function (t) {
var f = new NotFilter({
const f = new NotFilter({
filter: new EqualityFilter({
attribute: 'foo',
value: 'bar'
@ -56,9 +32,8 @@ test('match true', function (t) {
t.end();
});
test('match false', function (t) {
var f = new NotFilter({
const f = new NotFilter({
filter: new EqualityFilter({
attribute: 'foo',
value: 'bar'

View File

@ -1,38 +1,15 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var EqualityFilter;
var OrFilter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
EqualityFilter = filters.EqualityFilter;
OrFilter = filters.OrFilter;
t.ok(EqualityFilter);
t.ok(OrFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { filters: { EqualityFilter, OrFilter } } = require('../../lib');
test('Construct no args', function (t) {
t.ok(new OrFilter());
t.end();
});
test('Construct args', function (t) {
var f = new OrFilter();
const f = new OrFilter();
f.addFilter(new EqualityFilter({
attribute: 'foo',
value: 'bar'
@ -46,9 +23,8 @@ test('Construct args', function (t) {
t.end();
});
test('match true', function (t) {
var f = new OrFilter();
const f = new OrFilter();
f.addFilter(new EqualityFilter({
attribute: 'foo',
value: 'bar'
@ -62,9 +38,8 @@ test('match true', function (t) {
t.end();
});
test('match false', function (t) {
var f = new OrFilter();
const f = new OrFilter();
f.addFilter(new EqualityFilter({
attribute: 'foo',
value: 'bar'

View File

@ -1,14 +1,11 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var parse = require('../../lib/index').parseFilter;
'use strict';
const { test } = require('tap');
const { parseFilter: parse } = require('../../lib');
test('GH-48 XML Strings in filter', function (t) {
var str = '(&(CentralUIEnrollments=\\<mydoc\\>*)(objectClass=User))';
var f = parse(str);
const str = '(&(CentralUIEnrollments=\\<mydoc\\>*)(objectClass=User))';
const f = parse(str);
t.ok(f);
t.ok(f.filters);
t.equal(f.filters.length, 2);
@ -18,11 +15,10 @@ test('GH-48 XML Strings in filter', function (t) {
t.end();
});
test('GH-50 = in filter', function (t) {
var str = '(uniquemember=uuid=930896af-bf8c-48d4-885c-6573a94b1853, ' +
const str = '(uniquemember=uuid=930896af-bf8c-48d4-885c-6573a94b1853, ' +
'ou=users, o=smartdc)';
var f = parse(str);
const f = parse(str);
t.ok(f);
t.equal(f.attribute, 'uniquemember');
t.equal(f.value,
@ -30,10 +26,9 @@ test('GH-50 = in filter', function (t) {
t.end();
});
test('( in filter', function (t) {
var str = '(foo=bar\\()';
var f = parse(str);
const str = '(foo=bar\\()';
const f = parse(str);
t.ok(f);
t.equal(f.attribute, 'foo');
t.equal(f.value, 'bar(');
@ -42,8 +37,8 @@ test('( in filter', function (t) {
});
test(') in filter', function (t) {
var str = '(foo=bar\\))';
var f = parse(str);
const str = '(foo=bar\\))';
const f = parse(str);
t.ok(f);
t.equal(f.attribute, 'foo');
t.equal(f.value, 'bar)');
@ -51,10 +46,9 @@ test(') in filter', function (t) {
t.end();
});
test('\\ in filter', function (t) {
var str = '(foo=bar\\\\)';
var f = parse(str);
const str = '(foo=bar\\\\)';
const f = parse(str);
t.ok(f);
t.equal(f.attribute, 'foo');
t.equal(f.value, 'bar\\');
@ -62,10 +56,9 @@ test('\\ in filter', function (t) {
t.end();
});
test('* in equality filter', function (t) {
var str = '(foo=bar\\*)';
var f = parse(str);
const str = '(foo=bar\\*)';
const f = parse(str);
t.ok(f);
t.equal(f.attribute, 'foo');
t.equal(f.value, 'bar*');
@ -73,10 +66,9 @@ test('* in equality filter', function (t) {
t.end();
});
test('* substr filter (prefix)', function (t) {
var str = '(foo=bar*)';
var f = parse(str);
const str = '(foo=bar*)';
const f = parse(str);
t.ok(f);
t.equal(f.attribute, 'foo');
t.equal(f.initial, 'bar');
@ -84,10 +76,9 @@ test('* substr filter (prefix)', function (t) {
t.end();
});
test('GH-53 NotFilter', function (t) {
var str = '(&(objectClass=person)(!(objectClass=shadowAccount)))';
var f = parse(str);
const str = '(&(objectClass=person)(!(objectClass=shadowAccount)))';
const f = parse(str);
t.ok(f);
t.equal(f.type, 'and');
t.equal(f.filters.length, 2);
@ -99,9 +90,8 @@ test('GH-53 NotFilter', function (t) {
t.end();
});
test('presence filter', function (t) {
var f = parse('(foo=*)');
const f = parse('(foo=*)');
t.ok(f);
t.equal(f.type, 'present');
t.equal(f.attribute, 'foo');
@ -109,7 +99,6 @@ test('presence filter', function (t) {
t.end();
});
test('bogus filter', function (t) {
t.throws(function () {
parse('foo>1');
@ -117,7 +106,6 @@ test('bogus filter', function (t) {
t.end();
});
test('bogus filter !=', function (t) {
t.throws(function () {
parse('foo!=1');
@ -125,7 +113,6 @@ test('bogus filter !=', function (t) {
t.end();
});
test('mismatched parens', function (t) {
t.throws(function () {
parse('(&(foo=bar)(!(state=done))');

View File

@ -1,39 +1,18 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var PresenceFilter;
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
PresenceFilter = filters.PresenceFilter;
t.ok(PresenceFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { filters: { PresenceFilter } } = require('../../lib');
test('Construct no args', function (t) {
var f = new PresenceFilter();
const f = new PresenceFilter();
t.ok(f);
t.ok(!f.attribute);
t.end();
});
test('Construct args', function (t) {
var f = new PresenceFilter({
const f = new PresenceFilter({
attribute: 'foo'
});
t.ok(f);
@ -43,7 +22,7 @@ test('Construct args', function (t) {
});
test('GH-109 = escape value only in toString()', function (t) {
var f = new PresenceFilter({
const f = new PresenceFilter({
attribute: 'fo)o'
});
t.ok(f);
@ -52,9 +31,8 @@ test('GH-109 = escape value only in toString()', function (t) {
t.end();
});
test('match true', function (t) {
var f = new PresenceFilter({
const f = new PresenceFilter({
attribute: 'foo'
});
t.ok(f);
@ -62,9 +40,8 @@ test('match true', function (t) {
t.end();
});
test('match false', function (t) {
var f = new PresenceFilter({
const f = new PresenceFilter({
attribute: 'foo'
});
t.ok(f);
@ -72,34 +49,32 @@ test('match false', function (t) {
t.end();
});
test('parse ok', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo', 0x87);
var f = new PresenceFilter();
const f = new PresenceFilter();
t.ok(f);
var reader = new BerReader(writer.buffer);
const reader = new BerReader(writer.buffer);
reader.readSequence();
t.ok(f.parse(reader));
t.ok(f.matches({ foo: 'bar' }));
t.end();
});
test('GH-109 = to ber uses plain values', function (t) {
var f = new PresenceFilter({
let f = new PresenceFilter({
attribute: 'f(o)o'
});
t.ok(f);
var writer = new BerWriter();
const writer = new BerWriter();
f.toBer(writer);
f = new PresenceFilter();
t.ok(f);
var reader = new BerReader(writer.buffer);
const reader = new BerReader(writer.buffer);
reader.readSequence();
t.ok(f.parse(reader));

View File

@ -1,40 +1,19 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var SubstringFilter;
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
///--- Tests
test('load library', function (t) {
var filters = require('../../lib/index').filters;
t.ok(filters);
SubstringFilter = filters.SubstringFilter;
t.ok(SubstringFilter);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { filters: { SubstringFilter } } = require('../../lib');
test('Construct no args', function (t) {
var f = new SubstringFilter();
const f = new SubstringFilter();
t.ok(f);
t.ok(!f.attribute);
t.ok(!f.value);
t.end();
});
test('Construct args', function (t) {
var f = new SubstringFilter({
const f = new SubstringFilter({
attribute: 'foo',
initial: 'bar',
any: ['zig', 'zag'],
@ -51,9 +30,8 @@ test('Construct args', function (t) {
t.end();
});
test('GH-109 = escape value only in toString()', function (t) {
var f = new SubstringFilter({
const f = new SubstringFilter({
attribute: 'fo(o',
initial: 'ba(r)',
any: ['zi)g', 'z(ag'],
@ -70,9 +48,8 @@ test('GH-109 = escape value only in toString()', function (t) {
t.end();
});
test('match true', function (t) {
var f = new SubstringFilter({
const f = new SubstringFilter({
attribute: 'foo',
initial: 'bar',
any: ['zig', 'zag'],
@ -83,9 +60,8 @@ test('match true', function (t) {
t.end();
});
test('match false', function (t) {
var f = new SubstringFilter({
const f = new SubstringFilter({
attribute: 'foo',
initial: 'bar',
foo: ['zig', 'zag'],
@ -96,9 +72,8 @@ test('match false', function (t) {
t.end();
});
test('match any', function (t) {
var f = new SubstringFilter({
const f = new SubstringFilter({
attribute: 'foo',
initial: 'bar'
});
@ -107,9 +82,8 @@ test('match any', function (t) {
t.end();
});
test('GH-109 = escape for regex in matches', function (t) {
var f = new SubstringFilter({
const f = new SubstringFilter({
attribute: 'fo(o',
initial: 'ba(r)',
any: ['zi)g', 'z(ag'],
@ -120,29 +94,27 @@ test('GH-109 = escape for regex in matches', function (t) {
t.end();
});
test('parse ok', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.startSequence();
writer.writeString('bar', 0x80);
writer.writeString('bad', 0x81);
writer.writeString('baz', 0x82);
writer.endSequence();
var f = new SubstringFilter();
const f = new SubstringFilter();
t.ok(f);
t.ok(f.parse(new BerReader(writer.buffer)));
t.ok(f.matches({ foo: 'bargoobadgoobaz' }));
t.end();
});
test('parse bad', function (t) {
var writer = new BerWriter();
const writer = new BerWriter();
writer.writeString('foo');
writer.writeInt(20);
var f = new SubstringFilter();
const f = new SubstringFilter();
t.ok(f);
try {
f.parse(new BerReader(writer.buffer));
@ -152,22 +124,21 @@ test('parse bad', function (t) {
t.end();
});
test('GH-109 = to ber uses plain values', function (t) {
var f = new SubstringFilter({
let f = new SubstringFilter({
attribute: 'fo(o',
initial: 'ba(r)',
any: ['zi)g', 'z(ag'],
'final': '(baz)'
});
t.ok(f);
var writer = new BerWriter();
const writer = new BerWriter();
f.toBer(writer);
f = new SubstringFilter();
t.ok(f);
var reader = new BerReader(writer.buffer);
const reader = new BerReader(writer.buffer);
reader.readSequence();
t.ok(f.parse(reader));

View File

@ -1,64 +1,43 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
'use strict';
var test = require('tap').test;
var uuid = require('uuid');
var ldap = require('../lib/index');
///--- Globals
var SOCKET = process.platform === 'win32' ? '\\\\.\\pipe\\' + uuid() : '/tmp/.' + uuid();
var SUFFIX = 'dc=' + uuid();
var client;
var server;
///--- Helper
const tap = require('tap');
const uuid = require('uuid')
const { getSock } = require('./utils')
const ldap = require('../lib');
function search(t, options, callback) {
client.search(SUFFIX, options, function (err, res) {
t.ifError(err);
t.context.client.search(t.context.suffix, options, function (err, res) {
t.error(err);
t.ok(res);
var found = false;
let found = false;
res.on('searchEntry', function (entry) {
t.ok(entry);
found = true;
});
res.on('end', function () {
t.ok(found);
if (callback)
return callback();
t.true(found);
if (callback) return callback();
return t.end();
});
});
}
tap.beforeEach((done, t) => {
const suffix = `dc=${uuid()}`;
const server = ldap.createServer();
///--- Tests
test('setup', function (t) {
server = ldap.createServer();
t.ok(server);
server.listen(SOCKET, function () {
client = ldap.createClient({
socketPath: SOCKET
});
t.ok(client);
t.end();
});
t.context.server = server;
t.context.socketPath = getSock();
t.context.suffix = suffix;
server.bind('cn=root', function (req, res, next) {
res.end();
return next();
});
server.search(SUFFIX, function (req, res, next) {
server.search(suffix, function (req, res, next) {
var entry = {
dn: 'cn=foo, ' + SUFFIX,
dn: 'cn=foo, ' + suffix,
attributes: {
objectclass: ['person', 'top'],
cn: 'Pogo Stick',
@ -73,12 +52,32 @@ test('setup', function (t) {
res.end();
});
});
server.listen(t.context.socketPath, function () {
t.context.client = ldap.createClient({
socketPath: t.context.socketPath
});
test('Evolution search filter (GH-3)', function (t) {
t.context.client.on('connectError', (err) => {
t.context.server.close(() => done(err));
})
t.context.client.on('connect', (socket) => {
t.context.socket = socket;
done();
})
});
})
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) {
// This is what Evolution sends, when searching for a contact 'ogo'. Wow.
var filter =
const filter =
'(|(cn=ogo*)(givenname=ogo*)(sn=ogo*)(mail=ogo*)(member=ogo*)' +
'(primaryphone=ogo*)(telephonenumber=ogo*)(homephone=ogo*)(mobile=ogo*)' +
'(carphone=ogo*)(facsimiletelephonenumber=ogo*)' +
@ -99,9 +98,8 @@ test('Evolution search filter (GH-3)', function (t) {
return search(t, filter);
});
test('GH-49 Client errors on bad attributes', function (t) {
var searchOpts = {
tap.test('GH-49 Client errors on bad attributes', function (t) {
const searchOpts = {
filter: 'cn=*ogo*',
scope: 'one',
attributes: 'dn'
@ -109,17 +107,16 @@ test('GH-49 Client errors on bad attributes', function (t) {
return search(t, searchOpts);
});
test('GH-55 Client emits connect multiple times', function (t) {
var c = ldap.createClient({
socketPath: SOCKET
tap.test('GH-55 Client emits connect multiple times', function (t) {
const c = ldap.createClient({
socketPath: t.context.socketPath
});
var count = 0;
let count = 0;
c.on('connect', function (socket) {
t.ok(socket);
count++;
c.bind('cn=root', 'secret', function (err, res) {
c.bind('cn=root', 'secret', function (err) {
t.ifError(err);
c.unbind(function () {
t.equal(count, 1);
@ -128,13 +125,3 @@ test('GH-55 Client emits connect multiple times', function (t) {
});
});
});
test('shutdown', function (t) {
client.unbind(function () {
server.on('close', function () {
t.end();
});
server.close();
});
});

View File

@ -1,39 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
'use strict';
var test = require('tap').test;
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { AddRequest, Attribute, dn } = require('../../lib');
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var AddRequest;
var Attribute;
var dn;
///--- Tests
test('load library', function (t) {
AddRequest = require('../../lib/index').AddRequest;
Attribute = require('../../lib/index').Attribute;
dn = require('../../lib/index').dn;
t.ok(AddRequest);
t.ok(Attribute);
t.ok(dn);
t.end();
});
test('new no args', function (t) {
test('new no args', t => {
t.ok(new AddRequest());
t.end();
});
test('new with args', function (t) {
var req = new AddRequest({
test('new with args', t => {
const req = new AddRequest({
entry: dn.parse('cn=foo, o=test'),
attributes: [new Attribute({type: 'cn', vals: ['foo']}),
new Attribute({type: 'objectclass', vals: ['person']})]
@ -48,9 +25,8 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
test('parse', t => {
const ber = new BerWriter();
ber.writeString('cn=foo, o=test');
ber.startSequence();
@ -71,7 +47,7 @@ test('parse', function (t) {
ber.endSequence();
var req = new AddRequest();
const req = new AddRequest();
t.ok(req._parse(new BerReader(ber.buffer)));
t.equal(req.dn.toString(), 'cn=foo, o=test');
t.equal(req.attributes.length, 2);
@ -82,9 +58,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var req = new AddRequest({
test('toBer', t => {
const req = new AddRequest({
messageID: 123,
entry: dn.parse('cn=foo, o=test'),
attributes: [new Attribute({type: 'cn', vals: ['foo']}),
@ -93,7 +68,7 @@ test('toBer', function (t) {
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);
@ -114,9 +89,8 @@ test('toBer', function (t) {
t.end();
});
test('toObject', function (t) {
var req = new AddRequest({
test('toObject', t => {
const req = new AddRequest({
entry: dn.parse('cn=foo, o=test'),
attributes: [new Attribute({type: 'cn', vals: ['foo', 'bar']}),
new Attribute({type: 'objectclass', vals: ['person']})]
@ -124,7 +98,7 @@ test('toObject', function (t) {
t.ok(req);
var obj = req.toObject();
const obj = req.toObject();
t.ok(obj);
t.ok(obj.dn);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var AddResponse;
///--- Tests
test('load library', function (t) {
AddResponse = require('../../lib/index').AddResponse;
t.ok(AddResponse);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { AddResponse } = require('../../lib');
test('new no args', function (t) {
t.ok(new AddResponse());
t.end();
});
test('new with args', function (t) {
var res = new AddResponse({
const res = new AddResponse({
messageID: 123,
status: 0
});
@ -38,14 +20,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeEnumeration(0);
ber.writeString('cn=root');
ber.writeString('foo');
var res = new AddResponse();
const res = new AddResponse();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.status, 0);
t.equal(res.matchedDN, 'cn=root');
@ -53,9 +34,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var res = new AddResponse({
const res = new AddResponse({
messageID: 123,
status: 3,
matchedDN: 'cn=root',
@ -63,7 +43,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,36 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var BindRequest;
var dn;
///--- Tests
test('load library', function (t) {
BindRequest = require('../../lib/index').BindRequest;
dn = require('../../lib/index').dn;
t.ok(BindRequest);
t.ok(dn);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { BindRequest, dn } = require('../../lib');
test('new no args', function (t) {
t.ok(new BindRequest());
t.end();
});
test('new with args', function (t) {
var req = new BindRequest({
const req = new BindRequest({
version: 3,
name: dn.parse('cn=root'),
credentials: 'secret'
@ -42,14 +22,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeInt(3);
ber.writeString('cn=root');
ber.writeString('secret', 0x80);
var req = new BindRequest();
const req = new BindRequest();
t.ok(req._parse(new BerReader(ber.buffer)));
t.equal(req.version, 3);
t.equal(req.dn.toString(), 'cn=root');
@ -57,9 +36,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var req = new BindRequest({
const req = new BindRequest({
messageID: 123,
version: 3,
name: dn.parse('cn=root'),
@ -67,7 +45,7 @@ test('toBer', function (t) {
});
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var BindResponse;
///--- Tests
test('load library', function (t) {
BindResponse = require('../../lib/index').BindResponse;
t.ok(BindResponse);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { BindResponse } = require('../../lib');
test('new no args', function (t) {
t.ok(new BindResponse());
t.end();
});
test('new with args', function (t) {
var res = new BindResponse({
const res = new BindResponse({
messageID: 123,
status: 0
});
@ -38,14 +20,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeEnumeration(0);
ber.writeString('cn=root');
ber.writeString('foo');
var res = new BindResponse();
const res = new BindResponse();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.status, 0);
t.equal(res.matchedDN, 'cn=root');
@ -53,9 +34,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var res = new BindResponse({
const res = new BindResponse({
messageID: 123,
status: 3,
matchedDN: 'cn=root',
@ -63,7 +43,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,36 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var CompareRequest;
var dn;
///--- Tests
test('load library', function (t) {
CompareRequest = require('../../lib/index').CompareRequest;
dn = require('../../lib/index').dn;
t.ok(CompareRequest);
t.ok(dn);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { CompareRequest, dn } = require('../../lib');
test('new no args', function (t) {
t.ok(new CompareRequest());
t.end();
});
test('new with args', function (t) {
var req = new CompareRequest({
const req = new CompareRequest({
entry: dn.parse('cn=foo, o=test'),
attribute: 'sn',
value: 'testy'
@ -42,9 +22,8 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeString('cn=foo, o=test');
ber.startSequence();
@ -52,8 +31,7 @@ test('parse', function (t) {
ber.writeString('testy');
ber.endSequence();
var req = new CompareRequest();
const req = new CompareRequest();
t.ok(req._parse(new BerReader(ber.buffer)));
t.equal(req.dn, 'cn=foo, o=test');
t.equal(req.attribute, 'sn');
@ -61,9 +39,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var req = new CompareRequest({
const req = new CompareRequest({
messageID: 123,
entry: dn.parse('cn=foo, o=test'),
attribute: 'sn',
@ -72,7 +49,7 @@ test('toBer', function (t) {
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var CompareResponse;
///--- Tests
test('load library', function (t) {
CompareResponse = require('../../lib/index').CompareResponse;
t.ok(CompareResponse);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { CompareResponse } = require('../../lib');
test('new no args', function (t) {
t.ok(new CompareResponse());
t.end();
});
test('new with args', function (t) {
var res = new CompareResponse({
const res = new CompareResponse({
messageID: 123,
status: 0
});
@ -38,14 +20,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeEnumeration(0);
ber.writeString('cn=root');
ber.writeString('foo');
var res = new CompareResponse();
const res = new CompareResponse();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.status, 0);
t.equal(res.matchedDN, 'cn=root');
@ -53,9 +34,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var res = new CompareResponse({
const res = new CompareResponse({
messageID: 123,
status: 3,
matchedDN: 'cn=root',
@ -63,7 +43,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,37 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var asn1 = require('asn1');
var logger = Object.create(require('abstract-logging'));
var test = require('tap').test;
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var DeleteRequest;
var dn;
///--- Tests
test('load library', function (t) {
DeleteRequest = require('../../lib/index').DeleteRequest;
dn = require('../../lib/index').dn;
t.ok(DeleteRequest);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { DeleteRequest, dn } = require('../../lib');
test('new no args', function (t) {
t.ok(new DeleteRequest());
t.end();
});
test('new with args', function (t) {
var req = new DeleteRequest({
const req = new DeleteRequest({
entry: dn.parse('cn=test')
});
t.ok(req);
@ -39,30 +18,26 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeString('cn=test', 0x4a);
var req = new DeleteRequest({
log: logger
});
var reader = new BerReader(ber.buffer);
const req = new DeleteRequest();
const reader = new BerReader(ber.buffer);
reader.readSequence(0x4a);
t.ok(req.parse(reader, reader.length));
t.equal(req.dn.toString(), 'cn=test');
t.end();
});
test('toBer', function (t) {
var req = new DeleteRequest({
const req = new DeleteRequest({
messageID: 123,
entry: dn.parse('cn=test')
});
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var DeleteResponse;
///--- Tests
test('load library', function (t) {
DeleteResponse = require('../../lib/index').DeleteResponse;
t.ok(DeleteResponse);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { DeleteResponse } = require('../../lib');
test('new no args', function (t) {
t.ok(new DeleteResponse());
t.end();
});
test('new with args', function (t) {
var res = new DeleteResponse({
const res = new DeleteResponse({
messageID: 123,
status: 0
});
@ -38,14 +20,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeEnumeration(0);
ber.writeString('cn=root');
ber.writeString('foo');
var res = new DeleteResponse();
const res = new DeleteResponse();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.status, 0);
t.equal(res.matchedDN, 'cn=root');
@ -53,9 +34,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var res = new DeleteResponse({
const res = new DeleteResponse({
messageID: 123,
status: 3,
matchedDN: 'cn=root',
@ -63,7 +43,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,51 +1,8 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
var Buffer = require('buffer').Buffer;
// Buffer.compare was only added on node 0.11.13
var areBuffersEqual = function areBuffersEqual(bufA, bufB) {
if(!(Buffer.isBuffer(bufA) && Buffer.isBuffer(bufB))) {
return false;
}
if(typeof Buffer.compare === 'function') {
return Buffer.compare(bufA, bufB) === 0;
}
var len = bufA.length;
if (len !== bufB.length) {
return false;
}
for (var i = 0; i < len; i++) {
if (bufA.readUInt8(i) !== bufB.readUInt8(i)) {
return false;
}
}
return true;
};
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var ExtendedRequest;
var dn;
///--- Tests
test('load library', function (t) {
ExtendedRequest = require('../../lib/index').ExtendedRequest;
dn = require('../../lib/index').dn;
t.ok(ExtendedRequest);
t.ok(dn);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { ExtendedRequest } = require('../../lib');
test('new no args', function (t) {
t.ok(new ExtendedRequest());
@ -54,37 +11,37 @@ test('new no args', function (t) {
test('new with args', function (t) {
var req = new ExtendedRequest({
const req = new ExtendedRequest({
requestName: '1.2.3.4',
requestValue: 'test'
});
t.ok(req);
t.equal(req.requestName, '1.2.3.4');
t.equal(req.requestValue, 'test');
t.ok(areBuffersEqual(req.requestValueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
t.equal(req.value, 'test');
t.ok(areBuffersEqual(req.valueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
t.end();
});
test('new with buffer args', function (t) {
var req = new ExtendedRequest({
const req = new ExtendedRequest({
requestName: '1.2.3.4',
requestValue: new Buffer('test', 'utf8')
requestValue: Buffer.from('test', 'utf8')
});
t.ok(req);
t.equal(req.requestName, '1.2.3.4');
t.equal(req.requestValue, req.requestValueBuffer);
t.ok(areBuffersEqual(req.requestValueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
t.equal(req.value, req.valueBuffer);
t.ok(areBuffersEqual(req.valueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
t.end();
});
test('new no args set args', function (t) {
var req = new ExtendedRequest();
const req = new ExtendedRequest();
t.ok(req);
req.name = '1.2.3.4';
@ -92,50 +49,50 @@ test('new no args set args', function (t) {
req.value = 'test';
t.equal(req.requestValue, 'test');
t.ok(areBuffersEqual(req.requestValueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
t.equal(req.value, 'test');
t.ok(areBuffersEqual(req.valueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
t.end();
});
test('new no args set args buffer', function (t) {
var req = new ExtendedRequest();
const req = new ExtendedRequest();
t.ok(req);
req.name = '1.2.3.4';
t.equal(req.requestName, '1.2.3.4');
req.value = new Buffer('test', 'utf8');
req.value = Buffer.from('test', 'utf8');
t.equal(req.requestValue, req.requestValueBuffer);
t.ok(areBuffersEqual(req.requestValueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
t.equal(req.value, req.valueBuffer);
t.ok(areBuffersEqual(req.valueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeString('1.2.3.4', 0x80);
ber.writeString('test', 0x81);
var req = new ExtendedRequest();
const req = new ExtendedRequest();
t.ok(req._parse(new BerReader(ber.buffer)));
t.equal(req.requestName, '1.2.3.4');
t.equal(req.requestValue, 'test');
t.ok(areBuffersEqual(req.requestValueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.requestValueBuffer, Buffer.from('test', 'utf8')), 0);
t.equal(req.value, 'test');
t.ok(areBuffersEqual(req.valueBuffer, new Buffer('test', 'utf8')));
t.is(Buffer.compare(req.valueBuffer, Buffer.from('test', 'utf8')), 0);
t.end();
});
test('toBer', function (t) {
var req = new ExtendedRequest({
const req = new ExtendedRequest({
messageID: 123,
requestName: '1.2.3.4',
requestValue: 'test'
@ -143,7 +100,7 @@ test('toBer', function (t) {
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);
@ -156,15 +113,15 @@ test('toBer', function (t) {
test('toBer from buffer', function (t) {
var req = new ExtendedRequest({
const req = new ExtendedRequest({
messageID: 123,
requestName: '1.2.3.4',
requestValue: new Buffer('test', 'utf8')
requestValue: Buffer.from('test', 'utf8')
});
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var ExtendedResponse;
///--- Tests
test('load library', function (t) {
ExtendedResponse = require('../../lib/index').ExtendedResponse;
t.ok(ExtendedResponse);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { ExtendedResponse } = require('../../lib');
test('new no args', function (t) {
t.ok(new ExtendedResponse());
t.end();
});
test('new with args', function (t) {
var res = new ExtendedResponse({
const res = new ExtendedResponse({
messageID: 123,
status: 0,
responseName: '1.2.3.4',
@ -42,16 +24,15 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeEnumeration(0);
ber.writeString('cn=root');
ber.writeString('foo');
ber.writeString('1.2.3.4', 0x8a);
ber.writeString('test', 0x8b);
var res = new ExtendedResponse();
const res = new ExtendedResponse();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.status, 0);
t.equal(res.matchedDN, 'cn=root');
@ -61,9 +42,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var res = new ExtendedResponse({
const res = new ExtendedResponse({
messageID: 123,
status: 3,
matchedDN: 'cn=root',
@ -73,7 +53,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,36 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var ModifyDNRequest;
var dn;
///--- Tests
test('load library', function (t) {
ModifyDNRequest = require('../../lib/index').ModifyDNRequest;
dn = require('../../lib/index').dn;
t.ok(ModifyDNRequest);
t.ok(dn);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { ModifyDNRequest, dn } = require('../../lib');
test('new no args', function (t) {
t.ok(new ModifyDNRequest());
t.end();
});
test('new with args', function (t) {
var req = new ModifyDNRequest({
const req = new ModifyDNRequest({
entry: dn.parse('cn=foo, o=test'),
newRdn: dn.parse('cn=foo2'),
deleteOldRdn: true
@ -42,14 +22,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeString('cn=foo, o=test');
ber.writeString('cn=foo2');
ber.writeBoolean(true);
var req = new ModifyDNRequest();
const req = new ModifyDNRequest();
t.ok(req._parse(new BerReader(ber.buffer)));
t.equal(req.dn.toString(), 'cn=foo, o=test');
t.equal(req.newRdn.toString(), 'cn=foo2');
@ -58,9 +37,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var req = new ModifyDNRequest({
const req = new ModifyDNRequest({
messageID: 123,
entry: dn.parse('cn=foo, o=test'),
newRdn: dn.parse('cn=foo2'),
@ -69,7 +47,7 @@ test('toBer', function (t) {
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var ModifyDNResponse;
///--- Tests
test('load library', function (t) {
ModifyDNResponse = require('../../lib/index').ModifyDNResponse;
t.ok(ModifyDNResponse);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { ModifyDNResponse } = require('../../lib');
test('new no args', function (t) {
t.ok(new ModifyDNResponse());
t.end();
});
test('new with args', function (t) {
var res = new ModifyDNResponse({
const res = new ModifyDNResponse({
messageID: 123,
status: 0
});
@ -38,14 +20,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeEnumeration(0);
ber.writeString('cn=root');
ber.writeString('foo');
var res = new ModifyDNResponse();
const res = new ModifyDNResponse();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.status, 0);
t.equal(res.matchedDN, 'cn=root');
@ -53,9 +34,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var res = new ModifyDNResponse({
const res = new ModifyDNResponse({
messageID: 123,
status: 3,
matchedDN: 'cn=root',
@ -63,7 +43,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,42 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var ModifyRequest;
var Attribute;
var Change;
var dn;
///--- Tests
test('load library', function (t) {
ModifyRequest = require('../../lib/index').ModifyRequest;
Attribute = require('../../lib/index').Attribute;
Change = require('../../lib/index').Change;
dn = require('../../lib/index').dn;
t.ok(ModifyRequest);
t.ok(Attribute);
t.ok(Change);
t.ok(dn);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { ModifyRequest, Attribute, Change, dn } = require('../../lib');
test('new no args', function (t) {
t.ok(new ModifyRequest());
t.end();
});
test('new with args', function (t) {
var req = new ModifyRequest({
const req = new ModifyRequest({
object: dn.parse('cn=foo, o=test'),
changes: [new Change({
operation: 'Replace',
@ -52,9 +26,8 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeString('cn=foo, o=test');
ber.startSequence();
@ -72,7 +45,7 @@ test('parse', function (t) {
ber.endSequence();
var req = new ModifyRequest();
const req = new ModifyRequest();
t.ok(req._parse(new BerReader(ber.buffer)));
t.equal(req.dn.toString(), 'cn=foo, o=test');
t.equal(req.changes.length, 1);
@ -82,9 +55,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var req = new ModifyRequest({
const req = new ModifyRequest({
messageID: 123,
object: dn.parse('cn=foo, o=test'),
changes: [new Change({
@ -95,7 +67,7 @@ test('toBer', function (t) {
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var ModifyResponse;
///--- Tests
test('load library', function (t) {
ModifyResponse = require('../../lib/index').ModifyResponse;
t.ok(ModifyResponse);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { ModifyResponse } = require('../../lib');
test('new no args', function (t) {
t.ok(new ModifyResponse());
t.end();
});
test('new with args', function (t) {
var res = new ModifyResponse({
const res = new ModifyResponse({
messageID: 123,
status: 0
});
@ -38,14 +20,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeEnumeration(0);
ber.writeString('cn=root');
ber.writeString('foo');
var res = new ModifyResponse();
const res = new ModifyResponse();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.status, 0);
t.equal(res.matchedDN, 'cn=root');
@ -53,9 +34,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var res = new ModifyResponse({
const res = new ModifyResponse({
messageID: 123,
status: 3,
matchedDN: 'cn=root',
@ -63,7 +43,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,24 +1,10 @@
// Copyright 2014 Joyent, Inc. All rights reserved.
'use strict';
var test = require('tap').test;
var logger = Object.create(require('abstract-logging'));
///--- Globals
var lib;
var Parser;
///--- Tests
test('load library', function (t) {
lib = require('../../lib/');
Parser = lib.Parser;
t.ok(Parser);
t.end();
});
const { test } = require('tap');
const { Parser, LDAPMessage, LDAP_REQ_EXTENSION } = require('../../lib');
test('wrong protocol error', function (t) {
var p = new Parser({log: logger});
const p = new Parser();
p.once('error', function (err) {
t.ok(err);
@ -26,12 +12,12 @@ test('wrong protocol error', function (t) {
});
// Send some bogus data to incur an error
p.write(new Buffer([16, 1, 4]));
p.write(Buffer.from([16, 1, 4]));
});
test('bad protocol op', function (t) {
var p = new Parser({log: logger});
var message = new lib.LDAPMessage({
const p = new Parser();
const message = new LDAPMessage({
protocolOp: 254 // bogus (at least today)
});
p.once('error', function (err) {
@ -43,14 +29,14 @@ test('bad protocol op', function (t) {
});
test('bad message structure', function (t) {
var p = new Parser({log: logger});
const p = new Parser();
// message with bogus structure
var message = new lib.LDAPMessage({
protocolOp: lib.LDAP_REQ_EXTENSION
const message = new LDAPMessage({
protocolOp: LDAP_REQ_EXTENSION
});
message._toBer = function (writer) {
writer.writeBuffer(new Buffer([16, 1, 4]), 80);
writer.writeBuffer(Buffer.from([16, 1, 4]), 80);
return writer;
};

View File

@ -1,39 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var SearchEntry;
var Attribute;
var dn;
///--- Tests
test('load library', function (t) {
SearchEntry = require('../../lib/index').SearchEntry;
Attribute = require('../../lib/index').Attribute;
dn = require('../../lib/index').dn;
t.ok(SearchEntry);
t.ok(dn);
t.ok(Attribute);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { SearchEntry, Attribute, dn } = require('../../lib');
test('new no args', function (t) {
t.ok(new SearchEntry());
t.end();
});
test('new with args', function (t) {
var res = new SearchEntry({
const res = new SearchEntry({
messageID: 123,
objectName: dn.parse('cn=foo, o=test'),
attributes: [new Attribute({type: 'cn', vals: ['foo']}),
@ -50,9 +27,8 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeString('cn=foo, o=test');
ber.startSequence();
@ -73,7 +49,7 @@ test('parse', function (t) {
ber.endSequence();
var res = new SearchEntry();
const res = new SearchEntry();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.dn, 'cn=foo, o=test');
t.equal(res.attributes.length, 2);
@ -84,9 +60,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var res = new SearchEntry({
const res = new SearchEntry({
messageID: 123,
objectName: dn.parse('cn=foo, o=test'),
attributes: [new Attribute({type: 'cn', vals: ['foo']}),
@ -94,7 +69,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,39 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var SearchRequest;
var EqualityFilter;
var dn;
///--- Tests
test('load library', function (t) {
SearchRequest = require('../../lib/index').SearchRequest;
EqualityFilter = require('../../lib/index').EqualityFilter;
dn = require('../../lib/index').dn;
t.ok(SearchRequest);
t.ok(EqualityFilter);
t.ok(dn);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { SearchRequest, EqualityFilter, dn } = require('../../lib');
test('new no args', function (t) {
t.ok(new SearchRequest());
t.end();
});
test('new with args', function (t) {
var req = new SearchRequest({
const req = new SearchRequest({
baseObject: dn.parse('cn=foo, o=test'),
filter: new EqualityFilter({
attribute: 'email',
@ -50,14 +27,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var f = new EqualityFilter({
const f = new EqualityFilter({
attribute: 'email',
value: 'foo@bar.com'
});
var ber = new BerWriter();
let ber = new BerWriter();
ber.writeString('cn=foo, o=test');
ber.writeEnumeration(0);
ber.writeEnumeration(0);
@ -66,7 +42,7 @@ test('parse', function (t) {
ber.writeBoolean(false);
ber = f.toBer(ber);
var req = new SearchRequest();
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');
@ -79,9 +55,8 @@ test('parse', function (t) {
t.end();
});
test('toBer', function (t) {
var req = new SearchRequest({
const req = new SearchRequest({
messageID: 123,
baseObject: dn.parse('cn=foo, o=test'),
scope: 1,
@ -98,7 +73,7 @@ test('toBer', function (t) {
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,34 +1,16 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var SearchResponse;
///--- Tests
test('load library', function (t) {
SearchResponse = require('../../lib/index').SearchResponse;
t.ok(SearchResponse);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { SearchResponse } = require('../../lib');
test('new no args', function (t) {
t.ok(new SearchResponse());
t.end();
});
test('new with args', function (t) {
var res = new SearchResponse({
const res = new SearchResponse({
messageID: 123,
status: 0
});
@ -38,14 +20,13 @@ test('new with args', function (t) {
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
ber.writeEnumeration(0);
ber.writeString('cn=root');
ber.writeString('foo');
var res = new SearchResponse();
const res = new SearchResponse();
t.ok(res._parse(new BerReader(ber.buffer)));
t.equal(res.status, 0);
t.equal(res.matchedDN, 'cn=root');
@ -55,7 +36,7 @@ test('parse', function (t) {
test('toBer', function (t) {
var res = new SearchResponse({
const res = new SearchResponse({
messageID: 123,
status: 3,
matchedDN: 'cn=root',
@ -63,7 +44,7 @@ test('toBer', function (t) {
});
t.ok(res);
var ber = new BerReader(res.toBer());
const ber = new BerReader(res.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,55 +1,35 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
var asn1 = require('asn1');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
var UnbindRequest;
///--- Tests
test('load library', function (t) {
UnbindRequest = require('../../lib/index').UnbindRequest;
t.ok(UnbindRequest);
t.end();
});
'use strict';
const { test } = require('tap');
const { BerReader, BerWriter } = require('asn1');
const { UnbindRequest } = require('../../lib');
test('new no args', function (t) {
t.ok(new UnbindRequest());
t.end();
});
test('new with args', function (t) {
var req = new UnbindRequest({});
const req = new UnbindRequest({});
t.ok(req);
t.end();
});
test('parse', function (t) {
var ber = new BerWriter();
const ber = new BerWriter();
var req = new UnbindRequest();
const req = new UnbindRequest();
t.ok(req._parse(new BerReader(ber.buffer)));
t.end();
});
test('toBer', function (t) {
var req = new UnbindRequest({
const req = new UnbindRequest({
messageID: 123
});
t.ok(req);
var ber = new BerReader(req.toBer());
const ber = new BerReader(req.toBer());
t.ok(ber);
t.equal(ber.readSequence(), 0x30);
t.equal(ber.readInt(), 123);

View File

@ -1,38 +1,12 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
'use strict';
var logger = Object.create(require('abstract-logging'));
const tap = require('tap');
const vasync = require('vasync');
const { getSock } = require('./utils');
const ldap = require('../lib');
var fs = require('fs')
var tap = require('tap');
var uuid = require('uuid');
var vasync = require('vasync');
///--- Globals
var BIND_DN = 'cn=root';
var BIND_PW = 'secret';
var SUFFIX = 'dc=test';
var SERVER_PORT = process.env.SERVER_PORT || 1389;
var ldap;
var Attribute;
var Change;
var client;
var server;
var sock;
function getSock() {
if (process.platform === 'win32') {
return '\\\\.\\pipe\\' + uuid();
} else {
return '/tmp/.' + uuid();
}
}
///--- Tests
const SERVER_PORT = process.env.SERVER_PORT || 1389;
const SUFFIX = 'dc=test';
tap.beforeEach(function (done, t) {
// We do not need a `.afterEach` to clean up the sock files because that
@ -41,12 +15,6 @@ tap.beforeEach(function (done, t) {
done()
})
tap.test('load library', function (t) {
ldap = require('../lib/index');
t.ok(ldap.createServer);
t.end();
});
tap.test('basic create', function (t) {
const server = ldap.createServer();
t.ok(server);
@ -66,49 +34,42 @@ tap.test('properties', function (t) {
server.listen(0, 'localhost', function () {
t.ok(server.url);
server.close();
t.end();
server.close(() => t.end());
});
});
tap.test('listen on unix/named socket', function (t) {
t.plan(2);
const server = ldap.createServer();
server.listen(t.context.sock, function () {
t.ok(server.url);
t.equal(server.url.split(':')[0], 'ldapi');
server.close();
t.end();
server.close(() => t.end());
});
});
tap.test('listen on static port', function (t) {
t.plan(2);
const server = ldap.createServer();
server.listen(SERVER_PORT, '127.0.0.1', function () {
var addr = server.address();
const addr = server.address();
t.equal(addr.port, parseInt(SERVER_PORT, 10));
t.equals(server.url, 'ldap://127.0.0.1:' + SERVER_PORT);
server.close();
t.end();
t.equals(server.url, `ldap://127.0.0.1:${SERVER_PORT}`);
server.close(() => t.end());
});
});
tap.test('listen on ephemeral port', function (t) {
t.plan(2);
const server = ldap.createServer();
server.listen(0, 'localhost', function () {
var addr = server.address();
const addr = server.address();
t.ok(addr.port > 0);
t.ok(addr.port < 65535);
server.close();
t.end();
server.close(() => t.end());
});
});
tap.test('route order', function (t) {
function generateHandler(response) {
var func = function handler(req, res, next) {
const func = function handler(req, res, next) {
res.send({
dn: response,
attributes: { }
@ -119,11 +80,11 @@ tap.test('route order', function (t) {
return func;
}
server = ldap.createServer();
sock = getSock();
var dnShort = SUFFIX;
var dnMed = 'dc=sub, ' + SUFFIX;
var dnLong = 'dc=long, dc=sub, ' + SUFFIX;
const server = ldap.createServer();
const sock = t.context.sock;
const dnShort = SUFFIX;
const dnMed = 'dc=sub, ' + SUFFIX;
const dnLong = 'dc=long, dc=sub, ' + SUFFIX;
// Mount routes out of order
server.search(dnMed, generateHandler(dnMed));
@ -131,10 +92,21 @@ tap.test('route order', function (t) {
server.search(dnLong, generateHandler(dnLong));
server.listen(sock, function () {
t.ok(true, 'server listen');
client = ldap.createClient({ socketPath: sock });
const client = ldap.createClient({ socketPath: sock });
client.on('connect', () => {
vasync.forEachParallel({
'func': runSearch,
'inputs': [dnShort, dnMed, dnLong]
}, function (err, results) {
t.error(err);
client.unbind();
server.close(() => t.end());
});
})
function runSearch(value, cb) {
client.search(value, '(objectclass=*)', function (err, res) {
t.ifError(err);
t.error(err);
t.ok(res);
res.on('searchEntry', function (entry) {
t.equal(entry.dn.toString(), value);
@ -144,23 +116,13 @@ tap.test('route order', function (t) {
});
});
}
vasync.forEachParallel({
'func': runSearch,
'inputs': [dnShort, dnMed, dnLong]
}, function (err, results) {
t.notOk(err);
client.unbind();
server.close();
t.end();
});
});
});
tap.test('route absent', function (t) {
const server = ldap.createServer();
var DN_ROUTE = 'dc=base';
var DN_MISSING = 'dc=absent';
const DN_ROUTE = 'dc=base';
const DN_MISSING = 'dc=absent';
server.bind(DN_ROUTE, function (req, res, next) {
res.end();
@ -170,9 +132,9 @@ tap.test('route absent', function (t) {
server.listen(t.context.sock, function () {
t.ok(true, 'server startup');
vasync.parallel({
'funcs': [
funcs: [
function presentBind(cb) {
var clt = ldap.createClient({ socketPath: t.context.sock });
const clt = ldap.createClient({ socketPath: t.context.sock });
clt.bind(DN_ROUTE, '', function (err) {
t.notOk(err);
clt.unbind();
@ -180,7 +142,7 @@ tap.test('route absent', function (t) {
});
},
function absentBind(cb) {
var clt = ldap.createClient({ socketPath: t.context.sock });
const clt = ldap.createClient({ socketPath: t.context.sock });
clt.bind(DN_MISSING, '', function (err) {
t.ok(err);
t.equal(err.code, ldap.LDAP_NO_SUCH_OBJECT);
@ -191,14 +153,12 @@ tap.test('route absent', function (t) {
]
}, function (err, result) {
t.notOk(err);
server.close();
t.end();
server.close(() => t.end());
});
});
});
tap.test('route unbind', function (t) {
t.plan(4);
const server = ldap.createServer();
server.unbind(function (req, res, next) {
@ -209,23 +169,22 @@ tap.test('route unbind', function (t) {
server.listen(t.context.sock, function () {
t.ok(true, 'server startup');
client = ldap.createClient({ socketPath: t.context.sock });
const client = ldap.createClient({ socketPath: t.context.sock });
client.bind('', '', function (err) {
t.ifError(err, 'client bind error');
t.error(err, 'client bind error');
client.unbind(function (err) {
t.ifError(err, 'client unbind error');
server.close();
t.end();
t.error(err, 'client unbind error');
server.close(() => t.end());
});
});
});
});
tap.test('strict routing', function (t) {
var testDN = 'cn=valid';
var clt;
var server;
var sock = t.context.sock;
const testDN = 'cn=valid';
let clt;
let server;
const sock = t.context.sock;
vasync.pipeline({
funcs: [
function setup(_, cb) {
@ -251,7 +210,7 @@ tap.test('strict routing', function (t) {
},
function testBad(_, cb) {
clt.search('not a dn', {scope: 'base'}, function (err, res) {
t.ifError(err);
t.error(err);
res.once('error', function (err2) {
t.ok(err2);
t.equal(err2.code, ldap.LDAP_INVALID_DN_SYNTAX);
@ -265,9 +224,9 @@ tap.test('strict routing', function (t) {
},
function testGood(_, cb) {
clt.search(testDN, {scope: 'base'}, function (err, res) {
t.ifError(err);
t.error(err);
res.once('error', function (err2) {
t.ifError(err2);
t.error(err2);
cb(err2);
});
res.once('end', function (result) {
@ -281,8 +240,7 @@ tap.test('strict routing', function (t) {
if (clt) {
clt.destroy();
}
server.close();
t.end();
server.close(() => t.end());
});
});
@ -290,7 +248,7 @@ tap.test('non-strict routing', function (t) {
const server = ldap.createServer({
strictDN: false
});
var testDN = 'this ain\'t a DN';
const testDN = 'this ain\'t a DN';
// invalid DNs go to default handler
server.search('', function (req, res, next) {
@ -303,16 +261,15 @@ tap.test('non-strict routing', function (t) {
server.listen(t.context.sock, function () {
t.ok(true, 'server startup');
var clt = ldap.createClient({
const clt = ldap.createClient({
socketPath: t.context.sock,
strictDN: false
});
clt.search(testDN, {scope: 'base'}, function (err, res) {
t.ifError(err);
t.error(err);
res.on('end', function () {
clt.destroy();
server.close();
t.end();
server.close(() => t.end());
});
});
});
@ -321,15 +278,20 @@ tap.test('non-strict routing', function (t) {
tap.test('close accept a callback', function (t) {
const server = ldap.createServer();
// callback is called when the server is closed
server.close(function(err){
t.end();
});
server.listen(0, function(err) {
t.error(err);
server.close(function(err){
t.error(err)
t.end();
});
})
});
tap.test('close without error calls callback', function (t) {
const server = ldap.createServer();
// when the server is closed without error, the callback parameter is undefined
server.listen(1389,'127.0.0.1',function(err){
t.error(err);
server.close(function(err){
t.error(err);
t.end();

View File

@ -1,28 +1,10 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
///--- Globals
var url;
var parseURL;
///--- Tests
test('load library', function (t) {
parseURL = require('../lib/index').parseURL;
t.ok(parseURL);
t.end();
});
'use strict';
const { test } = require('tap');
const { parseURL } = require('../lib');
test('parse empty', function (t) {
var u = parseURL('ldap:///');
const u = parseURL('ldap:///');
t.equal(u.hostname, 'localhost');
t.equal(u.port, 389);
t.ok(!u.DN);
@ -33,7 +15,7 @@ test('parse empty', function (t) {
test('parse hostname', function (t) {
var u = parseURL('ldap://example.com/');
const u = parseURL('ldap://example.com/');
t.equal(u.hostname, 'example.com');
t.equal(u.port, 389);
t.ok(!u.DN);
@ -44,7 +26,7 @@ test('parse hostname', function (t) {
test('parse host and port', function (t) {
var u = parseURL('ldap://example.com:1389/');
const u = parseURL('ldap://example.com:1389/');
t.equal(u.hostname, 'example.com');
t.equal(u.port, 1389);
t.ok(!u.DN);
@ -56,7 +38,7 @@ test('parse host and port', function (t) {
test('parse full', function (t) {
var u = parseURL('ldaps://ldap.example.com:1389/dc=example%20,dc=com' +
const u = parseURL('ldaps://ldap.example.com:1389/dc=example%20,dc=com' +
'?cn,sn?sub?(cn=Babs%20Jensen)');
t.equal(u.secure, true);

17
test/utils.js Normal file
View File

@ -0,0 +1,17 @@
'use strict';
const os = require('os');
const path = require('path');
const uuid = require('uuid');
function getSock() {
if (process.platform === 'win32') {
return '\\\\.\\pipe\\' + uuid();
} else {
return path.join(os.tmpdir(), uuid());
}
}
module.exports = {
getSock
}