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
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('load library', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
dn = require('../lib/index').dn;
|
|
|
|
t.ok(dn);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
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);
|
2012-02-18 08:15:52 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
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);
|
2012-02-18 08:15:52 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
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);
|
2012-02-18 08:15:52 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
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);
|
2012-02-18 08:15:52 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +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();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
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();
|
|
|
|
});
|
2011-09-23 15:54:48 +00:00
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('empty DNs GH-16', function (t) {
|
2011-09-23 15:54:48 +00:00
|
|
|
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();
|
|
|
|
});
|
2011-09-29 21:46:10 +00:00
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('case insensitive attribute names GH-20', function (t) {
|
2011-09-29 21:46:10 +00:00
|
|
|
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();
|
|
|
|
});
|