From 6c3da5d7c99e8e33f261d43c3e9d98609010ea19 Mon Sep 17 00:00:00 2001 From: rxlabz Date: Wed, 28 Oct 2020 09:18:11 +0100 Subject: [PATCH 1/2] declare transport dsn as private property --- dart/lib/src/transport/http_transport.dart | 7 ++- dart/test/test_utils.dart | 53 +++++++++++----------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/dart/lib/src/transport/http_transport.dart b/dart/lib/src/transport/http_transport.dart index 2bf0c8a52e..0330d5ecc3 100644 --- a/dart/lib/src/transport/http_transport.dart +++ b/dart/lib/src/transport/http_transport.dart @@ -13,8 +13,7 @@ import 'transport.dart'; class HttpTransport implements Transport { final SentryOptions _options; - @visibleForTesting - final Dsn dsn; + final Dsn _dsn; /// Use for browser stacktrace final String _origin; @@ -26,7 +25,7 @@ class HttpTransport implements Transport { HttpTransport({@required SentryOptions options, String origin}) : _options = options, _origin = origin, - dsn = Dsn.parse(options.dsn), + _dsn = Dsn.parse(options.dsn), _headers = _buildHeaders(sdkIdentifier: options.sdk.identifier) { _credentialBuilder = CredentialBuilder( dsn: Dsn.parse(options.dsn), @@ -46,7 +45,7 @@ class HttpTransport implements Transport { ); final response = await _options.httpClient.post( - dsn.postUri, + _dsn.postUri, headers: _credentialBuilder.configure(_headers), body: body, ); diff --git a/dart/test/test_utils.dart b/dart/test/test_utils.dart index e2ae805539..c338228c6b 100644 --- a/dart/test/test_utils.dart +++ b/dart/test/test_utils.dart @@ -8,7 +8,6 @@ import 'dart:convert'; import 'package:http/http.dart'; import 'package:http/testing.dart'; import 'package:sentry/sentry.dart'; -import 'package:sentry/src/transport/http_transport.dart'; import 'package:test/test.dart'; const String testDsn = 'https://public:secret@sentry.example.com/1'; @@ -89,8 +88,8 @@ Future testCaptureException( expect('$sentryId', 'testeventid'); } - final transport = options.transport as HttpTransport; - expect(postUri, transport.dsn.postUri); + final dsn = Dsn.parse(options.dsn); + expect(postUri, dsn.postUri); testHeaders( headers, @@ -181,16 +180,16 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { final options = SentryOptions(dsn: testDsn); final client = SentryClient(options); - final transport = options.transport as HttpTransport; + final dsn = Dsn.parse(options.dsn); - expect(transport.dsn.uri, Uri.parse(testDsn)); + expect(dsn.uri, Uri.parse(testDsn)); expect( - transport.dsn.postUri, + dsn.postUri, 'https://sentry.example.com/api/1/store/', ); - expect(transport.dsn.publicKey, 'public'); - expect(transport.dsn.secretKey, 'secret'); - expect(transport.dsn.projectId, '1'); + expect(dsn.publicKey, 'public'); + expect(dsn.secretKey, 'secret'); + expect(dsn.projectId, '1'); await client.close(); }); @@ -198,16 +197,16 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { final options = SentryOptions(dsn: _testDsnWithoutSecret); final client = SentryClient(options); - final transport = options.transport as HttpTransport; + final dsn = Dsn.parse(options.dsn); - expect(transport.dsn.uri, Uri.parse(_testDsnWithoutSecret)); + expect(dsn.uri, Uri.parse(_testDsnWithoutSecret)); expect( - transport.dsn.postUri, + dsn.postUri, 'https://sentry.example.com/api/1/store/', ); - expect(transport.dsn.publicKey, 'public'); - expect(transport.dsn.secretKey, null); - expect(transport.dsn.projectId, '1'); + expect(dsn.publicKey, 'public'); + expect(dsn.secretKey, null); + expect(dsn.projectId, '1'); await client.close(); }); @@ -215,32 +214,32 @@ void runTest({Codec, List> gzip, bool isWeb = false}) { final options = SentryOptions(dsn: _testDsnWithPath); final client = SentryClient(options); - final transport = options.transport as HttpTransport; + final dsn = Dsn.parse(options.dsn); - expect(transport.dsn.uri, Uri.parse(_testDsnWithPath)); + expect(dsn.uri, Uri.parse(_testDsnWithPath)); expect( - transport.dsn.postUri, + dsn.postUri, 'https://sentry.example.com/path/api/1/store/', ); - expect(transport.dsn.publicKey, 'public'); - expect(transport.dsn.secretKey, 'secret'); - expect(transport.dsn.projectId, '1'); + expect(dsn.publicKey, 'public'); + expect(dsn.secretKey, 'secret'); + expect(dsn.projectId, '1'); await client.close(); }); test('can parse DSN with port', () async { final options = SentryOptions(dsn: _testDsnWithPort); final client = SentryClient(options); - final transport = options.transport as HttpTransport; + final dsn = Dsn.parse(options.dsn); - expect(transport.dsn.uri, Uri.parse(_testDsnWithPort)); + expect(dsn.uri, Uri.parse(_testDsnWithPort)); expect( - transport.dsn.postUri, + dsn.postUri, 'https://sentry.example.com:8888/api/1/store/', ); - expect(transport.dsn.publicKey, 'public'); - expect(transport.dsn.secretKey, 'secret'); - expect(transport.dsn.projectId, '1'); + expect(dsn.publicKey, 'public'); + expect(dsn.secretKey, 'secret'); + expect(dsn.projectId, '1'); await client.close(); }); test('sends client auth header without secret', () async { From 6d2a7b356fc8bf4d1cdbe5d4ec80a0bcc59b677b Mon Sep 17 00:00:00 2001 From: rxlabz Date: Wed, 28 Oct 2020 09:21:50 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d9342b213..0ac46028e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - Ref: rename sdk files accordely to their content - chore: new analysis options rules - Ref: rename the `throwable` argument name to `exception` in `captureEvents(...)` +- Ref : remove dsn from Transport public Api # `package:sentry` changelog