diff --git a/src/external.ts b/src/external.ts index b9d5c8b..7efbb60 100644 --- a/src/external.ts +++ b/src/external.ts @@ -11,7 +11,7 @@ export const getUsers = async (ctx: Context, name?: string): Promise => { }).catch(() => UserListResponse.fromPartial({})); if (!userList || !userList.items || userList.items.length === 0) { - return; + return []; } const allRoles = await ctx.roleClient.read({ @@ -78,7 +78,7 @@ export const getGroups = async (ctx: Context, name?: string): Promise => } if (!roleList || !roleList.items || roleList.items.length === 0) { - return; + return []; } const allUsers = await ctx.userClient.read({ diff --git a/test/base.test.ts b/test/base.test.ts index b2c8117..7bc911a 100644 --- a/test/base.test.ts +++ b/test/base.test.ts @@ -224,6 +224,19 @@ describe('search', () => { values: ['John Doe'] }); }); + + it('should not find a missing user', async () => { + const response = await new Promise(r => { + const client = getClient(true); + client.search('cn=Mary,ou=users,' + server.cfg.get('ldap:base_dn'), {}, async (err, res) => { + r(await readResponse(res)); + }) + }); + + expect(response.error).toBe(undefined); + expect(response.entries).not.toBe(undefined); + expect(response.entries).lengthOf(0); + }); }); describe('group', () => { @@ -262,5 +275,18 @@ describe('search', () => { ] }); }); + + it('should not find a missing group', async () => { + const response = await new Promise(r => { + const client = getClient(true); + client.search('cn=Builder,ou=groups,' + server.cfg.get('ldap:base_dn'), {}, async (err, res) => { + r(await readResponse(res)); + }) + }); + + expect(response.error).toBe(undefined); + expect(response.entries).not.toBe(undefined); + expect(response.entries).lengthOf(0); + }); }); });