-
Notifications
You must be signed in to change notification settings - Fork 736
FEAT [GUI] Display signed-in user info in top bar and populate operator label with username #1636
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b63361c
Add labels to attack results
e8164aa
Merge branch 'main' into users/behnam/attack-result-labels
4ec494a
format
5e04ca7
label queries OR'ed with old way
fa5a0d7
review feedback
aafefc1
format
c46e78d
Merge branch 'main' of https://github.com/behnam-o/PyRIT
9425f46
Merge branch 'main' of https://github.com/microsoft/PyRIT
a89d5de
[GUI] Display signed-in user info in top bar
570cc60
Revert "format"
f0c1c3d
Revert "review feedback"
483c1ec
Revert " label queries OR'ed with old way"
dc67bc6
Revert "format"
543a582
Revert "Add labels to attack results"
2fdb0a4
Merge branch 'main' into dev/gui-username
f350df6
code coverage tests
17c96c9
set the alias as operator label
76d22b8
feedback
39c6513
extra whitespace
dc35964
EOF
dccb1b3
feedback
05bca81
empty account name fallback
49118d3
label override tests
87d7a36
Merge branch 'main' into dev/gui-username
behnam-o da9883e
Merge branch 'main' into dev/gui-username
behnam-o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { makeStyles, tokens } from '@fluentui/react-components' | ||
|
|
||
| export const useUserAccountButtonStyles = makeStyles({ | ||
| wrapper: { | ||
| marginLeft: 'auto', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| }, | ||
| popoverContent: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| gap: tokens.spacingVerticalS, | ||
| }, | ||
| accountName: { | ||
| fontWeight: tokens.fontWeightSemibold, | ||
| }, | ||
| accountEmail: { | ||
| fontSize: tokens.fontSizeBase200, | ||
| color: tokens.colorNeutralForeground3, | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { render, screen } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { FluentProvider, webLightTheme } from '@fluentui/react-components' | ||
| import { UserAccountButton } from './UserAccountButton' | ||
|
|
||
|
behnam-o marked this conversation as resolved.
|
||
| const mockLoginRedirect = jest.fn() | ||
| const mockLogoutRedirect = jest.fn() | ||
| const mockGetActiveAccount = jest.fn() | ||
| let mockAccounts: { name?: string; username?: string }[] = [] | ||
|
|
||
| jest.mock('@azure/msal-react', () => ({ | ||
| useMsal: () => ({ | ||
| instance: { | ||
| getActiveAccount: mockGetActiveAccount, | ||
| loginRedirect: mockLoginRedirect, | ||
| logoutRedirect: mockLogoutRedirect, | ||
| }, | ||
| accounts: mockAccounts, | ||
| }), | ||
| })) | ||
|
|
||
| let mockAuthConfig = { clientId: '', tenantId: '', allowedGroupIds: '' } | ||
|
|
||
| jest.mock('../auth/AuthConfigContext', () => ({ | ||
| useAuthConfig: () => mockAuthConfig, | ||
| })) | ||
|
|
||
| jest.mock('../auth/msalConfig', () => ({ | ||
| buildLoginRequest: (clientId: string) => ({ scopes: [`${clientId}/.default`] }), | ||
| })) | ||
|
|
||
| const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => ( | ||
| <FluentProvider theme={webLightTheme}>{children}</FluentProvider> | ||
| ) | ||
|
|
||
| describe('UserAccountButton', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| mockGetActiveAccount.mockReturnValue(null) | ||
| mockLoginRedirect.mockResolvedValue(undefined) | ||
| mockLogoutRedirect.mockResolvedValue(undefined) | ||
| mockAuthConfig = { clientId: '', tenantId: '', allowedGroupIds: '' } | ||
| mockAccounts = [] | ||
| }) | ||
|
|
||
| it('returns null when auth is disabled (no clientId)', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <UserAccountButton /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| // UserAccountButton renders null — no buttons appear | ||
| expect(screen.queryByRole('button')).toBeNull() | ||
| }) | ||
|
|
||
| it('renders Log In button when auth enabled but no account', () => { | ||
| mockAuthConfig = { clientId: 'test-client-id', tenantId: 'test-tenant', allowedGroupIds: '' } | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <UserAccountButton /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| expect(screen.getByRole('button', { name: /log in/i })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('calls loginRedirect when Log In is clicked', async () => { | ||
| mockAuthConfig = { clientId: 'test-client-id', tenantId: 'test-tenant', allowedGroupIds: '' } | ||
| const user = userEvent.setup() | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <UserAccountButton /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /log in/i })) | ||
|
|
||
| expect(mockLoginRedirect).toHaveBeenCalledWith({ scopes: ['test-client-id/.default'] }) | ||
| }) | ||
|
|
||
| it('renders user display name and Sign Out when account exists', () => { | ||
| mockAuthConfig = { clientId: 'test-client-id', tenantId: 'test-tenant', allowedGroupIds: '' } | ||
| mockGetActiveAccount.mockReturnValue({ | ||
| name: 'Alice Smith', | ||
| username: 'alice@example.com', | ||
| }) | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <UserAccountButton /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| expect(screen.getByText('Alice Smith')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders user display name when account comes from accounts[0] (no active account)', () => { | ||
| mockAuthConfig = { clientId: 'test-client-id', tenantId: 'test-tenant', allowedGroupIds: '' } | ||
| mockAccounts = [{ name: 'Bob Jones', username: 'bob@example.com' }] | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <UserAccountButton /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| expect(screen.getByText('Bob Jones')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('calls logoutRedirect when Sign Out is clicked', async () => { | ||
| mockAuthConfig = { clientId: 'test-client-id', tenantId: 'test-tenant', allowedGroupIds: '' } | ||
| mockGetActiveAccount.mockReturnValue({ | ||
| name: 'Alice Smith', | ||
| username: 'alice@example.com', | ||
| }) | ||
| const user = userEvent.setup() | ||
|
|
||
| render( | ||
| <TestWrapper> | ||
| <UserAccountButton /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| // Open the popover by clicking the user button | ||
| await user.click(screen.getByRole('button', { name: /alice smith/i })) | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /sign out/i })) | ||
|
|
||
|
behnam-o marked this conversation as resolved.
|
||
| expect(mockLogoutRedirect).toHaveBeenCalled() | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.