node-ldapjs/test/dn.test.js

146 lines
3.3 KiB
JavaScript
Raw Normal View History

2011-08-04 20:32:01 +00:00
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tap').test;
///--- Globals
var dn;
///--- Tests
test('load library', function (t) {
2011-08-04 20:32:01 +00:00
dn = require('../lib/index').dn;
t.ok(dn);
t.end();
});
test('parse basic', function (t) {
2011-08-04 20:32:01 +00:00
var DN_STR = 'cn=mark, ou=people, o=joyent';
var name = dn.parse(DN_STR);
t.ok(name);
t.ok(name.rdns);
t.ok(Array.isArray(name.rdns));
t.equal(3, name.rdns.length);
name.rdns.forEach(function (rdn) {
t.equal('object', typeof (rdn));
2011-08-04 20:32:01 +00:00
});
t.equal(name.toString(), DN_STR);
t.end();
});
test('parse escaped', function (t) {
2011-08-04 20:32:01 +00:00
var DN_STR = 'cn=m\\,ark, ou=people, o=joyent';
var name = dn.parse(DN_STR);
t.ok(name);
t.ok(name.rdns);
t.ok(Array.isArray(name.rdns));
t.equal(3, name.rdns.length);
name.rdns.forEach(function (rdn) {
t.equal('object', typeof (rdn));
2011-08-04 20:32:01 +00:00
});
t.equal(name.toString(), DN_STR);
t.end();
});
test('parse compound', function (t) {
2011-08-04 20:32:01 +00:00
var DN_STR = 'cn=mark+sn=cavage, ou=people, o=joyent';
var name = dn.parse(DN_STR);
t.ok(name);
t.ok(name.rdns);
t.ok(Array.isArray(name.rdns));
t.equal(3, name.rdns.length);
name.rdns.forEach(function (rdn) {
t.equal('object', typeof (rdn));
2011-08-04 20:32:01 +00:00
});
t.equal(name.toString(), DN_STR);
t.end();
});
test('parse quoted', function (t) {
2011-08-04 20:32:01 +00:00
var DN_STR = 'cn="mark+sn=cavage", ou=people, o=joyent';
var name = dn.parse(DN_STR);
t.ok(name);
t.ok(name.rdns);
t.ok(Array.isArray(name.rdns));
t.equal(3, name.rdns.length);
name.rdns.forEach(function (rdn) {
t.equal('object', typeof (rdn));
2011-08-04 20:32:01 +00:00
});
t.equal(name.toString(), DN_STR);
t.end();
});
2011-08-16 00:52:05 +00:00
test('equals', function (t) {
2011-08-16 00:52:05 +00:00
var 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')));
t.ok(!dn1.equals(dn.parse('cn=foo2, dc=bar')));
t.end();
});
test('child of', function (t) {
2011-08-16 00:52:05 +00:00
var 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'));
t.ok(!dn1.childOf('cn=foo, dc=bar'));
t.ok(dn1.childOf(dn.parse('dc=bar')));
t.end();
});
test('parent of', function (t) {
2011-08-16 00:52:05 +00:00
var 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'));
t.ok(dn1.parentOf(dn.parse('cn=moo, cn=foo, dc=bar')));
t.end();
});
test('empty DNs GH-16', function (t) {
var _dn = dn.parse('');
var _dn2 = dn.parse('cn=foo');
t.notOk(_dn.equals('cn=foo'));
t.notOk(_dn2.equals(''));
t.notOk(_dn.parentOf('cn=foo'));
t.notOk(_dn.childOf('cn=foo'));
t.notOk(_dn2.parentOf(''));
t.notOk(_dn2.childOf(''));
t.end();
});
test('case insensitive attribute names GH-20', function (t) {
var 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('rdn spacing', function (t) {
var dn1 = dn.parse('cn=foo,dc=bar');
var dn2 = dn.parse('cn=foo, dc=bar');
t.ok(dn1.equals(dn2));
t.equals(dn1.toString(), 'cn=foo,dc=bar');
t.equals(dn2.toString(), 'cn=foo, dc=bar');
t.equals(dn1.spaced().toString(), 'cn=foo, dc=bar');
t.equals(dn2.spaced(false).toString(), 'cn=foo,dc=bar');
t.end();
});