Skip to content

Commit

Permalink
fix: return empty list with no matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Jun 28, 2024
1 parent 7bf2e11 commit 416015e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getUsers = async (ctx: Context, name?: string): Promise<any[]> => {
}).catch(() => UserListResponse.fromPartial({}));

if (!userList || !userList.items || userList.items.length === 0) {
return;
return [];
}

const allRoles = await ctx.roleClient.read({
Expand Down Expand Up @@ -78,7 +78,7 @@ export const getGroups = async (ctx: Context, name?: string): Promise<any[]> =>
}

if (!roleList || !roleList.items || roleList.items.length === 0) {
return;
return [];
}

const allUsers = await ctx.userClient.read({
Expand Down
26 changes: 26 additions & 0 deletions test/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ describe('search', () => {
values: ['John Doe']
});
});

it('should not find a missing user', async () => {
const response = await new Promise<SearchResponse>(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', () => {
Expand Down Expand Up @@ -262,5 +275,18 @@ describe('search', () => {
]
});
});

it('should not find a missing group', async () => {
const response = await new Promise<SearchResponse>(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);
});
});
});

0 comments on commit 416015e

Please sign in to comment.