Skip to content

Commit

Permalink
Test react-error-overlay passes dev CSP
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Aug 25, 2023
1 parent 94b2d46 commit c907220
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 2 additions & 4 deletions internals/getSecurityHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const localnet = `
const hmrWebsocket = `
ws://localhost:2222
`
const reactErrorOverlay = `
'sha256-RV6I4HWPb71LvA27WVD3cEz8GsJrHlfcM/2X2Q5gV00='
`
const reactErrorOverlay = `'sha256-RV6I4HWPb71LvA27WVD3cEz8GsJrHlfcM/2X2Q5gV00='`
const hmrScripts = `
'unsafe-eval'
`
Expand Down Expand Up @@ -106,4 +104,4 @@ const getPermissionsPolicy = () =>
.join(' ')
.replace(/ ,/g, ',')

module.exports = { getCsp, getPermissionsPolicy }
module.exports = { getCsp, getPermissionsPolicy, reactErrorOverlay }
12 changes: 12 additions & 0 deletions playwright/tests/csp-react-error-overlay.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from '@playwright/test'
import { reactErrorOverlay } from '../../internals/getSecurityHeaders.js'

test('Dev Content-Security-Policy should allow react-error-overlay', async ({ page, baseURL }) => {
if (baseURL !== 'http://localhost:3000') test.skip()
expect((await page.request.head('/')).headers()).toHaveProperty('content-security-policy')
expect((await page.request.head('/')).headers()['content-security-policy']).toContain(reactErrorOverlay)
await page.goto('/e2e')
await page.getByRole('button', { name: 'Trigger uncaught error' }).click()
await expect(page.locator('iframe')).toBeVisible()
await expect(page.frameLocator('iframe').getByText('ReferenceError')).toBeVisible()
})
11 changes: 9 additions & 2 deletions src/app/pages/E2EPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function E2EPage() {
<br />
<TestUnsafeInputs></TestUnsafeInputs>
<br />
<TriggerFatalError></TriggerFatalError>
<TriggerError></TriggerError>
<br />
<DemoAlertBoxes></DemoAlertBoxes>
</div>
Expand Down Expand Up @@ -118,7 +118,7 @@ function UnsafePasswordField(props: {
)
}

function TriggerFatalError() {
function TriggerError() {
const dispatch = useDispatch()
return (
<div>
Expand All @@ -128,6 +128,13 @@ function TriggerFatalError() {
dispatch(walletActions.openWalletFromPrivateKey({ privateKey: '0xAA', choosePassword: undefined }))
}}
/>
<Button
label="Trigger uncaught error"
onClick={() => {
// @ts-expect-error Function does not exist
functionDoesNotExist()
}}
/>
</div>
)
}
Expand Down

0 comments on commit c907220

Please sign in to comment.