Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add and adjust unit and integration tests
revert unintended yarn script deletion
- Loading branch information
Showing
9 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/integration-tests/suites/tracing/envelope-header-no-pii/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,17 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
import { Integrations } from '@sentry/tracing'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [new Integrations.BrowserTracing({ tracingOrigins: [/.*/] })], | ||
environment: 'production', | ||
tracesSampleRate: 1, | ||
debug: true, | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setUser({ id: 'user123', segment: 'segmentB' }); | ||
scope.setTransactionName('testTransactionDSC'); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/integration-tests/suites/tracing/envelope-header-no-pii/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,24 @@ | ||
import { expect } from '@playwright/test'; | ||
import { EventEnvelopeHeaders } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { envelopeHeaderRequestParser, getFirstSentryEnvelopeRequest } from '../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'should not send user_id in DSC data in trace envelope header if sendDefaultPii option is not set', | ||
async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const envHeader = await getFirstSentryEnvelopeRequest<EventEnvelopeHeaders>(page, url, envelopeHeaderRequestParser); | ||
|
||
expect(envHeader.trace).toBeDefined(); | ||
expect(envHeader.trace).toEqual({ | ||
environment: 'production', | ||
transaction: expect.stringContaining('index.html'), | ||
user_segment: 'segmentB', | ||
sample_rate: '1', | ||
trace_id: expect.any(String), | ||
public_key: 'public', | ||
}); | ||
}, | ||
); |
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
39 changes: 39 additions & 0 deletions
39
packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/server.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,39 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
import http from 'http'; | ||
|
||
const app = express(); | ||
|
||
export type TestAPIResponse = { test_data: { host: string; 'sentry-trace': string; baggage: string } }; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
environment: 'prod', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
Sentry.setUser({ id: 'user123', segment: 'SegmentA' }); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/test/express', (_req, res) => { | ||
const transaction = Sentry.getCurrentHub().getScope()?.getTransaction(); | ||
if (transaction) { | ||
transaction.traceId = '86f39e84263a4de99c326acab3bfe3bd'; | ||
} | ||
const headers = http.get('http://somewhere.not.sentry/').getHeaders(); | ||
|
||
// Responding with the headers outgoing request headers back to the assertions. | ||
res.send({ test_data: headers }); | ||
}); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
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
40 changes: 40 additions & 0 deletions
40
packages/node-integration-tests/suites/express/sentry-trace/baggage-user-id/server.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,40 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
import http from 'http'; | ||
|
||
const app = express(); | ||
|
||
export type TestAPIResponse = { test_data: { host: string; 'sentry-trace': string; baggage: string } }; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
environment: 'prod', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
sendDefaultPii: true, | ||
}); | ||
|
||
Sentry.setUser({ id: 'user123', segment: 'SegmentA' }); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/test/express', (_req, res) => { | ||
const transaction = Sentry.getCurrentHub().getScope()?.getTransaction(); | ||
if (transaction) { | ||
transaction.traceId = '86f39e84263a4de99c326acab3bfe3bd'; | ||
} | ||
const headers = http.get('http://somewhere.not.sentry/').getHeaders(); | ||
|
||
// Responding with the headers outgoing request headers back to the assertions. | ||
res.send({ test_data: headers }); | ||
}); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
18 changes: 18 additions & 0 deletions
18
packages/node-integration-tests/suites/express/sentry-trace/baggage-user-id/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,18 @@ | ||
import * as path from 'path'; | ||
|
||
import { getAPIResponse, runServer } from '../../../../utils/index'; | ||
import { TestAPIResponse } from '../server'; | ||
|
||
test('Includes user_id in baggage if sendDefaultPii is set to true', async () => { | ||
const url = await runServer(__dirname, `${path.resolve(__dirname, '.')}/server.ts`); | ||
|
||
const response = (await getAPIResponse(new URL(`${url}/express`))) as TestAPIResponse; | ||
|
||
expect(response).toBeDefined(); | ||
expect(response).toMatchObject({ | ||
test_data: { | ||
host: 'somewhere.not.sentry', | ||
baggage: expect.stringContaining('sentry-user_id=user123'), | ||
}, | ||
}); | ||
}); |
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