Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 1f12eca

Browse files
authored
Add integration tests (#571)
* Initial integration test, um, test * Hack in service * Add integration test for issue #480 * Add fix for issue #418 * Add fix for issue #370
1 parent 0ccbec6 commit 1f12eca

File tree

8 files changed

+149
-3
lines changed

8 files changed

+149
-3
lines changed

.github/workflows/integration.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: 'Integration Tests'
2+
3+
# Notes:
4+
# https://github.community/t5/GitHub-Actions/Github-Actions-services-not-reachable/m-p/30739/highlight/true#M538
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- master
10+
- next
11+
12+
jobs:
13+
baseline:
14+
name: Baseline Tests
15+
runs-on: ubuntu-latest
16+
17+
# services:
18+
# openldap:
19+
# image: docker.pkg.github.com/ldapjs/docker-test-openldap/openldap:1.0
20+
# ports:
21+
# - 389:389
22+
# - 636:636
23+
24+
steps:
25+
- uses: actions/checkout@v1
26+
- uses: actions/setup-node@v1
27+
28+
# Hack way to start service since GitHub doesn't integrate with its own services
29+
- name: Docker login
30+
run: docker login docker.pkg.github.com -u ${GITHUB_ACTOR} -p ${GITHUB_TOKEN}
31+
env:
32+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
33+
- name: Pull Docker image
34+
run: docker pull "docker.pkg.github.com/ldapjs/docker-test-openldap/openldap:1.0"
35+
- name: Start OpenLDAP service
36+
run: docker run -it -d --name openldap -p 389:389 -p 636:636 docker.pkg.github.com/ldapjs/docker-test-openldap/openldap:1.0
37+
38+
- name: Install Packages
39+
run: npm install
40+
- name: Run Tests
41+
run: npm run test:integration

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3'
2+
3+
services:
4+
openldap:
5+
image: docker.pkg.github.com/ldapjs/docker-test-openldap/openldap:1.0
6+
ports:
7+
- 389:389
8+
- 636:636

lib/client/client.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,8 @@ Client.prototype.exop = function exop (name, value, controls, callback) {
369369
if (typeof (value) === 'function') {
370370
callback = value
371371
controls = []
372-
value = ''
372+
value = undefined
373373
}
374-
if (!(Buffer.isBuffer(value) || typeof (value) === 'string')) { throw new TypeError('value (Buffer || string) required') }
375374
if (typeof (controls) === 'function') {
376375
callback = controls
377376
controls = []

lib/url.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ const filter = require('./filters/')
88
module.exports = {
99

1010
parse: function (urlStr, parseDN) {
11-
const parsedURL = new url.URL(urlStr)
11+
let parsedURL
12+
try {
13+
parsedURL = new url.URL(urlStr)
14+
} catch (error) {
15+
throw new TypeError(urlStr + ' is an invalid LDAP url (scope)')
16+
}
17+
1218
if (!parsedURL.protocol || !(parsedURL.protocol === 'ldap:' || parsedURL.protocol === 'ldaps:')) { throw new TypeError(urlStr + ' is an invalid LDAP url (protocol)') }
1319

1420
const u = {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"test:cov": "tap",
4040
"test:cov:html": "tap --coverage-report=html",
4141
"test:watch": "tap -n -w --no-coverage-report",
42+
"test:integration": "tap --no-cov 'test-integration/**/*.test.js'",
43+
"test:integration:local": "docker-compose up -d && npm run test:integration && docker-compose down",
4244
"lint": "standard | snazzy",
4345
"lint:ci": "standard"
4446
},
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
const tap = require('tap')
4+
const ldapjs = require('../../lib')
5+
6+
const SCHEME = process.env.SCHEME || 'ldap'
7+
const HOST = process.env.HOST || '127.0.0.1'
8+
const PORT = process.env.PORT || 389
9+
10+
const baseURL = `${SCHEME}://${HOST}:${PORT}`
11+
12+
tap.test('connects to a server', t => {
13+
t.plan(2)
14+
15+
const client = ldapjs.createClient({ url: baseURL })
16+
client.bind('cn=Philip J. Fry,ou=people,dc=planetexpress,dc=com', 'fry', (err) => {
17+
t.error(err)
18+
t.pass()
19+
client.unbind()
20+
})
21+
})
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict'
2+
3+
const tap = require('tap')
4+
const ldapjs = require('../../lib')
5+
6+
const SCHEME = process.env.SCHEME || 'ldap'
7+
const HOST = process.env.HOST || '127.0.0.1'
8+
const PORT = process.env.PORT || 389
9+
10+
const baseURL = `${SCHEME}://${HOST}:${PORT}`
11+
12+
tap.test('modifyDN with long name (issue #480)', t => {
13+
const longStr = 'a292979f2c86d513d48bbb9786b564b3c5228146e5ba46f404724e322544a7304a2b1049168803a5485e2d57a544c6a0d860af91330acb77e5907a9e601ad1227e80e0dc50abe963b47a004f2c90f570450d0e920d15436fdc771e3bdac0487a9735473ed3a79361d1778d7e53a7fb0e5f01f97a75ef05837d1d5496fc86968ff47fcb64'
14+
const targetDN = 'cn=Turanga Leela,ou=people,dc=planetexpress,dc=com'
15+
const client = ldapjs.createClient({ url: baseURL })
16+
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', bindHandler)
17+
18+
function bindHandler (err) {
19+
t.error(err)
20+
client.modifyDN(
21+
targetDN,
22+
`cn=${longStr},ou=people,dc=planetexpress,dc=com`,
23+
modifyHandler
24+
)
25+
}
26+
27+
function modifyHandler (err, res) {
28+
t.error(err)
29+
t.ok(res)
30+
t.equal(res.status, 0)
31+
32+
client.modifyDN(
33+
`cn=${longStr},ou=people,dc=planetexpress,dc=com`,
34+
targetDN,
35+
(err, res) => {
36+
t.error(err)
37+
client.unbind(t.end)
38+
}
39+
)
40+
}
41+
})
42+
43+
tap.test('whois works correctly (issue #370)', t => {
44+
const client = ldapjs.createClient({ url: baseURL })
45+
client.bind('cn=Philip J. Fry,ou=people,dc=planetexpress,dc=com', 'fry', (err) => {
46+
t.error(err)
47+
48+
client.exop('1.3.6.1.4.1.4203.1.11.3', (err, value, res) => {
49+
t.error(err)
50+
t.ok(value)
51+
t.is(value, 'dn:cn=Philip J. Fry,ou=people,dc=planetexpress,dc=com')
52+
t.ok(res)
53+
t.is(res.status, 0)
54+
55+
client.unbind(t.end)
56+
})
57+
})
58+
})

test/client.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,17 @@ tap.test('createClient', t => {
368368
)
369369
})
370370

371+
tap.test('exception from bad createClient parameter (issue #418)', t => {
372+
try {
373+
// This port number is totally invalid. It will cause the URL parser
374+
// to throw an exception that should be caught.
375+
ldap.createClient({ url: 'ldap://127.0.0.1:13891389' })
376+
} catch (error) {
377+
t.ok(error)
378+
t.end()
379+
}
380+
})
381+
371382
// TODO: this test is really flaky. It would be better if we could validate
372383
// the options _withouth_ having to connect to a server.
373384
// t.test('attaches a child function to logger', async t => {

0 commit comments

Comments
 (0)