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

Commit ac588a0

Browse files
committed
Add integration test for issue #923
1 parent 1cc6a73 commit ac588a0

File tree

4 files changed

+100
-5
lines changed

4 files changed

+100
-5
lines changed

.github/workflows/integration.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ jobs:
2020

2121
services:
2222
openldap:
23-
image: ghcr.io/ldapjs/docker-test-openldap/openldap:latest
23+
image: ghcr.io/ldapjs/docker-test-openldap/openldap:2023-03-18
2424
ports:
2525
- 389:389
2626
- 636:636
27+
options: >
28+
--health-cmd "ldapsearch -Y EXTERNAL -Q -H ldapi:// -b ou=people,dc=planetexpress,dc=com -LLL '(cn=Turanga Leela)' cn"
2729
2830
steps:
2931
- uses: actions/checkout@v3

docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
version: '3'
2-
31
services:
42
openldap:
5-
image: ghcr.io/ldapjs/docker-test-openldap/openldap:latest
3+
image: ghcr.io/ldapjs/docker-test-openldap/openldap:2023-03-18
64
ports:
75
- 389:389
86
- 636:636
7+
healthcheck:
8+
start_period: 3s
9+
test: >
10+
/usr/bin/ldapsearch -Y EXTERNAL -Q -H ldapi:// -b ou=people,dc=planetexpress,dc=com -LLL '(cn=Turanga Leela)' cn 1>/dev/null

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"test:cov:html": "tap --coverage-report=html -R terse",
4848
"test:watch": "tap -n -w --no-coverage-report -R terse",
4949
"test:integration": "tap --no-cov -R terse 'test-integration/**/*.test.js'",
50-
"test:integration:local": "docker-compose up -d && npm run test:integration && docker-compose down",
50+
"test:integration:local": "docker-compose up -d --wait && npm run test:integration ; docker-compose down",
5151
"lint": "eslint . --fix",
5252
"lint:ci": "eslint .",
5353
"docs": "node scripts/build-docs.js"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict'
2+
3+
const tap = require('tap')
4+
const ldapjs = require('../../lib')
5+
const { DN } = require('@ldapjs/dn')
6+
const Change = require('@ldapjs/change')
7+
8+
const SCHEME = process.env.SCHEME || 'ldap'
9+
const HOST = process.env.HOST || '127.0.0.1'
10+
const PORT = process.env.PORT || 389
11+
const baseURL = `${SCHEME}://${HOST}:${PORT}`
12+
13+
const client = ldapjs.createClient({ url: baseURL })
14+
15+
tap.teardown(() => {
16+
client.unbind()
17+
})
18+
19+
tap.test('modifies entry specified by dn string', t => {
20+
t.plan(4)
21+
22+
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
23+
t.error(err, 'bind error')
24+
})
25+
26+
const dn = 'cn=large10,ou=large_ou,dc=planetexpress,dc=com'
27+
const change = new Change({
28+
operation: 'replace',
29+
modification: {
30+
type: 'givenName',
31+
values: ['test']
32+
}
33+
})
34+
35+
client.modify(dn, change, (err) => {
36+
t.error(err, 'modify error')
37+
validateChange({ t, expected: 'test', client })
38+
})
39+
})
40+
41+
tap.test('modifies entry specified by dn object', t => {
42+
t.plan(4)
43+
44+
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err) => {
45+
t.error(err, 'bind error')
46+
})
47+
48+
const dn = DN.fromString('cn=large10,ou=large_ou,dc=planetexpress,dc=com')
49+
const change = new Change({
50+
operation: 'replace',
51+
modification: {
52+
type: 'givenName',
53+
values: ['test2']
54+
}
55+
})
56+
57+
client.modify(dn, change, (err) => {
58+
t.error(err, 'modify error')
59+
validateChange({ t, expected: 'test2', client })
60+
})
61+
})
62+
63+
function validateChange ({ t, expected, client }) {
64+
const searchBase = 'ou=large_ou,dc=planetexpress,dc=com'
65+
const searchOpts = {
66+
filter: '(cn=large10)',
67+
scope: 'subtree',
68+
attributes: ['givenName'],
69+
sizeLimit: 10,
70+
timeLimit: 0
71+
}
72+
73+
client.search(searchBase, searchOpts, (err, res) => {
74+
t.error(err, 'search error')
75+
76+
res.on('searchEntry', entry => {
77+
t.equal(
78+
entry.attributes.filter(a => a.type === 'givenName').pop().values.pop(),
79+
expected
80+
)
81+
})
82+
83+
res.on('error', err => {
84+
t.error(err, 'search entry error')
85+
})
86+
87+
res.on('end', () => {
88+
t.end()
89+
})
90+
})
91+
}

0 commit comments

Comments
 (0)