@@ -6,11 +6,11 @@ import 'dart:convert';
6
6
import 'dart:io' ;
7
7
8
8
import 'package:http/http.dart' ;
9
- import 'package:quiver/time.dart' ;
10
9
import 'package:sentry/sentry.dart' ;
11
10
import 'package:test/test.dart' ;
12
11
13
12
const String _testDsn
= 'https://public:[email protected] /1' ;
13
+ const String _testDsnWithoutSecret
= 'https://[email protected] /1' ;
14
14
15
15
void main () {
16
16
group ('$SentryClient ' , () {
@@ -24,9 +24,75 @@ void main() {
24
24
await client.close ();
25
25
});
26
26
27
+ test ('can parse DSN without secret' , () async {
28
+ final SentryClient client = new SentryClient (dsn: _testDsnWithoutSecret);
29
+ expect (client.dsnUri, Uri .parse (_testDsnWithoutSecret));
30
+ expect (client.postUri, 'https://sentry.example.com/api/1/store/' );
31
+ expect (client.publicKey, 'public' );
32
+ expect (client.secretKey, null );
33
+ expect (client.projectId, '1' );
34
+ await client.close ();
35
+ });
36
+
37
+ test ('sends client auth header without secret' , () async {
38
+ final MockClient httpMock = new MockClient ();
39
+ final ClockProvider fakeClockProvider =
40
+ () => new DateTime .utc (2017 , 1 , 2 );
41
+
42
+ Map <String , String > headers;
43
+
44
+ httpMock.answerWith ((Invocation invocation) async {
45
+ if (invocation.memberName == #close) {
46
+ return null ;
47
+ }
48
+ if (invocation.memberName == #post) {
49
+ headers = invocation.namedArguments[#headers];
50
+ return new Response ('{"id": "test-event-id"}' , 200 );
51
+ }
52
+ fail ('Unexpected invocation of ${invocation .memberName } in HttpMock' );
53
+ });
54
+
55
+ final SentryClient client = new SentryClient (
56
+ dsn: _testDsnWithoutSecret,
57
+ httpClient: httpMock,
58
+ clock: fakeClockProvider,
59
+ compressPayload: false ,
60
+ uuidGenerator: () => 'X' * 32 ,
61
+ environmentAttributes: const Event (
62
+ serverName: 'test.server.com' ,
63
+ release: '1.2.3' ,
64
+ environment: 'staging' ,
65
+ ),
66
+ );
67
+
68
+ try {
69
+ throw new ArgumentError ('Test error' );
70
+ } catch (error, stackTrace) {
71
+ final SentryResponse response = await client.captureException (
72
+ exception: error, stackTrace: stackTrace);
73
+ expect (response.isSuccessful, true );
74
+ expect (response.eventId, 'test-event-id' );
75
+ expect (response.error, null );
76
+ }
77
+
78
+ final Map <String , String > expectedHeaders = < String , String > {
79
+ 'User-Agent' : '$sdkName /$sdkVersion ' ,
80
+ 'Content-Type' : 'application/json' ,
81
+ 'X-Sentry-Auth' : 'Sentry sentry_version=6, '
82
+ 'sentry_client=${SentryClient .sentryClient }, '
83
+ 'sentry_timestamp=${fakeClockProvider ().millisecondsSinceEpoch }, '
84
+ 'sentry_key=public' ,
85
+ };
86
+
87
+ expect (headers, expectedHeaders);
88
+
89
+ await client.close ();
90
+ });
91
+
27
92
testCaptureException (bool compressPayload) async {
28
93
final MockClient httpMock = new MockClient ();
29
- final Clock fakeClock = new Clock .fixed (new DateTime .utc (2017 , 1 , 2 ));
94
+ final ClockProvider fakeClockProvider =
95
+ () => new DateTime .utc (2017 , 1 , 2 );
30
96
31
97
String postUri;
32
98
Map <String , String > headers;
@@ -47,7 +113,7 @@ void main() {
47
113
final SentryClient client = new SentryClient (
48
114
dsn: _testDsn,
49
115
httpClient: httpMock,
50
- clock: fakeClock ,
116
+ clock: fakeClockProvider ,
51
117
uuidGenerator: () => 'X' * 32 ,
52
118
compressPayload: compressPayload,
53
119
environmentAttributes: const Event (
@@ -74,9 +140,7 @@ void main() {
74
140
'Content-Type' : 'application/json' ,
75
141
'X-Sentry-Auth' : 'Sentry sentry_version=6, '
76
142
'sentry_client=${SentryClient .sentryClient }, '
77
- 'sentry_timestamp=${fakeClock
78
- .now ()
79
- .millisecondsSinceEpoch }, '
143
+ 'sentry_timestamp=${fakeClockProvider ().millisecondsSinceEpoch }, '
80
144
'sentry_key=public, '
81
145
'sentry_secret=secret' ,
82
146
};
@@ -133,7 +197,8 @@ void main() {
133
197
134
198
test ('reads error message from the x-sentry-error header' , () async {
135
199
final MockClient httpMock = new MockClient ();
136
- final Clock fakeClock = new Clock .fixed (new DateTime (2017 , 1 , 2 ));
200
+ final ClockProvider fakeClockProvider =
201
+ () => new DateTime .utc (2017 , 1 , 2 );
137
202
138
203
httpMock.answerWith ((Invocation invocation) async {
139
204
if (invocation.memberName == #close) {
@@ -150,7 +215,7 @@ void main() {
150
215
final SentryClient client = new SentryClient (
151
216
dsn: _testDsn,
152
217
httpClient: httpMock,
153
- clock: fakeClock ,
218
+ clock: fakeClockProvider ,
154
219
uuidGenerator: () => 'X' * 32 ,
155
220
compressPayload: false ,
156
221
environmentAttributes: const Event (
@@ -176,7 +241,8 @@ void main() {
176
241
177
242
test ('$Event userContext overrides client' , () async {
178
243
final MockClient httpMock = new MockClient ();
179
- final Clock fakeClock = new Clock .fixed (new DateTime (2017 , 1 , 2 ));
244
+ final ClockProvider fakeClockProvider =
245
+ () => new DateTime .utc (2017 , 1 , 2 );
180
246
181
247
String loggedUserId; // used to find out what user context was sent
182
248
httpMock.answerWith ((Invocation invocation) async {
@@ -211,7 +277,7 @@ void main() {
211
277
final SentryClient client = new SentryClient (
212
278
dsn: _testDsn,
213
279
httpClient: httpMock,
214
- clock: fakeClock ,
280
+ clock: fakeClockProvider ,
215
281
uuidGenerator: () => 'X' * 32 ,
216
282
compressPayload: false ,
217
283
environmentAttributes: const Event (
0 commit comments