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

Commit a433489

Browse files
authored
Add integration test for PasswordPolicyControl (#949)
1 parent bec2ff8 commit a433489

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed

.github/workflows/integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
services:
2222
openldap:
23-
image: ghcr.io/ldapjs/docker-test-openldap/openldap:2023-08-15
23+
image: ghcr.io/ldapjs/docker-test-openldap/openldap:2023-10-30
2424
ports:
2525
- 389:389
2626
- 636:636

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
openldap:
3-
image: ghcr.io/ldapjs/docker-test-openldap/openldap:2023-08-15
3+
image: ghcr.io/ldapjs/docker-test-openldap/openldap:2023-10-30
44
ports:
55
- 389:389
66
- 636:636

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"@ldapjs/asn1": "^2.0.0",
1515
"@ldapjs/attribute": "^1.0.0",
1616
"@ldapjs/change": "^1.0.0",
17-
"@ldapjs/controls": "^2.0.0",
17+
"@ldapjs/controls": "^2.1.0",
1818
"@ldapjs/dn": "^1.1.0",
1919
"@ldapjs/filter": "^2.1.1",
20-
"@ldapjs/messages": "^1.2.1",
20+
"@ldapjs/messages": "^1.3.0",
2121
"@ldapjs/protocol": "^1.2.1",
2222
"abstract-logging": "^2.0.1",
2323
"assert-plus": "^1.0.0",
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
const baseURL = `${SCHEME}://${HOST}:${PORT}`
10+
11+
tap.test('can use password policy response', t => {
12+
const client = ldapjs.createClient({ url: baseURL })
13+
const targetDN = 'cn=Bender Bending Rodríguez,ou=people,dc=planetexpress,dc=com'
14+
15+
client.bind('cn=admin,dc=planetexpress,dc=com', 'GoodNewsEveryone', (err, res) => {
16+
t.error(err)
17+
t.ok(res)
18+
t.equal(res.status, 0)
19+
20+
const newPassword = 'bender2'
21+
changePassword(client, newPassword, () => {
22+
client.unbind()
23+
bindNewClient(newPassword, { error: 2 }, (client) => {
24+
const newPassword = 'bender'
25+
changePassword(client, newPassword, () => {
26+
client.unbind()
27+
bindNewClient(newPassword, { timeBeforeExpiration: 1000 }, (client) => {
28+
client.unbind(t.end)
29+
})
30+
})
31+
})
32+
})
33+
})
34+
35+
function bindNewClient (pwd, expected, callback) {
36+
const client = ldapjs.createClient({ url: baseURL })
37+
const control = new ldapjs.PasswordPolicyControl()
38+
39+
client.bind(targetDN, pwd, control, (err, res) => {
40+
t.error(err)
41+
t.ok(res)
42+
t.equal(res.status, 0)
43+
44+
let error = null
45+
let timeBeforeExpiration = null
46+
let graceAuthNsRemaining = null
47+
48+
res.controls.forEach(control => {
49+
if (control.type === ldapjs.PasswordPolicyControl.OID) {
50+
error = control.value.error ?? error
51+
timeBeforeExpiration = control.value.timeBeforeExpiration ?? timeBeforeExpiration
52+
graceAuthNsRemaining = control.value.graceAuthNsRemaining ?? graceAuthNsRemaining
53+
}
54+
})
55+
56+
if (expected.error !== undefined) {
57+
t.equal(error, expected.error)
58+
}
59+
if (expected.timeBeforeExpiration !== undefined) {
60+
t.equal(timeBeforeExpiration, expected.timeBeforeExpiration)
61+
}
62+
if (expected.graceAuthNsRemaining !== undefined) {
63+
t.equal(graceAuthNsRemaining, expected.graceAuthNsRemaining)
64+
}
65+
66+
callback(client)
67+
})
68+
}
69+
70+
function changePassword (client, newPwd, callback) {
71+
const change = new ldapjs.Change({
72+
operation: 'replace',
73+
modification: new ldapjs.Attribute({
74+
type: 'userPassword',
75+
values: newPwd
76+
})
77+
})
78+
79+
client.modify(targetDN, change, (err, res) => {
80+
t.error(err)
81+
t.ok(res)
82+
t.equal(res.status, 0)
83+
84+
callback()
85+
})
86+
}
87+
})

0 commit comments

Comments
 (0)