-
Notifications
You must be signed in to change notification settings - Fork 295
feat: (UI) Hide User/Profile API Key Features in UI if depending on parameter value BED-7137 #2418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c8e59e4
f78d12c
b9bd189
ea89eae
9ed14b9
0e4b4c1
551b160
67245f3
01b980c
b125504
8c1d6ec
e2390e8
063f5fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,126 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Copyright 2026 Specter Ops, Inc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Licensed under the Apache License, Version 2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import userEvent from '@testing-library/user-event'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ConfigurationKey } from 'js-client-library'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { rest } from 'msw'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { setupServer } from 'msw/node'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { render, screen } from '../../test-utils'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { noop } from '../../utils'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import UserActionsMenu from './UserActionsMenu'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const CONFIG_ENABLED_RESPONSE = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key: ConfigurationKey.APITokens, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enabled: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const CONFIG_DISABLED_RESPONSE = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key: ConfigurationKey.APITokens, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enabled: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type ComponentProps = React.ComponentProps<typeof UserActionsMenu>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const server = setupServer( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rest.get(`/api/v2/config`, async (_req, res, ctx) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return res(ctx.json(CONFIG_ENABLED_RESPONSE)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| beforeAll(() => server.listen()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| afterEach(() => server.resetHandlers()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| afterAll(() => server.close()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('Api Keys', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setup = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userId = '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onOpen = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showPasswordOptions = false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showAuthMgmtButtons = false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showDisableMfaButton = false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userDisabled = false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onUpdateUser = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onDisableUser = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onEnableUser = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onDeleteUser = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onUpdateUserPassword = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onExpireUserPassword = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onManageUserTokens = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onDisableUserMfa = noop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| index = 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } = {} as ComponentProps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const user = userEvent.setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const screen = render( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <UserActionsMenu | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userId={userId} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onOpen={onOpen} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showPasswordOptions={showPasswordOptions} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showAuthMgmtButtons={showAuthMgmtButtons} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showDisableMfaButton={showDisableMfaButton} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userDisabled={userDisabled} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onUpdateUser={onUpdateUser} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onDisableUser={onDisableUser} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onEnableUser={onEnableUser} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onDeleteUser={onDeleteUser} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onUpdateUserPassword={onUpdateUserPassword} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onExpireUserPassword={onExpireUserPassword} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onManageUserTokens={onManageUserTokens} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onDisableUserMfa={onDisableUserMfa} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| index={index} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { screen, user }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('should display generate/revoke api tokens button', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { user } = setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const button = screen.getByRole('button', { name: /show user actions/i }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await user.click(button); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await screen.findByRole('menuitem', { name: /generate \/ revoke api tokens/i }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('should not display generate/revoke api tokens button', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server.use( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rest.get(`/api/v2/config`, async (_req, res, ctx) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return res(ctx.json(CONFIG_DISABLED_RESPONSE)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { user } = setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const button = screen.getByRole('button', { name: /show user actions/i }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await user.click(button); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const apiKeyManagementButton = screen.queryByRole('menuitem', { name: /generate \/ revoke api tokens/i }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(apiKeyManagementButton).not.toBeInTheDocument(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+112
to
+124
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the disabled-path check deterministic after config fetch. At Line 123, immediate 💡 Suggested test hardening-import { render, screen } from '../../test-utils';
+import { render, screen, waitFor } from '../../test-utils';
it('should not display generate/revoke api tokens button', async () => {
+ let configRequested = false;
server.use(
rest.get(`/api/v2/config`, async (_req, res, ctx) => {
+ configRequested = true;
return res(ctx.json(CONFIG_DISABLED_RESPONSE));
})
);
const { user } = setup();
const button = screen.getByRole('button', { name: /show user actions/i });
await user.click(button);
+ await waitFor(() => expect(configRequested).toBe(true));
const apiKeyManagementButton = screen.queryByRole('menuitem', { name: /generate \/ revoke api tokens/i });
expect(apiKeyManagementButton).not.toBeInTheDocument();
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stabilize the disabled-state assertion to avoid false positives.
At Line 216, absence is asserted immediately; this can pass before the async config query settles. Wait for configuration query completion first, then assert non-presence.
💡 Suggested test hardening
const queryClient = new QueryClient(); render(<UserProfile />, { queryClient }); - await queryClient.invalidateQueries(configurationKeys.all); - const apiKeyManagementButton = screen.queryByRole('button', { name: 'API Key Management' }); - expect(apiKeyManagementButton).not.toBeInTheDocument(); + await waitFor(() => + expect(queryClient.getQueryState(configurationKeys.all)?.status).toBe('success') + ); + expect(screen.queryByRole('button', { name: 'API Key Management' })).not.toBeInTheDocument();📝 Committable suggestion
🤖 Prompt for AI Agents