-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Use makeDsn from core to extract the URL from DSN for filt…
…ering breadcrumbs (#4395)
- Loading branch information
Showing
3 changed files
with
57 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,7 +321,7 @@ describe('Tests the SDK functionality', () => { | |
expect(result).toBeNull(); | ||
}); | ||
|
||
it('should filters out dsn breadcrumbs', () => { | ||
it('should filter out dsn breadcrumbs', () => { | ||
(getDevServer as jest.Mock).mockReturnValue({ url: 'http://localhost:8081' }); | ||
|
||
const mockBeforeBreadcrumb = (breadcrumb: Breadcrumb, _hint?: BreadcrumbHint) => { | ||
|
@@ -345,37 +345,76 @@ describe('Tests the SDK functionality', () => { | |
expect(result).toBeNull(); | ||
}); | ||
|
||
it('should keep breadcrumbs matching dsn if the url parsing fails for dsn', () => { | ||
it('should filter out dsn breadcrumbs that the ports match', () => { | ||
(getDevServer as jest.Mock).mockReturnValue({ url: 'http://localhost:8081' }); | ||
|
||
const mockBeforeBreadcrumb = (breadcrumb: Breadcrumb, _hint?: BreadcrumbHint) => { | ||
return breadcrumb; | ||
}; | ||
|
||
// Mock the URL constructor to throw an exception for this test case | ||
const originalURL = (global as any).URL; | ||
jest.spyOn(global as any, 'URL').mockImplementationOnce(() => { | ||
throw new Error('Failed to parse DSN URL'); | ||
}); | ||
const passedOptions = { | ||
dsn: 'https://[email protected]:8181/1234567', | ||
beforeBreadcrumb: mockBeforeBreadcrumb, | ||
}; | ||
|
||
init(passedOptions); | ||
|
||
const breadcrumb: Breadcrumb = { | ||
type: 'http', | ||
data: { url: 'https://selfhosted.app.server:8181/api' }, | ||
}; | ||
|
||
const result = usedOptions()?.beforeBreadcrumb!(breadcrumb); | ||
|
||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('should keep breadcrumbs if the ports do not match', () => { | ||
(getDevServer as jest.Mock).mockReturnValue({ url: 'http://localhost:8081' }); | ||
|
||
const mockBeforeBreadcrumb = (breadcrumb: Breadcrumb, _hint?: BreadcrumbHint) => { | ||
return breadcrumb; | ||
}; | ||
|
||
const passedOptions = { | ||
dsn: 'https://[email protected]/1234567', | ||
dsn: 'https://[email protected]:8181/1234567', | ||
beforeBreadcrumb: mockBeforeBreadcrumb, | ||
}; | ||
|
||
init(passedOptions); | ||
|
||
const breadcrumb: Breadcrumb = { | ||
type: 'http', | ||
data: { url: 'https://def.ingest.sentry.io/1234567' }, | ||
data: { url: 'https://selfhosted.app.server:8080/api' }, | ||
}; | ||
|
||
const result = usedOptions()?.beforeBreadcrumb!(breadcrumb); | ||
|
||
expect(result).toEqual(breadcrumb); | ||
}); | ||
|
||
it('should keep breadcrumbs if the url parsing fails for dsn', () => { | ||
(getDevServer as jest.Mock).mockReturnValue({ url: 'http://localhost:8081' }); | ||
|
||
const mockBeforeBreadcrumb = (breadcrumb: Breadcrumb, _hint?: BreadcrumbHint) => { | ||
return breadcrumb; | ||
}; | ||
|
||
const passedOptions = { | ||
dsn: 'invalid-dsn', | ||
beforeBreadcrumb: mockBeforeBreadcrumb, | ||
}; | ||
|
||
init(passedOptions); | ||
|
||
// Restore the original URL constructor | ||
(global as any).URL = originalURL; | ||
const breadcrumb: Breadcrumb = { | ||
type: 'http', | ||
data: { url: 'https://def.ingest.sentry.io/1234567' }, | ||
}; | ||
|
||
const result = usedOptions()?.beforeBreadcrumb!(breadcrumb); | ||
|
||
expect(result).toEqual(breadcrumb); | ||
}); | ||
|
||
it('should keep non dev server or dsn breadcrumbs', () => { | ||
|