Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Fix null role response from users fetch (#871) (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa authored Jun 7, 2022
1 parent d4e2a99 commit bbb35a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/teleport/src/services/user/makeUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 Gravitational, Inc.
* Copyright 2020-2022 Gravitational, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@ export default function makeUser(json): User {
const [name, roles, authType] = at(json, ['name', 'roles', 'authType']);
return {
name,
roles,
roles: roles || [],
authType: authType === 'local' ? 'teleport local user' : authType,
isLocal: authType === 'local',
};
Expand Down
14 changes: 10 additions & 4 deletions packages/teleport/src/services/user/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 Gravitational, Inc.
* Copyright 2020-2022 Gravitational, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -170,9 +170,15 @@ test('undefined values in context response gives proper default values', async (
});
});

test('fetch users, null response gives empty array', async () => {
test('fetch users, null response values gives empty array', async () => {
jest.spyOn(api, 'get').mockResolvedValue(null);

const response = await user.fetchUsers();
let response = await user.fetchUsers();
expect(response).toStrictEqual([]);

jest.spyOn(api, 'get').mockResolvedValue([{ name: '', authType: '' }]);

response = await user.fetchUsers();
expect(response).toStrictEqual([
{ authType: '', isLocal: false, name: '', roles: [] },
]);
});

0 comments on commit bbb35a3

Please sign in to comment.