forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add options for passing nonces to feedback integration (getsent…
- Loading branch information
1 parent
5e26092
commit d4c7a09
Showing
13 changed files
with
175 additions
and
12 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/init.js
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,19 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
// Import this separately so that generatePlugin can handle it for CDN scenarios | ||
import { feedbackIntegration } from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [ | ||
feedbackIntegration({ tags: { from: 'integration init' }, styleNonce: 'foo1234', scriptNonce: 'foo1234' }), | ||
], | ||
}); | ||
|
||
document.addEventListener('securitypolicyviolation', () => { | ||
const container = document.querySelector('#csp-violation'); | ||
if (container) { | ||
container.innerText = 'CSP Violation'; | ||
} | ||
}); |
13 changes: 13 additions & 0 deletions
13
dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/template.html
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,13 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta | ||
http-equiv="Content-Security-Policy" | ||
content="style-src 'nonce-foo1234'; script-src sentry-test.io 'nonce-foo1234';" | ||
/> | ||
</head> | ||
<body> | ||
<div id="csp-violation" /> | ||
</body> | ||
</html> |
84 changes: 84 additions & 0 deletions
84
dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/test.ts
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,84 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { TEST_HOST, sentryTest } from '../../../utils/fixtures'; | ||
import { envelopeRequestParser, getEnvelopeType, shouldSkipFeedbackTest } from '../../../utils/helpers'; | ||
|
||
sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipFeedbackTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const feedbackRequestPromise = page.waitForResponse(res => { | ||
const req = res.request(); | ||
|
||
const postData = req.postData(); | ||
if (!postData) { | ||
return false; | ||
} | ||
|
||
try { | ||
return getEnvelopeType(req) === 'feedback'; | ||
} catch (err) { | ||
return false; | ||
} | ||
}); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await page.getByText('Report a Bug').click(); | ||
expect(await page.locator(':visible:text-is("Report a Bug")').count()).toEqual(1); | ||
await page.locator('[name="name"]').fill('Jane Doe'); | ||
await page.locator('[name="email"]').fill('janedoe@example.org'); | ||
await page.locator('[name="message"]').fill('my example feedback'); | ||
await page.locator('[data-sentry-feedback] .btn--primary').click(); | ||
|
||
const feedbackEvent = envelopeRequestParser((await feedbackRequestPromise).request()); | ||
expect(feedbackEvent).toEqual({ | ||
type: 'feedback', | ||
breadcrumbs: expect.any(Array), | ||
contexts: { | ||
feedback: { | ||
contact_email: 'janedoe@example.org', | ||
message: 'my example feedback', | ||
name: 'Jane Doe', | ||
source: 'widget', | ||
url: `${TEST_HOST}/index.html`, | ||
}, | ||
trace: { | ||
trace_id: expect.stringMatching(/\w{32}/), | ||
span_id: expect.stringMatching(/\w{16}/), | ||
}, | ||
}, | ||
level: 'info', | ||
tags: { | ||
from: 'integration init', | ||
}, | ||
timestamp: expect.any(Number), | ||
event_id: expect.stringMatching(/\w{32}/), | ||
environment: 'production', | ||
sdk: { | ||
integrations: expect.arrayContaining(['Feedback']), | ||
version: expect.any(String), | ||
name: 'sentry.javascript.browser', | ||
packages: expect.anything(), | ||
}, | ||
request: { | ||
url: `${TEST_HOST}/index.html`, | ||
headers: { | ||
'User-Agent': expect.stringContaining(''), | ||
}, | ||
}, | ||
platform: 'javascript', | ||
}); | ||
const cspContainer = await page.locator('#csp-violation'); | ||
expect(cspContainer).not.toContainText('CSP Violation'); | ||
}); |
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
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