Skip to content

Commit 832cbc9

Browse files
committed
fix: simple query
1 parent 3736a06 commit 832cbc9

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

src/service-ldap.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class ServiceLDAP extends Service {
2323
attributes: {
2424
bindDN: {
2525
type: "string"
26-
},
26+
},
2727
base: {
2828
type: "string"
2929
},
@@ -62,9 +62,9 @@ export class ServiceLDAP extends Service {
6262
await this.start();
6363

6464
try {
65-
await this.client.bind(this.bindDN);
66-
const { entries } = await this.client.search(query.base, query.options);
67-
return entries;
65+
await this.client.bind(query.bindDN, query.password);
66+
return await this.client.search(query.base, query);
67+
// return entries;
6868
} finally {
6969
await this.client.unbind();
7070
}

tests/fixtures/ldap/base.ldif

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ dn: cn=konsum,ou=groups,dc=example,dc=com
3838
cn: konsum
3939
objectclass: groupOfUniqueNames
4040
uniqueMember: uid=user1,ou=accounts,dc=example,dc=com
41+
42+
dn: cn=service1,ou=groups,dc=example,dc=com
43+
cn: service1
44+
objectclass: groupOfUniqueNames
45+
46+
dn: cn=service2,ou=groups,dc=example,dc=com
47+
cn: service2
48+
objectclass: groupOfUniqueNames

tests/query-test.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import test from "ava";
2+
import { StandaloneServiceProvider } from "@kronos-integration/service";
3+
import { ServiceLDAP } from "../src/service-ldap.mjs";
4+
5+
const config = {
6+
type: ServiceLDAP,
7+
url: "ldap://localhost:3389",
8+
bindDN: "ou=accounts,dc=example,dc=com"
9+
};
10+
11+
test("service-ldap search", async t => {
12+
const sp = new StandaloneServiceProvider();
13+
const ldap = await sp.declareService(config);
14+
await ldap.start();
15+
t.is(ldap.state, "running");
16+
17+
t.deepEqual(
18+
(
19+
await ldap.search({
20+
bindDN: "uid=user1,ou=accounts,dc=example,dc=com",
21+
password: "test",
22+
base: "ou=groups,dc=example,dc=com",
23+
scope: "sub",
24+
attributes: ["cn"],
25+
filter: "(objectclass=groupOfUniqueNames)"
26+
})
27+
).searchEntries,
28+
[{ cn: "konsum", dn: "cn=konsum,ou=groups,dc=example,dc=com" }]
29+
);
30+
});

tests/start-local-ldap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ case $(uname) in
1717
esac
1818

1919

20-
${SLAPD} -f ${SLAPD_CONF} -h ldap://localhost:3389 -d 9 &
20+
${SLAPD} -f ${SLAPD_CONF} -h ldap://localhost:3389 -d 1 &
2121
ldapadd -h localhost:3389 -D cn=Manager,dc=example,dc=com -w test -f tests/fixtures/ldap/base.ldif

0 commit comments

Comments
 (0)