@@ -2,24 +2,41 @@ import { EventProcessor } from '@sentry/types';
22
33import { InboundFilters , InboundFiltersOptions } from '../../../src/integrations/inboundfilters' ;
44
5- /** JSDoc */
5+ /**
6+ * Creates an instance of the InboundFilters integration and returns
7+ * the event processor that the InboundFilters integration creates.
8+ *
9+ * To test the InboundFilters integration, call this function and assert on
10+ * how the event processor handles an event. For example, if you set up the
11+ * InboundFilters to filter out an SOME_EXCEPTION_EVENT.
12+ *
13+ * ```
14+ * // some options that cause SOME_EXCEPTION_EVENT to be filtered
15+ * const eventProcessor = createInboundFiltersEventProcessor(options);
16+ *
17+ * expect(eventProcessor(SOME_EXCEPTION_EVENT)).toBe(null);
18+ * ```
19+ *
20+ * @param options options passed into the InboundFilters integration
21+ * @param clientOptions options passed into the mock Sentry client
22+ */
623function createInboundFiltersEventProcessor (
724 options : Partial < InboundFiltersOptions > = { } ,
825 clientOptions : Partial < InboundFiltersOptions > = { } ,
926) : EventProcessor {
1027 const eventProcessors : EventProcessor [ ] = [ ] ;
11- const inboundFilters = new InboundFilters ( options ) ;
28+ const inboundFiltersInstance = new InboundFilters ( options ) ;
1229
13- function addGlobalEventProcessor ( callback : EventProcessor ) : void {
14- eventProcessors . push ( callback ) ;
30+ function addGlobalEventProcessor ( processor : EventProcessor ) : void {
31+ eventProcessors . push ( processor ) ;
1532 expect ( eventProcessors ) . toHaveLength ( 1 ) ;
1633 }
1734
1835 function getCurrentHub ( ) : any {
1936 return {
2037 getIntegration ( _integration : any ) : any {
2138 // pretend integration is enabled
22- return inboundFilters ;
39+ return inboundFiltersInstance ;
2340 } ,
2441 getClient ( ) : any {
2542 return {
@@ -29,13 +46,12 @@ function createInboundFiltersEventProcessor(
2946 } ;
3047 }
3148
32- inboundFilters . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ;
33-
49+ inboundFiltersInstance . setupOnce ( addGlobalEventProcessor , getCurrentHub ) ;
3450 return eventProcessors [ 0 ] ;
3551}
3652
3753describe ( 'InboundFilters' , ( ) => {
38- describe ( 'isSentryError ' , ( ) => {
54+ describe ( '_isSentryError ' , ( ) => {
3955 it ( 'should work as expected' , ( ) => {
4056 const eventProcessor = createInboundFiltersEventProcessor ( ) ;
4157 expect ( eventProcessor ( MESSAGE_EVENT ) ) . toBe ( MESSAGE_EVENT ) ;
@@ -81,7 +97,7 @@ describe('InboundFilters', () => {
8197 expect ( eventProcessor ( MESSAGE_EVENT_2 ) ) . toBe ( MESSAGE_EVENT_2 ) ;
8298 } ) ;
8399
84- it ( 'uses message when both, message and exception are available' , ( ) => {
100+ it ( 'prefers message when both message and exception are available' , ( ) => {
85101 const eventProcessor = createInboundFiltersEventProcessor ( {
86102 ignoreErrors : [ / c a p t u r e M e s s a g e / ] ,
87103 } ) ;
@@ -102,11 +118,11 @@ describe('InboundFilters', () => {
102118
103119 it ( 'uses default filters' , ( ) => {
104120 const eventProcessor = createInboundFiltersEventProcessor ( ) ;
105- expect ( eventProcessor ( DEFAULT_EVENT ) ) . toBe ( null ) ;
121+ expect ( eventProcessor ( SCRIPT_ERROR_EVENT ) ) . toBe ( null ) ;
106122 } ) ;
107123
108124 describe ( 'on exception' , ( ) => {
109- it ( 'uses exceptions data when message is unavailable' , ( ) => {
125+ it ( 'uses exception data when message is unavailable' , ( ) => {
110126 const eventProcessor = createInboundFiltersEventProcessor ( {
111127 ignoreErrors : [ 'SyntaxError: unidentified ? at line 1337' ] ,
112128 } ) ;
@@ -131,19 +147,18 @@ describe('InboundFilters', () => {
131147
132148 describe ( 'denyUrls/allowUrls' , ( ) => {
133149 it ( 'should filter captured message based on its stack trace using string filter' , ( ) => {
134- const eventProcessorBoth = createInboundFiltersEventProcessor ( {
135- allowUrls : [ 'https://awesome-analytics.io' ] ,
150+ const eventProcessorDeny = createInboundFiltersEventProcessor ( {
136151 denyUrls : [ 'https://awesome-analytics.io' ] ,
137152 } ) ;
138- expect ( eventProcessorBoth ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( null ) ;
139- const eventProcessorAllow = createInboundFiltersEventProcessor ( {
153+ expect ( eventProcessorDeny ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( null ) ;
154+ } ) ;
155+
156+ it ( 'should allow denyUrls to take precedence' , ( ) => {
157+ const eventProcessorBoth = createInboundFiltersEventProcessor ( {
140158 allowUrls : [ 'https://awesome-analytics.io' ] ,
141- } ) ;
142- expect ( eventProcessorAllow ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( MESSAGE_EVENT_WITH_STACKTRACE ) ;
143- const eventProcessorDeny = createInboundFiltersEventProcessor ( {
144159 denyUrls : [ 'https://awesome-analytics.io' ] ,
145160 } ) ;
146- expect ( eventProcessorDeny ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( null ) ;
161+ expect ( eventProcessorBoth ( MESSAGE_EVENT_WITH_STACKTRACE ) ) . toBe ( null ) ;
147162 } ) ;
148163
149164 it ( 'should filter captured message based on its stack trace using regexp filter' , ( ) => {
@@ -167,7 +182,7 @@ describe('InboundFilters', () => {
167182 expect ( eventProcessor ( EXCEPTION_EVENT_WITH_FRAMES ) ) . toBe ( null ) ;
168183 } ) ;
169184
170- it ( 'should filter captured exceptions based on its stack trace using regexp filter' , ( ) => {
185+ it ( 'should filter captured exception based on its stack trace using regexp filter' , ( ) => {
171186 const eventProcessor = createInboundFiltersEventProcessor ( {
172187 denyUrls : [ / a w e s o m e - a n a l y t i c s \. i o / ] ,
173188 } ) ;
@@ -199,14 +214,14 @@ describe('InboundFilters', () => {
199214 const eventProcessor = createInboundFiltersEventProcessor ( {
200215 denyUrls : [ 'https://awesome-analytics.io/some/file.js' ] ,
201216 } ) ;
202- expect ( eventProcessor ( MESSAGE_EVENT_WITH_ANON_FRAME ) ) . toBe ( null ) ;
217+ expect ( eventProcessor ( MESSAGE_EVENT_WITH_ANON_LAST_FRAME ) ) . toBe ( null ) ;
203218 } ) ;
204219
205220 it ( 'should search for script names when the last frame is from native code' , ( ) => {
206221 const eventProcessor = createInboundFiltersEventProcessor ( {
207222 denyUrls : [ 'https://awesome-analytics.io/some/file.js' ] ,
208223 } ) ;
209- expect ( eventProcessor ( MESSAGE_EVENT_WITH_NATIVE_FRAME ) ) . toBe ( null ) ;
224+ expect ( eventProcessor ( MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME ) ) . toBe ( null ) ;
210225 } ) ;
211226 } ) ;
212227} ) ;
@@ -234,7 +249,7 @@ const MESSAGE_EVENT_WITH_STACKTRACE = {
234249 } ,
235250} ;
236251
237- const MESSAGE_EVENT_WITH_ANON_FRAME = {
252+ const MESSAGE_EVENT_WITH_ANON_LAST_FRAME = {
238253 message : 'any' ,
239254 stacktrace : {
240255 frames : [
@@ -245,7 +260,7 @@ const MESSAGE_EVENT_WITH_ANON_FRAME = {
245260 } ,
246261} ;
247262
248- const MESSAGE_EVENT_WITH_NATIVE_FRAME = {
263+ const MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME = {
249264 message : 'any' ,
250265 stacktrace : {
251266 frames : [
@@ -296,7 +311,7 @@ const SENTRY_EVENT = {
296311 } ,
297312} ;
298313
299- const DEFAULT_EVENT = {
314+ const SCRIPT_ERROR_EVENT = {
300315 exception : {
301316 values : [
302317 {
0 commit comments