|
| 1 | +import 'dart:convert'; |
| 2 | + |
1 | 3 | import 'package:http/http.dart';
|
2 | 4 | import 'package:http/testing.dart';
|
3 | 5 | import 'package:mockito/mockito.dart';
|
@@ -281,6 +283,56 @@ void main() {
|
281 | 283 | }
|
282 | 284 | });
|
283 | 285 |
|
| 286 | + test('response body is included according to $MaxResponseBodySize', |
| 287 | + () async { |
| 288 | + final scenarios = [ |
| 289 | + // never |
| 290 | + MaxBodySizeTestConfig(MaxResponseBodySize.never, 0, false), |
| 291 | + MaxBodySizeTestConfig(MaxResponseBodySize.never, 4001, false), |
| 292 | + MaxBodySizeTestConfig(MaxResponseBodySize.never, 10001, false), |
| 293 | + // always |
| 294 | + MaxBodySizeTestConfig(MaxResponseBodySize.always, 0, true), |
| 295 | + MaxBodySizeTestConfig(MaxResponseBodySize.always, 4001, true), |
| 296 | + MaxBodySizeTestConfig(MaxResponseBodySize.always, 10001, true), |
| 297 | + // small |
| 298 | + MaxBodySizeTestConfig(MaxResponseBodySize.small, 0, true), |
| 299 | + MaxBodySizeTestConfig(MaxResponseBodySize.small, 4000, true), |
| 300 | + MaxBodySizeTestConfig(MaxResponseBodySize.small, 4001, false), |
| 301 | + // medium |
| 302 | + MaxBodySizeTestConfig(MaxResponseBodySize.medium, 0, true), |
| 303 | + MaxBodySizeTestConfig(MaxResponseBodySize.medium, 4001, true), |
| 304 | + MaxBodySizeTestConfig(MaxResponseBodySize.medium, 10000, true), |
| 305 | + MaxBodySizeTestConfig(MaxResponseBodySize.medium, 10001, false), |
| 306 | + ]; |
| 307 | + |
| 308 | + fixture._hub.options.captureFailedRequests = true; |
| 309 | + fixture._hub.options.sendDefaultPii = true; |
| 310 | + |
| 311 | + for (final scenario in scenarios) { |
| 312 | + fixture._hub.options.maxResponseBodySize = scenario.maxBodySize; |
| 313 | + fixture.transport.reset(); |
| 314 | + |
| 315 | + final bodyBytes = List.generate(scenario.contentLength, (index) => 0); |
| 316 | + final bodyString = utf8.decode(bodyBytes); |
| 317 | + |
| 318 | + final sut = fixture.getSut( |
| 319 | + client: fixture.getClient(statusCode: 401, body: bodyString), |
| 320 | + failedRequestStatusCodes: [SentryStatusCode(401)], |
| 321 | + ); |
| 322 | + |
| 323 | + final request = Request('GET', requestUri); |
| 324 | + await sut.send(request); |
| 325 | + |
| 326 | + expect(fixture.transport.calls, 1); |
| 327 | + |
| 328 | + final eventCall = fixture.transport.events.first; |
| 329 | + final capturedResponse = eventCall.contexts.response; |
| 330 | + expect(capturedResponse, isNotNull); |
| 331 | + expect(capturedResponse?.data, |
| 332 | + scenario.shouldBeIncluded ? isNotNull : isNull); |
| 333 | + } |
| 334 | + }); |
| 335 | + |
284 | 336 | test('request passed to hint', () async {
|
285 | 337 | fixture._hub.options.captureFailedRequests = true;
|
286 | 338 |
|
|
0 commit comments