Skip to content

Commit

Permalink
[workspace]feat: add a unit test case to indicate React is anti-xss (#…
Browse files Browse the repository at this point in the history
…7699)

* feat: add a unit test case to indicate React is anti-xss

Signed-off-by: SuZhou-Joe <[email protected]>

* Changeset file for PR #7699 created/updated

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 9195f97)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and SuZhou-Joe committed Aug 19, 2024
1 parent f1f14c9 commit d49370f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7699.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add a unit test case to indicate React is anti-xss ([#7699](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7699))
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,18 @@ describe('WorkspaceDetail', () => {
expect(screen.queryByText('Enter details')).not.toBeNull();
});
});

it('will not render xss content', async () => {
const alertSpy = jest.spyOn(window, 'alert').mockImplementation(() => {});
const workspaceService = createWorkspacesSetupContractMockWithValue({
...workspaceObject,
name: '<script>alert("name")</script>',
description: '<script>alert("description")</script>',
});
const { getByText } = render(WorkspaceDetailPage({ workspacesService: workspaceService }));
expect(getByText('<script>alert("name")</script>')).toBeInTheDocument();
expect(getByText('<script>alert("description")</script>')).toBeInTheDocument();
expect(alertSpy).toBeCalledTimes(0);
alertSpy.mockRestore();
});
});

0 comments on commit d49370f

Please sign in to comment.