Skip to content

Commit

Permalink
Security: Upgrade react-router-dom to v6 (#6065)
Browse files Browse the repository at this point in the history
* upgrade react-router-dom to 6.28.1

* switch <Switch> component to <Routes>

* replace useHistory with useNavigate

* remove useRouteMatch on OrganizationCard

* add RouterProvider to tests

* refactor Page and PrivatePage to handle new Routes

* don't set page title for certain pages

* fix RouterProvider in tests

* fix dmarc-summaries link to dmarc reports
  • Loading branch information
lcampbell2 authored Jan 21, 2025
1 parent 562a969 commit 832eb55
Show file tree
Hide file tree
Showing 41 changed files with 1,159 additions and 1,147 deletions.
191 changes: 45 additions & 146 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"react-error-boundary": "^3.1.4",
"react-joyride": "^2.8.2",
"react-phone-input-2": "^2.15.1",
"react-router-dom": "^5.3.3",
"react-router-dom": "^6.28.1",
"react-table": "^7.8.0",
"yup": "^0.32.11"
},
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/admin/AdminPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, Flex, Stack, Text, useToast, Select } from '@chakra-ui/react'
import { AddIcon } from '@chakra-ui/icons'
import { t, Trans } from '@lingui/macro'
import { useQuery } from '@apollo/client'
import { Link as RouteLink, useHistory, useParams } from 'react-router-dom'
import { Link as RouteLink, useNavigate, useParams } from 'react-router-dom'
import { useLingui } from '@lingui/react'

import { AdminPanel } from './AdminPanel'
Expand All @@ -28,7 +28,7 @@ export default function AdminPage() {

const { activeMenu } = useParams()
const toast = useToast()
const history = useHistory()
const navigate = useNavigate()
const { i18n } = useLingui()

const memoizedSetDebouncedSearchTermCallback = useCallback(() => {
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function AdminPage() {

useEffect(() => {
if (!activeMenu) {
history.replace(`/admin/organizations`)
navigate(`/admin/organizations`, { replace: true })
}
if (initRender && data?.findMyOrganizations?.edges.length === 1) {
setInitRender(false)
Expand Down Expand Up @@ -145,7 +145,7 @@ export default function AdminPage() {

const changeActiveMenu = (val) => {
if (activeMenu !== val) {
history.replace(`/admin/${val}`)
navigate(`/admin/${val}`, { replace: true })
}
}

Expand Down
37 changes: 25 additions & 12 deletions frontend/src/admin/__tests__/AdminPanel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { theme, ChakraProvider } from '@chakra-ui/react'
import { I18nProvider } from '@lingui/react'
import { setupI18n } from '@lingui/core'
import { MockedProvider } from '@apollo/client/testing'
import { MemoryRouter, Route } from 'react-router-dom'
import { createMemoryRouter, RouterProvider } from 'react-router-dom'
import { makeVar } from '@apollo/client'
import { en } from 'make-plural/plurals'

Expand Down Expand Up @@ -44,24 +44,37 @@ const mocks = [
},
]

const router = createMemoryRouter(
[
{
path: '/reset-password/:resetToken',
element: (
<AdminPanel orgSlug="test-org.slug" permission="ADMIN" orgId={rawOrgDomainListData.findOrganizationBySlug.id} />
),
},
],
{
initialEntries: ['/reset-password/fwsdGDFSGSDVA.gedafbedafded.bgdbsedbeagbe'],
initialIndex: 0,
},
)

describe('<AdminPanel />', () => {
it('renders both a domain list and user list', async () => {
const { getByText } = render(
<MockedProvider mocks={mocks} cache={createCache()}>
<UserVarProvider userVar={makeVar({ jwt: null, tfaSendMethod: null, userName: null })}>
<I18nProvider i18n={i18n}>
<ChakraProvider theme={theme}>
<MemoryRouter initialEntries={['/admin']} initialIndex={0}>
<Route path="/admin">
<TourProvider>
<AdminPanel
orgSlug="test-org.slug"
permission="ADMIN"
orgId={rawOrgDomainListData.findOrganizationBySlug.id}
/>
</TourProvider>
</Route>
</MemoryRouter>
<TourProvider>
<RouterProvider router={router}>
<AdminPanel
orgSlug="test-org.slug"
permission="ADMIN"
orgId={rawOrgDomainListData.findOrganizationBySlug.id}
/>
</RouterProvider>
</TourProvider>
</ChakraProvider>
</I18nProvider>
</UserVarProvider>
Expand Down
Loading

0 comments on commit 832eb55

Please sign in to comment.