Skip to content

test(replay): Add integration test for privacy #7055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/integration-tests/suites/replay/privacy/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
window.Replay = new Sentry.Replay({
flushMinDelay: 200,
flushMaxDelay: 200,
useCompression: false,
});

Sentry.init({
dsn: 'https://[email protected]/1337',
sampleRate: 0,
replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 0.0,

integrations: [window.Replay],
});
13 changes: 13 additions & 0 deletions packages/integration-tests/suites/replay/privacy/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" /></head>
<body>
<button aria-label="Click me" onclick="console.log('Test log')">Click me</button>
<div>This should be masked by default</div>
<div data-sentry-unmask>This should be unmasked due to data attribute</div>
<input placeholder="Placeholder should be masked" />
<div title="Title should be masked">Title should be masked</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80"><path d="M79 71.91a7.32 7.32 0 0 0 0-7.38L46.4 8A7.22 7.22 0 0 0 40 4.37 7.33 7.33 0 0 0 33.62 8L23.06 26.33l2.66 1.54A51.42 51.42 0 0 1 44.6 46.75a50.41 50.41 0 0 1 6.81 22.72H44a44.34 44.34 0 0 0-5.84-19A43.76 43.76 0 0 0 22.07 34.2l-2.66-1.54-9.83 17.13 2.65 1.54A24.9 24.9 0 0 1 24.3 69.47H7.39a1.2 1.2 0 0 1-1.06-.59 1.21 1.21 0 0 1 0-1.23l4.73-8.14a17.67 17.67 0 0 0-5.38-3.08L1 64.57A7.34 7.34 0 0 0 1 72a7.25 7.25 0 0 0 6.39 3.67h23.24v-3.12a31.32 31.32 0 0 0-4.09-15.38 31.26 31.26 0 0 0-8.67-9.57l3.71-6.39a38 38 0 0 1 11.33 12.28 38.1 38.1 0 0 1 5.1 19v3.08h19.68v-3.02a57.52 57.52 0 0 0-7.76-28.88A57.48 57.48 0 0 0 31.47 24.1l7.51-13a1.18 1.18 0 0 1 1.02-.57 1.16 1.16 0 0 1 1.05.59L73.7 67.61a1.2 1.2 0 0 1 0 1.22 1.13 1.13 0 0 1-1.06.59H65c.1 2.07.1 4.09 0 6.16h7.65A7.1 7.1 0 0 0 79 71.91z"/></svg>
<img href="#foo" />
</body>
</html>
226 changes: 226 additions & 0 deletions packages/integration-tests/suites/replay/privacy/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import { expect } from '@playwright/test';
import { EventType } from '@sentry-internal/rrweb';
import type { RecordingEvent } from '@sentry/replay';

import { sentryTest } from '../../../utils/fixtures';
import { envelopeRequestParser } from '../../../utils/helpers';
import { waitForReplayRequest } from '../../../utils/replayHelpers';

sentryTest('should have the correct default privacy settings', async ({ getLocalTestPath, page }) => {
// For this test, we skip all bundle tests, as we're only interested in Replay being correctly
// exported from the `@sentry/browser` npm package.
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) {
sentryTest.skip();
}

const reqPromise0 = waitForReplayRequest(page, 0);

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 getLocalTestPath({ testDir: __dirname });

await page.goto(url);
const replayPayload = envelopeRequestParser<RecordingEvent[]>(await reqPromise0, 5);
const checkoutEvent = replayPayload.find(({type}) => type === EventType.FullSnapshot);

expect(checkoutEvent?.data).toMatchObject(
{
'initialOffset': {
'left': 0,
'top': 0,
},
'node': {
'childNodes': [
{
'id': 2,
'name': 'html',
'publicId': '',
'systemId': '',
'type': 1,
},
{
'attributes': {},
'childNodes': [
{
'attributes': {},
'childNodes': [
{
'attributes': {
'charset': 'utf-8',
},
'childNodes': [],
'id': 5,
'tagName': 'meta',
'type': 2,
},
],
'id': 4,
'tagName': 'head',
'type': 2,
},
{
'id': 6,
'textContent': '\n ',
'type': 3,
},
{
'attributes': {},
'childNodes': [
{
'id': 8,
'textContent': '\n ',
'type': 3,
},
{
'attributes': {
'aria-label': 'Click me',
'onclick': "console.log('Test log')",
},
'childNodes': [
{
'id': 10,
'textContent': '***** **',
'type': 3,
},
],
'id': 9,
'tagName': 'button',
'type': 2,
},
{
'id': 11,
'textContent': '\n ',
'type': 3,
},
{
'attributes': {},
'childNodes': [
{
'id': 13,
'textContent': '**** ****** ** ****** ** *******',
'type': 3,
},
],
'id': 12,
'tagName': 'div',
'type': 2,
},
{
'id': 14,
'textContent': '\n ',
'type': 3,
},
{
'attributes': {
'data-sentry-unmask': '',
},
'childNodes': [
{
'id': 16,
'textContent': 'This should be unmasked due to data attribute',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should break when we merge and release getsentry/rrweb#40

'type': 3,
},
],
'id': 15,
'tagName': 'div',
'type': 2,
},
{
'id': 17,
'textContent': '\n ',
'type': 3,
},
{
'attributes': {
'placeholder': 'Placeholder should be masked',
},
'childNodes': [],
'id': 18,
'tagName': 'input',
'type': 2,
},
{
'id': 19,
'textContent': '\n ',
'type': 3,
},
{
'attributes': {
'title': 'Title should be masked',
},
'childNodes': [
{
'id': 21,
'textContent': '***** ****** ** ******',
'type': 3,
},
],
'id': 20,
'tagName': 'div',
'type': 2,
},
{
'id': 22,
'textContent': '\n ',
'type': 3,
},
{
'attributes': {
'rr_height': '1264px',
'rr_width': '1264px',
},
'childNodes': [],
'id': 23,
'isSVG': true,
'tagName': 'svg',
'type': 2,
},
{
'id': 24,
'textContent': '\n ',
'type': 3,
},
{
'attributes': {
'rr_height': '0px',
'rr_width': '0px',
},
'childNodes': [],
'id': 25,
'tagName': 'img',
'type': 2,
},
{
'id': 26,
'textContent': '\n ',
'type': 3,
},
{
'id': 27,
'textContent': '\n\n',
'type': 3,
},
],
'id': 7,
'tagName': 'body',
'type': 2,
},
],
'id': 3,
'tagName': 'html',
'type': 2,
},
],
'id': 1,
'type': 0,
},
}

);
});
4 changes: 2 additions & 2 deletions packages/integration-tests/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const envelopeParser = (request: Request | null): unknown[] => {
});
};

export const envelopeRequestParser = (request: Request | null): Event => {
return envelopeParser(request)[2] as Event;
export const envelopeRequestParser = <T = Event>(request: Request | null, index = 2): T => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thought in #7052 😅

return envelopeParser(request)[index] as T;
};

export const envelopeHeaderRequestParser = (request: Request | null): EventEnvelopeHeaders => {
Expand Down
2 changes: 2 additions & 0 deletions packages/replay/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { Replay } from './integration';

export type {RecordingEvent} from './types'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure the best way to expose this type for the test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was also struggling with this and opted to duplicate the type in #7052. If we're comfortable exposing this as public API, I think exporting it is fine and I'll also switch to it in my PR.
The one reason against exporting it would be breaking changes in rrweb 2.x, if any? But considering how far off it seems that we're upgrading, I'd say it's negligible. WDYT?