From d49370f064a6dff497beb0d0a49aca1f5c4c1d8a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 15 Aug 2024 16:35:57 +0000 Subject: [PATCH] [workspace]feat: add a unit test case to indicate React is anti-xss (#7699) * feat: add a unit test case to indicate React is anti-xss Signed-off-by: SuZhou-Joe * Changeset file for PR #7699 created/updated --------- Signed-off-by: SuZhou-Joe Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit 9195f97ff493f6efb231fbdd77dda3afa64b6409) Signed-off-by: github-actions[bot] --- changelogs/fragments/7699.yml | 2 ++ .../workspace_detail/workspace_detail.test.tsx | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 changelogs/fragments/7699.yml diff --git a/changelogs/fragments/7699.yml b/changelogs/fragments/7699.yml new file mode 100644 index 000000000000..24554fb44461 --- /dev/null +++ b/changelogs/fragments/7699.yml @@ -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)) \ No newline at end of file diff --git a/src/plugins/workspace/public/components/workspace_detail/workspace_detail.test.tsx b/src/plugins/workspace/public/components/workspace_detail/workspace_detail.test.tsx index d27f0187e5b1..78b4ec4cdd03 100644 --- a/src/plugins/workspace/public/components/workspace_detail/workspace_detail.test.tsx +++ b/src/plugins/workspace/public/components/workspace_detail/workspace_detail.test.tsx @@ -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: '', + description: '', + }); + const { getByText } = render(WorkspaceDetailPage({ workspacesService: workspaceService })); + expect(getByText('')).toBeInTheDocument(); + expect(getByText('')).toBeInTheDocument(); + expect(alertSpy).toBeCalledTimes(0); + alertSpy.mockRestore(); + }); });