-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Strict CSP style config (#1034)
Remove unsafe-inline from CSP style source related: descope/etc#2098
- Loading branch information
Showing
19 changed files
with
1,002 additions
and
152 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,77 @@ | ||
import { expect } from '@playwright/test'; | ||
import { test } from './fixtures/cspFixture.js'; | ||
|
||
const configContent = { | ||
flows: { | ||
flow1: { version: 1 }, | ||
}, | ||
componentsVersion: '1.2.3', | ||
}; | ||
|
||
test.describe('descope-wc', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.route('*/**/config.json', async (route) => | ||
route.fulfill({ json: configContent }), | ||
); | ||
|
||
await page.route('*/**/theme.json', async (route) => | ||
route.fulfill({ | ||
json: { | ||
light: { | ||
globals: '', | ||
components: {}, | ||
}, | ||
dark: { | ||
globals: '', | ||
components: {}, | ||
}, | ||
}, | ||
}), | ||
); | ||
|
||
await page.route('*/**/*.html', async (route) => | ||
route.fulfill({ body: `<div>123</div>` }), | ||
); | ||
|
||
await page.route( | ||
new RegExp( | ||
`.*\/@descope\/web-components-ui@${configContent.componentsVersion}/`, | ||
), | ||
async (route) => { | ||
const filePath = route | ||
.request() | ||
.url() | ||
.replace(new RegExp(`.*@${configContent.componentsVersion}`), ''); | ||
return route.fulfill({ | ||
path: require.resolve('@descope/web-components-ui' + filePath), | ||
}); | ||
}, | ||
); | ||
|
||
await page.route('**/start', async (route) => | ||
route.fulfill({ | ||
json: { | ||
executionId: 'pass|#|2tlLFAOthDriBZIOVXahmLnYv8Q', | ||
stepId: '4', | ||
status: 'waiting', | ||
action: '', | ||
screen: { | ||
id: 'pass/SC2sIjJonbfhE16bTzi1ZWZIlUCsu', | ||
state: { | ||
project: { | ||
name: 'Nir-test', | ||
}, | ||
}, | ||
}, | ||
stepName: 'Sign In', | ||
}, | ||
}), | ||
); | ||
|
||
await page.goto('http://localhost:5565'); | ||
}); | ||
|
||
test('init', async ({ page }) => { | ||
await expect(page.locator(`descope-wc`).first()).toBeVisible(); | ||
}); | ||
}); |
This file contains 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,33 @@ | ||
import * as pw from '@playwright/test'; | ||
|
||
const cspErrorPatterns = [/^Refused to/]; | ||
const cspIgnoreBrowsers = ['webkit']; | ||
|
||
const isMessageMatchPatterns = (message, patterns) => { | ||
return patterns.some((pattern) => pattern.test(message)); | ||
}; | ||
|
||
const getIsCspError = (message, browserName) => | ||
!cspIgnoreBrowsers.includes(browserName) && | ||
message.type() === 'error' && | ||
isMessageMatchPatterns(message.text(), cspErrorPatterns); | ||
|
||
// we are overriding the default test runner to add a check for console errors | ||
// if any console errors are detected, the test will fail | ||
const test = pw.test.extend({ | ||
page: async ({ page, browserName }, use) => { | ||
let isCspError = false; | ||
|
||
page.on('console', (message) => { | ||
if (getIsCspError(message, browserName)) { | ||
isCspError = true; | ||
} | ||
}); | ||
await use(page); | ||
|
||
if (isCspError) | ||
throw new Error(`CSP errors detected. See console output for details.`); | ||
}, | ||
}); | ||
|
||
export { test }; |
This file contains 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 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 @@ | ||
global.CSSStyleSheet.prototype.replaceSync = jest.fn(); |
This file contains 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.