Skip to content

Commit

Permalink
rephrased documentation and split up tests for web and mobile platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhaintz committed Aug 14, 2024
1 parent 8523a6d commit a30a862
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 175 deletions.
4 changes: 2 additions & 2 deletions flutter/lib/src/sentry_flutter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ class SentryFlutterOptions extends SentryOptions {

/// (Web only) Events only occurring on these Urls will be handled and sent to sentry.
/// If an empty list is used, the SDK will send all errors.
/// To use regex add the `^` and the `$` to the string.
/// `allowUrls` uses regex for the matching.
///
/// If used on a platform other than Web, this setting will be ignored.
List<String> allowUrls = [];

/// (Web only) Events occurring on these Urls will be ignored and are not sent to sentry.
/// If an empty list is used, the SDK will send all errors.
/// `denyUrls` uses regex for the matching.
/// In combination with `allowUrls` you can block subdomains of the domains listed in `allowUrls`.
/// To use regex add the `^` and the `$` to the string.
///
/// If used on a platform other than Web, this setting will be ignored.
List<String> denyUrls = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@TestOn('vm')
library flutter_test;

import 'package:flutter_test/flutter_test.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/event_processor/url_filter/url_filter_event_processor.dart';

void main() {
group("ignore allowUrls and denyUrls for non Web", () {
late Fixture fixture;

setUp(() async {
fixture = Fixture();
});

test('returns the event and ignore allowUrls and denyUrls for non Web',
() async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'another.url/for/a/special/test/testing/this-feature',
),
);
fixture.options.allowUrls = ["^this.is/.*\$"];
fixture.options.denyUrls = ["special"];

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNotNull);
});
});
}

class Fixture {
SentryFlutterOptions options = SentryFlutterOptions();
UrlFilterEventProcessor getSut() {
return UrlFilterEventProcessor(options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
@TestOn('browser')
library flutter_test;

import 'package:flutter_test/flutter_test.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/event_processor/url_filter/url_filter_event_processor.dart';

// can be tested on command line with
// `flutter test --platform=chrome test/event_processor/url_filter/web_url_filter_event_processor_test.dart`
void main() {
group(UrlFilterEventProcessor, () {
late Fixture fixture;

setUp(() {
fixture = Fixture();
});

test('returns event if no allowUrl and no denyUrl is set', () async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'foo.bar',
),
);

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNotNull);
});

test('returns null if allowUrl is set and does not match with url',
() async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'foo.bar',
),
);
fixture.options.allowUrls = ["another.url"];

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNull);
});

test('returns event if allowUrl is set and does partially match with url',
() async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'foo.bar',
),
);
fixture.options.allowUrls = ["bar"];

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNotNull);
});

test('returns event if denyUrl is set and does not match with url',
() async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'foo.bar',
),
);
fixture.options.denyUrls = ["another.url"];

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNotNull);
});

test('returns null if denyUrl is set and partially matches with url',
() async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'foo.bar',
),
);
fixture.options.denyUrls = ["bar"];

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNull);
});

test(
'returns null if it is part of the allowed domain, but blocked for subdomain',
() async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'this.is/a/special/url/for-testing/this-feature',
),
);
fixture.options.allowUrls = ["^this.is/.*\$"];
fixture.options.denyUrls = ["special"];

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNull);
});

test(
'returns event if it is part of the allowed domain, and not of the blocked for subdomain',
() async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'this.is/a/test/url/for-testing/this-feature',
),
);
fixture.options.allowUrls = ["^this.is/.*\$"];
fixture.options.denyUrls = ["special"];

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNotNull);
});

test(
'returns null if it is not part of the allowed domain, and not of the blocked for subdomain',
() async {
SentryEvent? event = SentryEvent(
request: SentryRequest(
url: 'another.url/for/a/test/testing/this-feature',
),
);
fixture.options.allowUrls = ["^this.is/.*\$"];
fixture.options.denyUrls = ["special"];

var eventProcessor = fixture.getSut();
event = await eventProcessor.apply(event, Hint());

expect(event, isNull);
});
});
}

class Fixture {
SentryFlutterOptions options = SentryFlutterOptions();
UrlFilterEventProcessor getSut() {
return UrlFilterEventProcessor(options);
}
}
173 changes: 0 additions & 173 deletions flutter/test/event_processor/url_filter_event_processor_test.dart

This file was deleted.

0 comments on commit a30a862

Please sign in to comment.