-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: Restrict certain messages actions on ABAC rooms #37128
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
11 commits
Select commit
Hold shift + click to select a range
586e427
feat: Restrict Forward Message
MartinSchoeler ae7a99f
feat: restrict Reply in DM action in ABAC rooms
MartinSchoeler c04c12b
feat: restrict permalink action in ABAC rooms
MartinSchoeler 86a1652
chore: tooltips
MartinSchoeler 222ec04
fix: fixes based on #37127
MartinSchoeler bb72320
Create wicked-ligers-hide.md
MartinSchoeler 405e019
test: update tests
MartinSchoeler 3700d4b
chore: move pr to chore
MartinSchoeler 711c693
test: update tests types
MartinSchoeler fb5966b
Merge branch 'develop' into feat/ABAC-message-restrictions
kodiakhq[bot] 005da73
Merge branch 'develop' into feat/ABAC-message-restrictions
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
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
154 changes: 154 additions & 0 deletions
154
apps/meteor/client/components/message/toolbar/items/actions/ForwardMessageAction.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,154 @@ | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { axe } from 'jest-axe'; | ||
|
|
||
| import ForwardMessageAction from './ForwardMessageAction'; | ||
| import FakeRoomProvider from '../../../../../../tests/mocks/client/FakeRoomProvider'; | ||
| import { createFakeRoom } from '../../../../../../tests/mocks/data'; | ||
|
|
||
| // Mock the getPermaLink function | ||
| jest.mock('../../../../../lib/getPermaLink', () => ({ | ||
| getPermaLink: jest.fn(() => Promise.resolve(null)), | ||
| })); | ||
|
|
||
| jest.mock('../../../../../views/room/modals/ForwardMessageModal', () => ({ | ||
| getPermaLink: jest.fn(() => null), | ||
| })); | ||
|
|
||
| const appRoot = mockAppRoot() | ||
| .withTranslations('en', 'core', { | ||
| Forward_message: 'Forward message', | ||
| Action_not_available_encrypted_content: 'Action not available for encrypted content', | ||
| }) | ||
| .build(); | ||
|
|
||
| const createMockMessage = (overrides: any = {}) => ({ | ||
| _id: 'message-id', | ||
| rid: 'room-id', | ||
| msg: 'Test message', | ||
| ts: new Date(), | ||
| u: { _id: 'user-id', username: 'testuser' }, | ||
| ...overrides, | ||
| }); | ||
|
|
||
| describe('ForwardMessageAction', () => { | ||
| it('should render the forward action for normal messages', () => { | ||
| const message = createMockMessage(); | ||
| const room = createFakeRoom(); | ||
|
|
||
| render( | ||
| <FakeRoomProvider roomOverrides={room}> | ||
| <ForwardMessageAction message={message} room={room} /> | ||
| </FakeRoomProvider>, | ||
| { wrapper: appRoot }, | ||
| ); | ||
|
|
||
| expect(screen.getByRole('button', { name: 'Forward message' })).toBeInTheDocument(); | ||
| expect(screen.getByRole('button', { name: 'Forward message' })).not.toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should be disabled for encrypted messages', () => { | ||
| const message = createMockMessage({ | ||
| t: 'e2e', | ||
| e2e: 'encrypted', | ||
| }); | ||
| const room = createFakeRoom(); | ||
|
|
||
| render( | ||
| <FakeRoomProvider roomOverrides={room}> | ||
| <ForwardMessageAction message={message} room={room} /> | ||
| </FakeRoomProvider>, | ||
| { wrapper: appRoot }, | ||
| ); | ||
|
|
||
| const button = screen.getByRole('button', { name: 'Action not available for encrypted content' }); | ||
| expect(button).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should be disabled for ABAC rooms', () => { | ||
| const message = createMockMessage(); | ||
| const room = createFakeRoom({ | ||
| // @ts-expect-error - abacAttributes is not yet implemented in IRoom type | ||
| abacAttributes: { someAttribute: 'value' }, | ||
| }); | ||
|
|
||
| render( | ||
| <FakeRoomProvider roomOverrides={room}> | ||
| <ForwardMessageAction message={message} room={room} /> | ||
| </FakeRoomProvider>, | ||
| { wrapper: appRoot }, | ||
| ); | ||
|
|
||
| const button = screen.getByRole('button', { name: 'Not_available_for_ABAC_enabled_rooms' }); | ||
| expect(button).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should be disabled for both encrypted messages and ABAC rooms', () => { | ||
| const message = createMockMessage({ | ||
| t: 'e2e', | ||
| e2e: 'encrypted', | ||
| }); | ||
| const room = createFakeRoom({ | ||
| // @ts-expect-error - abacAttributes is not yet implemented in IRoom type | ||
| abacAttributes: { someAttribute: 'value' }, | ||
| }); | ||
|
|
||
| render( | ||
| <FakeRoomProvider roomOverrides={room}> | ||
| <ForwardMessageAction message={message} room={room} /> | ||
| </FakeRoomProvider>, | ||
| { wrapper: appRoot }, | ||
| ); | ||
|
|
||
| const button = screen.getByRole('button', { name: 'Action not available for encrypted content' }); | ||
| expect(button).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('should have no accessibility violations for normal messages', async () => { | ||
| const message = createMockMessage(); | ||
| const room = createFakeRoom(); | ||
|
|
||
| const { container } = render( | ||
| <FakeRoomProvider roomOverrides={room}> | ||
| <ForwardMessageAction message={message} room={room} /> | ||
| </FakeRoomProvider>, | ||
| { wrapper: appRoot }, | ||
| ); | ||
| const results = await axe(container); | ||
| expect(results).toHaveNoViolations(); | ||
| }); | ||
|
|
||
| it('should have no accessibility violations for encrypted messages', async () => { | ||
| const message = createMockMessage({ | ||
| t: 'e2e', | ||
| e2e: 'encrypted', | ||
| }); | ||
| const room = createFakeRoom(); | ||
|
|
||
| const { container } = render( | ||
| <FakeRoomProvider roomOverrides={room}> | ||
| <ForwardMessageAction message={message} room={room} /> | ||
| </FakeRoomProvider>, | ||
| { wrapper: appRoot }, | ||
| ); | ||
| const results = await axe(container); | ||
| expect(results).toHaveNoViolations(); | ||
| }); | ||
|
|
||
| it('should have no accessibility violations for ABAC rooms', async () => { | ||
| const message = createMockMessage(); | ||
| const room = createFakeRoom({ | ||
| // @ts-expect-error - abacAttributes is not yet implemented in IRoom type | ||
| abacAttributes: { someAttribute: 'value' }, | ||
| }); | ||
|
|
||
| const { container } = render( | ||
| <FakeRoomProvider roomOverrides={room}> | ||
| <ForwardMessageAction message={message} room={room} /> | ||
| </FakeRoomProvider>, | ||
| { wrapper: appRoot }, | ||
| ); | ||
| const results = await axe(container); | ||
| expect(results).toHaveNoViolations(); | ||
| }); | ||
| }); | ||
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.