wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict'
 
const { test } = require('tap')
const { parseURL } = require('../lib')
 
test('parse empty', function (t) {
  const u = parseURL('ldap:///')
  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()
})
 
test('parse hostname', function (t) {
  const u = parseURL('ldap://example.com/')
  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()
})
 
test('parse host and port', function (t) {
  const u = parseURL('ldap://example.com:1389/')
  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()
})
 
test('parse full', function (t) {
  const u = parseURL('ldaps://ldap.example.com:1389/dc=example%20,dc=com' +
                    '?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')
  t.equal(u.filter.toString(), '(cn=Babs Jensen)')
 
  t.end()
})
 
test('supports href', function (t) {
  const u = parseURL('ldaps://ldap.example.com:1389/dc=example%20,dc=com?cn,sn?sub?(cn=Babs%20Jensen)')
  t.equal(u.href, 'ldaps://ldap.example.com:1389/dc=example%20,dc=com?cn,sn?sub?(cn=Babs%20Jensen)')
  t.end()
})