2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2019-08-27 13:08:00 +00:00
|
|
|
var test = require('tap').test;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var url;
|
2012-02-18 08:15:52 +00:00
|
|
|
var parseURL;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///--- Tests
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('load library', function (t) {
|
2011-08-19 22:08:23 +00:00
|
|
|
parseURL = require('../lib/index').parseURL;
|
|
|
|
t.ok(parseURL);
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse empty', function (t) {
|
2011-08-19 22:08:23 +00:00
|
|
|
var u = parseURL('ldap:///');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(u.hostname, 'localhost');
|
|
|
|
t.equal(u.port, 389);
|
|
|
|
t.ok(!u.DN);
|
|
|
|
t.ok(!u.attributes);
|
|
|
|
t.equal(u.secure, false);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse hostname', function (t) {
|
2011-08-19 22:08:23 +00:00
|
|
|
var u = parseURL('ldap://example.com/');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(u.hostname, 'example.com');
|
|
|
|
t.equal(u.port, 389);
|
|
|
|
t.ok(!u.DN);
|
|
|
|
t.ok(!u.attributes);
|
|
|
|
t.equal(u.secure, false);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse host and port', function (t) {
|
2011-08-19 22:08:23 +00:00
|
|
|
var u = parseURL('ldap://example.com:1389/');
|
2011-08-04 20:32:01 +00:00
|
|
|
t.equal(u.hostname, 'example.com');
|
|
|
|
t.equal(u.port, 1389);
|
|
|
|
t.ok(!u.DN);
|
|
|
|
t.ok(!u.attributes);
|
|
|
|
t.equal(u.secure, false);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
test('parse full', function (t) {
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2011-08-19 22:08:23 +00:00
|
|
|
var u = parseURL('ldaps://ldap.example.com:1389/dc=example%20,dc=com' +
|
2011-08-04 20:32:01 +00:00
|
|
|
'?cn,sn?sub?(cn=Babs%20Jensen)');
|
|
|
|
|
|
|
|
t.equal(u.secure, true);
|
|
|
|
t.equal(u.hostname, 'ldap.example.com');
|
|
|
|
t.equal(u.port, 1389);
|
|
|
|
t.equal(u.DN, 'dc=example ,dc=com');
|
|
|
|
t.ok(u.attributes);
|
|
|
|
t.equal(u.attributes.length, 2);
|
|
|
|
t.equal(u.attributes[0], 'cn');
|
|
|
|
t.equal(u.attributes[1], 'sn');
|
|
|
|
t.equal(u.scope, 'sub');
|
2012-02-21 01:21:53 +00:00
|
|
|
t.equal(u.filter.toString(), '(cn=Babs Jensen)');
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|