Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support dsn that use non-regular port or contains prefix path (getsen…
…try#42)

1. dsn may specify non-regular port
2. dsn may contains some paths before the projectID
  • Loading branch information
yrom authored and yjbanov committed Oct 16, 2019
commit 79ea1531cf869fefddeb55df07c726374682f75e
19 changes: 17 additions & 2 deletions lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,23 @@ class SentryClient {
User userContext;

@visibleForTesting
String get postUri =>
'${dsnUri.scheme}://${dsnUri.host}/api/$projectId/store/';
String get postUri {
String port = dsnUri.hasPort &&
((dsnUri.scheme == 'http' && dsnUri.port != 80) ||
(dsnUri.scheme == 'https' && dsnUri.port != 443))
? ':${dsnUri.port}'
: '';
int pathLength = dsnUri.pathSegments.length;
String apiPath;
if (pathLength > 1) {
// some paths would present before the projectID in the dsnUri
apiPath =
(dsnUri.pathSegments.sublist(0, pathLength - 1) + ['api']).join('/');
} else {
apiPath = 'api';
}
return '${dsnUri.scheme}://${dsnUri.host}${port}/$apiPath/$projectId/store/';
}

/// Reports an [event] to Sentry.io.
Future<SentryResponse> capture(
Expand Down
23 changes: 22 additions & 1 deletion test/sentry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import 'package:test/test.dart';

const String _testDsn = 'https://public:[email protected]/1';
const String _testDsnWithoutSecret = 'https://[email protected]/1';

const String _testDsnWithPath =
'https://public:[email protected]/path/1';
const String _testDsnWithPort =
'https://public:[email protected]:8888/1';
void main() {
group('$SentryClient', () {
test('can parse DSN', () async {
Expand All @@ -34,6 +37,24 @@ void main() {
await client.close();
});

test('can parse DSN with path', () async {
final SentryClient client = new SentryClient(dsn: _testDsnWithPath);
expect(client.dsnUri, Uri.parse(_testDsnWithPath));
expect(client.postUri, 'https://sentry.example.com/path/api/1/store/');
expect(client.publicKey, 'public');
expect(client.secretKey, 'secret');
expect(client.projectId, '1');
await client.close();
});
test('can parse DSN with port', () async {
final SentryClient client = new SentryClient(dsn: _testDsnWithPort);
expect(client.dsnUri, Uri.parse(_testDsnWithPort));
expect(client.postUri, 'https://sentry.example.com:8888/api/1/store/');
expect(client.publicKey, 'public');
expect(client.secretKey, 'secret');
expect(client.projectId, '1');
await client.close();
});
test('sends client auth header without secret', () async {
final MockClient httpMock = new MockClient();
final ClockProvider fakeClockProvider =
Expand Down