-
Notifications
You must be signed in to change notification settings - Fork 13k
fix: incorrect e2ee toggle behavior on Teams creation modal and private/broadcast toggling #36797
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
4 commits
Select commit
Hold shift + click to select a range
9f84b20
fix: incorrect e2ee toggle behavior on Teams creation and private/bro…
abhinavkrin 8a7b9f6
added changeset
abhinavkrin 05b8e20
changes requested
abhinavkrin 8cf32fd
Merge branch 'develop' into fix/e2ee-toggle-behavior-on-teams
kodiakhq[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/i18n': patch | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Fixes an issue where the encryption toggle was incorrectly reset/disabled/enabled in the Teams creation modal when Broadcast or Private was toggled, or when the user lacked unrelated permissions. |
258 changes: 258 additions & 0 deletions
258
apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/CreateTeamModal.spec.tsx
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,258 @@ | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
|
|
||
| import CreateTeamModal from './CreateTeamModal'; | ||
| import CreateTeamModalOld from '../../../sidebar/header/CreateTeam'; | ||
|
|
||
| jest.mock('../../../lib/utils/goToRoomById', () => ({ | ||
| goToRoomById: jest.fn(), | ||
| })); | ||
|
|
||
| type CreateTeamModalComponentType = typeof CreateTeamModal | typeof CreateTeamModalOld; | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
|
|
||
| describe.each([ | ||
| ['CreateTeamModal', CreateTeamModalOld], | ||
| ['CreateTeamModal in NavbarV2', CreateTeamModal], | ||
| ] as const)( | ||
| '%s', | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| (_name: string, CreateTeamModalComponent: CreateTeamModalComponentType) => { | ||
| it('should render with encryption option disabled and set to off when E2E_Enable=false and E2E_Enabled_Default_PrivateRooms=false', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withSetting('E2E_Enable', false).withSetting('E2E_Enabled_Default_PrivateRooms', false).build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const encrypted = screen.getByLabelText('Teams_New_Encrypted_Label') as HTMLInputElement; | ||
| expect(encrypted).toBeInTheDocument(); | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should render with encryption option enabled and set to off when E2E_Enable=true and E2E_Enabled_Default_PrivateRooms=false', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withSetting('E2E_Enable', true).withSetting('E2E_Enabled_Default_PrivateRooms', false).build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const encrypted = screen.getByLabelText('Teams_New_Encrypted_Label') as HTMLInputElement; | ||
| expect(encrypted).toBeInTheDocument(); | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeEnabled(); | ||
| }); | ||
|
|
||
| it('should render with encryption option disabled and set to off when E2E_Enable=false and E2E_Enabled_Default_PrivateRooms=true', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withSetting('E2E_Enable', false).withSetting('E2E_Enabled_Default_PrivateRooms', true).build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const encrypted = screen.getByLabelText('Teams_New_Encrypted_Label') as HTMLInputElement; | ||
| expect(encrypted).toBeInTheDocument(); | ||
|
|
||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should render with encryption option enabled and set to on when E2E_Enable=true and E2E_Enabled_Default_PrivateRooms=True', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withSetting('E2E_Enable', true).withSetting('E2E_Enabled_Default_PrivateRooms', true).build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const encrypted = screen.getByLabelText('Teams_New_Encrypted_Label') as HTMLInputElement; | ||
| expect(encrypted).toBeChecked(); | ||
| expect(encrypted).toBeEnabled(); | ||
| }); | ||
|
|
||
| it('when Private goes ON → OFF: forces Encrypted OFF and disables it (E2E_Enable=true, E2E_Enabled_Default_PrivateRooms=true)', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withSetting('E2E_Enable', true).withSetting('E2E_Enabled_Default_PrivateRooms', true).build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const encrypted = screen.getByLabelText('Teams_New_Encrypted_Label') as HTMLInputElement; | ||
| const priv = screen.getByLabelText('Teams_New_Private_Label') as HTMLInputElement; | ||
|
|
||
| // initial: private=true, encrypted ON and enabled | ||
| expect(priv).toBeChecked(); | ||
| expect(encrypted).toBeChecked(); | ||
| expect(encrypted).toBeEnabled(); | ||
|
|
||
| // Private ON -> OFF: encrypted must become OFF and disabled | ||
| await userEvent.click(priv); | ||
| expect(priv).not.toBeChecked(); | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('when Private goes OFF → ON: keeps Encrypted OFF but re-enables it (E2E_Enable=true, E2E_Enabled_Default_PrivateRooms=true)', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withSetting('E2E_Enable', true).withSetting('E2E_Enabled_Default_PrivateRooms', true).build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const encrypted = screen.getByLabelText('Teams_New_Encrypted_Label') as HTMLInputElement; | ||
| const priv = screen.getByLabelText('Teams_New_Private_Label') as HTMLInputElement; | ||
|
|
||
| // turn private OFF to simulate user path from non-private | ||
| await userEvent.click(priv); | ||
| expect(priv).not.toBeChecked(); | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeDisabled(); | ||
|
|
||
| // turn private back ON -> encrypted should remain OFF but become enabled | ||
| await userEvent.click(priv); | ||
| expect(priv).toBeChecked(); | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeEnabled(); | ||
| }); | ||
|
|
||
| it('private team: toggling Broadcast on/off does not change or disable Encrypted', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withSetting('E2E_Enable', true).withSetting('E2E_Enabled_Default_PrivateRooms', true).build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const encrypted = screen.getByLabelText('Teams_New_Encrypted_Label') as HTMLInputElement; | ||
| const broadcast = screen.getByLabelText('Teams_New_Broadcast_Label') as HTMLInputElement; | ||
| const priv = screen.getByLabelText('Teams_New_Private_Label') as HTMLInputElement; | ||
|
|
||
| expect(priv).toBeChecked(); | ||
| expect(encrypted).toBeChecked(); | ||
| expect(encrypted).toBeEnabled(); | ||
| expect(broadcast).not.toBeChecked(); | ||
|
|
||
| // Broadcast: OFF -> ON (Encrypted unchanged + enabled) | ||
| await userEvent.click(broadcast); | ||
| expect(broadcast).toBeChecked(); | ||
| expect(encrypted).toBeChecked(); | ||
| expect(encrypted).toBeEnabled(); | ||
|
|
||
| // Broadcast: ON -> OFF (Encrypted unchanged + enabled) | ||
| await userEvent.click(broadcast); | ||
| expect(broadcast).not.toBeChecked(); | ||
| expect(encrypted).toBeChecked(); | ||
| expect(encrypted).toBeEnabled(); | ||
|
|
||
| // User can still toggle Encrypted freely while Broadcast is OFF | ||
| await userEvent.click(encrypted); | ||
| expect(encrypted).not.toBeChecked(); | ||
|
|
||
| // User can still toggle Encrypted freely while Broadcast is ON | ||
| await userEvent.click(broadcast); | ||
| expect(broadcast).toBeChecked(); | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeEnabled(); | ||
| }); | ||
|
|
||
| it('non-private team: Encrypted remains OFF and disabled regardless of Broadcast state', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withSetting('E2E_Enable', true).withSetting('E2E_Enabled_Default_PrivateRooms', true).build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const encrypted = screen.getByLabelText('Teams_New_Encrypted_Label') as HTMLInputElement; | ||
| const broadcast = screen.getByLabelText('Teams_New_Broadcast_Label') as HTMLInputElement; | ||
| const priv = screen.getByLabelText('Teams_New_Private_Label') as HTMLInputElement; | ||
|
|
||
| // Switch to non-private | ||
| await userEvent.click(priv); | ||
| expect(priv).not.toBeChecked(); | ||
|
|
||
| // Encrypted must be OFF + disabled (non-private cannot be encrypted) | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeDisabled(); | ||
|
|
||
| // Broadcast: OFF -> ON (Encrypted stays OFF + disabled) | ||
| await userEvent.click(broadcast); | ||
| expect(broadcast).toBeChecked(); | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeDisabled(); | ||
|
|
||
| // Broadcast: ON -> OFF (Encrypted still OFF + disabled) | ||
| await userEvent.click(broadcast); | ||
| expect(broadcast).not.toBeChecked(); | ||
| expect(encrypted).not.toBeChecked(); | ||
| expect(encrypted).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should disable and turn on ReadOnly toggle when Broadcast is ON and no set-readonly permission', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const broadcast = screen.getByLabelText('Teams_New_Broadcast_Label') as HTMLInputElement; | ||
| const readOnly = screen.getByLabelText('Teams_New_Read_only_Label') as HTMLInputElement; | ||
|
|
||
| expect(readOnly).not.toBeChecked(); | ||
|
|
||
| // Broadcast: OFF -> ON (ReadOnly stays ON + disabled) | ||
| await userEvent.click(broadcast); | ||
| expect(broadcast).toBeChecked(); | ||
| expect(readOnly).toBeChecked(); | ||
| expect(readOnly).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should disable and turn on ReadOnly toggle when Broadcast is ON with set-readonly permission', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withPermission('set-readonly').build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const broadcast = screen.getByLabelText('Teams_New_Broadcast_Label') as HTMLInputElement; | ||
| const readOnly = screen.getByLabelText('Teams_New_Read_only_Label') as HTMLInputElement; | ||
|
|
||
| expect(readOnly).not.toBeChecked(); | ||
|
|
||
| // Broadcast: OFF -> ON (ReadOnly stays ON + disabled) | ||
| await userEvent.click(broadcast); | ||
| expect(broadcast).toBeChecked(); | ||
| expect(readOnly).toBeChecked(); | ||
| expect(readOnly).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should disable and turn off ReadOnly toggle when Broadcast is OFF with no set-readonly permission', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const broadcast = screen.getByLabelText('Teams_New_Broadcast_Label') as HTMLInputElement; | ||
| const readOnly = screen.getByLabelText('Teams_New_Read_only_Label') as HTMLInputElement; | ||
|
|
||
| expect(broadcast).not.toBeChecked(); | ||
| expect(readOnly).not.toBeChecked(); | ||
| expect(readOnly).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should enable ReadOnly toggle when Broadcast is OFF with set-readonly permission', async () => { | ||
| render(<CreateTeamModalComponent onClose={() => null} />, { | ||
| wrapper: mockAppRoot().withPermission('set-readonly').build(), | ||
| }); | ||
|
|
||
| await userEvent.click(screen.getByText('Advanced_settings')); | ||
|
|
||
| const broadcast = screen.getByLabelText('Teams_New_Broadcast_Label') as HTMLInputElement; | ||
| const readOnly = screen.getByLabelText('Teams_New_Read_only_Label') as HTMLInputElement; | ||
|
|
||
| expect(broadcast).not.toBeChecked(); | ||
| expect(readOnly).not.toBeChecked(); | ||
| expect(readOnly).toBeEnabled(); | ||
| }); | ||
| }, | ||
| ); | ||
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
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.