diff --git a/flutter/lib/src/event_processor/url_filter/html_url_filter_event_processor.dart b/flutter/lib/src/event_processor/url_filter/html_url_filter_event_processor.dart index 7792f6a333..39b73cb0cb 100644 --- a/flutter/lib/src/event_processor/url_filter/html_url_filter_event_processor.dart +++ b/flutter/lib/src/event_processor/url_filter/html_url_filter_event_processor.dart @@ -15,40 +15,23 @@ class WebUrlFilterEventProcessor implements UrlFilterEventProcessor { this._options, ); + final html.Window _window = html.window; final SentryFlutterOptions _options; @override SentryEvent? apply(SentryEvent event, Hint hint) { - final frames = _getStacktraceFrames(event); - final lastPath = frames?.first?.absPath; - - if (lastPath == null) { - return event; - } + final url = _window.location.toString(); if (_options.allowUrls.isNotEmpty && - !isMatchingRegexPattern(lastPath, _options.allowUrls)) { + !isMatchingRegexPattern(url, _options.allowUrls)) { return null; } if (_options.denyUrls.isNotEmpty && - isMatchingRegexPattern(lastPath, _options.denyUrls)) { + isMatchingRegexPattern(url, _options.denyUrls)) { return null; } return event; } - - Iterable? _getStacktraceFrames(SentryEvent event) { - if (event.exceptions?.isNotEmpty == true) { - return event.exceptions?.first.stackTrace?.frames; - } - if (event.threads?.isNotEmpty == true) { - final stacktraces = event.threads?.map((e) => e.stacktrace); - return stacktraces - ?.where((element) => element != null) - .expand((element) => element!.frames); - } - return null; - } } diff --git a/flutter/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart b/flutter/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart index 10cfee3478..3b94afeed8 100644 --- a/flutter/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart +++ b/flutter/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart @@ -17,40 +17,23 @@ class WebUrlFilterEventProcessor implements UrlFilterEventProcessor { this._options, ); + final web.Window _window = web.window; final SentryFlutterOptions _options; @override SentryEvent? apply(SentryEvent event, Hint hint) { - final frames = _getStacktraceFrames(event); - final lastPath = frames?.first?.absPath; - - if (lastPath == null) { - return event; - } + final url = _window.location.toString(); if (_options.allowUrls.isNotEmpty && - !isMatchingRegexPattern(lastPath, _options.allowUrls)) { + !isMatchingRegexPattern(url, _options.allowUrls)) { return null; } if (_options.denyUrls.isNotEmpty && - isMatchingRegexPattern(lastPath, _options.denyUrls)) { + isMatchingRegexPattern(url, _options.denyUrls)) { return null; } return event; } - - Iterable? _getStacktraceFrames(SentryEvent event) { - if (event.exceptions?.isNotEmpty == true) { - return event.exceptions?.first.stackTrace?.frames; - } - if (event.threads?.isNotEmpty == true) { - final stacktraces = event.threads?.map((e) => e.stacktrace); - return stacktraces - ?.where((element) => element != null) - .expand((element) => element!.frames); - } - return null; - } } diff --git a/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart b/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart index f16f5c5003..5fb5f7039d 100644 --- a/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart +++ b/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart @@ -7,6 +7,8 @@ import 'package:sentry_flutter/src/event_processor/url_filter/url_filter_event_p // can be tested on command line with // `flutter test --platform=chrome test/event_processor/url_filter/web_url_filter_event_processor_test.dart` +// The URL looks something like this: http://localhost:58551/event_processor/url_filter/web_url_filter_event_processor_test.html + void main() { group(UrlFilterEventProcessor, () { late Fixture fixture; @@ -16,24 +18,20 @@ void main() { }); test('returns event if no allowUrl and no denyUrl is set', () async { - SentryEvent? event = SentryEvent( - request: SentryRequest( - url: 'foo.bar', - ), - ); + final event = SentryEvent(); + final eventProcessor = fixture.getSut(); - var eventProcessor = fixture.getSut(); - event = await eventProcessor.apply(event, Hint()); + final processedEvent = await eventProcessor.apply(event, Hint()); - expect(event, isNotNull); + expect(processedEvent, isNotNull); }); test('returns null if allowUrl is set and does not match with url', () async { - final event = _createEventWithException("foo.bar"); + final event = SentryEvent(); fixture.options.allowUrls = ["another.url"]; + final eventProcessor = fixture.getSut(); - var eventProcessor = fixture.getSut(); final processedEvent = await eventProcessor.apply(event, Hint()); expect(processedEvent, isNull); @@ -41,10 +39,10 @@ void main() { test('returns event if allowUrl is set and does partially match with url', () async { - final event = _createEventWithException("foo.bar"); - fixture.options.allowUrls = ["bar"]; + final event = SentryEvent(); + fixture.options.allowUrls = ["event_processor_test"]; + final eventProcessor = fixture.getSut(); - var eventProcessor = fixture.getSut(); final processedEvent = await eventProcessor.apply(event, Hint()); expect(processedEvent, isNotNull); @@ -52,10 +50,10 @@ void main() { test('returns event if denyUrl is set and does not match with url', () async { - final event = _createEventWithException("foo.bar"); + final event = SentryEvent(); fixture.options.denyUrls = ["another.url"]; + final eventProcessor = fixture.getSut(); - var eventProcessor = fixture.getSut(); final processedEvent = await eventProcessor.apply(event, Hint()); expect(processedEvent, isNotNull); @@ -63,10 +61,10 @@ void main() { test('returns null if denyUrl is set and partially matches with url', () async { - final event = _createEventWithException("foo.bar"); - fixture.options.denyUrls = ["bar"]; + final event = SentryEvent(); + fixture.options.denyUrls = ["event_processor_test"]; + final eventProcessor = fixture.getSut(); - var eventProcessor = fixture.getSut(); final processedEvent = await eventProcessor.apply(event, Hint()); expect(processedEvent, isNull); @@ -75,13 +73,11 @@ void main() { test( 'returns null if it is part of the allowed domain, but blocked for subdomain', () async { - final event = _createEventWithException( - "this.is/a/special/url/for-testing/this-feature"); - - fixture.options.allowUrls = ["^this.is/.*\$"]; - fixture.options.denyUrls = ["special"]; + final event = SentryEvent(); + fixture.options.allowUrls = [".*localhost.*\$"]; + fixture.options.denyUrls = ["event"]; + final eventProcessor = fixture.getSut(); - var eventProcessor = fixture.getSut(); final processedEvent = await eventProcessor.apply(event, Hint()); expect(processedEvent, isNull); @@ -90,12 +86,11 @@ void main() { test( 'returns event if it is part of the allowed domain, and not of the blocked for subdomain', () async { - final event = _createEventWithException( - "this.is/a/test/url/for-testing/this-feature"); - fixture.options.allowUrls = ["^this.is/.*\$"]; + final event = SentryEvent(); + fixture.options.allowUrls = [".*localhost.*\$"]; fixture.options.denyUrls = ["special"]; + final eventProcessor = fixture.getSut(); - var eventProcessor = fixture.getSut(); final processedEvent = await eventProcessor.apply(event, Hint()); expect(processedEvent, isNotNull); @@ -104,60 +99,15 @@ void main() { test( 'returns null if it is not part of the allowed domain, and not of the blocked for subdomain', () async { - final event = _createEventWithException( - "another.url/for/a/test/testing/this-feature"); + final event = SentryEvent(); fixture.options.allowUrls = ["^this.is/.*\$"]; fixture.options.denyUrls = ["special"]; + final eventProcessor = fixture.getSut(); - var eventProcessor = fixture.getSut(); final processedEvent = await eventProcessor.apply(event, Hint()); expect(processedEvent, isNull); }); - - test( - 'returns event if denyUrl is set and not matching with url of first exception', - () async { - final frame1 = SentryStackFrame(absPath: "test.url"); - final st1 = SentryStackTrace(frames: [frame1]); - final exception1 = SentryException( - type: "test-type", value: "test-value", stackTrace: st1); - - final frame2 = SentryStackFrame(absPath: "foo.bar"); - final st2 = SentryStackTrace(frames: [frame2]); - final exception2 = SentryException( - type: "test-type", value: "test-value", stackTrace: st2); - - SentryEvent event = SentryEvent(exceptions: [exception1, exception2]); - - fixture.options.denyUrls = ["bar"]; - - var eventProcessor = fixture.getSut(); - final processedEvent = await eventProcessor.apply(event, Hint()); - - expect(processedEvent, isNotNull); - }); - - test( - 'returns event if denyUrl is set and not matching with url of first stacktraceframe', - () async { - final frame1 = SentryStackFrame(absPath: "test.url"); - final st1 = SentryStackTrace(frames: [frame1]); - final thread1 = SentryThread(stacktrace: st1); - - final frame2 = SentryStackFrame(absPath: "foo.bar"); - final st2 = SentryStackTrace(frames: [frame2]); - final thread2 = SentryThread(stacktrace: st2); - - SentryEvent event = SentryEvent(threads: [thread1, thread2]); - - fixture.options.denyUrls = ["bar"]; - - var eventProcessor = fixture.getSut(); - final processedEvent = await eventProcessor.apply(event, Hint()); - - expect(processedEvent, isNotNull); - }); }); } @@ -167,13 +117,3 @@ class Fixture { return UrlFilterEventProcessor(options); } } - -SentryEvent _createEventWithException(String url) { - final frame = SentryStackFrame(absPath: url); - final st = SentryStackTrace(frames: [frame]); - final exception = - SentryException(type: "test-type", value: "test-value", stackTrace: st); - SentryEvent event = SentryEvent(exceptions: [exception]); - - return event; -}