@@ -60,6 +60,10 @@ void main() {
60
60
"isW3cCaughtHeaderEnabled" : true ,
61
61
}),
62
62
);
63
+ when (mManager.didRequestBodyExceedSizeLimit (any))
64
+ .thenAnswer ((_) async => false );
65
+ when (mManager.didResponseBodyExceedSizeLimit (any))
66
+ .thenAnswer ((_) async => false );
63
67
});
64
68
65
69
test ('[networkLog] should call 1 host method on iOS' , () async {
@@ -239,4 +243,152 @@ void main() {
239
243
mInstabugHost.setNetworkLogBodyEnabled (enabled),
240
244
).called (1 );
241
245
});
246
+
247
+ group ('[networkLogInternal] body size limit tests' , () {
248
+ test ('should replace request body when it exceeds size limit' , () async {
249
+ final largeRequestData = data.copyWith (
250
+ requestBodySize: 15000 , // 15KB > 10KB default
251
+ responseBodySize: 5000 , // 5KB < 10KB default
252
+ );
253
+
254
+ when (mBuildInfo.isAndroid).thenReturn (true );
255
+ when (mManager.obfuscateLog (any)).thenAnswer ((invocation) async {
256
+ final inputData = invocation.positionalArguments[0 ] as NetworkData ;
257
+ return inputData;
258
+ });
259
+ when (mManager.omitLog (largeRequestData)).thenReturn (false );
260
+ when (mManager.didRequestBodyExceedSizeLimit (largeRequestData))
261
+ .thenAnswer ((_) async => true );
262
+ when (mManager.didResponseBodyExceedSizeLimit (largeRequestData))
263
+ .thenAnswer ((_) async => false );
264
+
265
+ await logger.networkLogInternal (largeRequestData);
266
+
267
+ // Verify that obfuscateLog was called with modified data
268
+ verify (mManager.obfuscateLog (argThat (
269
+ predicate <NetworkData >((processedData) =>
270
+ processedData.requestBody ==
271
+ '[REQUEST_BODY_REPLACED] - Size: 15000 exceeds limit' &&
272
+ processedData.responseBody == largeRequestData.responseBody),
273
+ ))).called (1 );
274
+
275
+ // Verify that networkLog was called
276
+ verify (mInstabugHost.networkLog (any)).called (1 );
277
+ verify (mApmHost.networkLogAndroid (any)).called (1 );
278
+ });
279
+
280
+ test ('should replace response body when it exceeds size limit' , () async {
281
+ final largeResponseData = data.copyWith (
282
+ requestBodySize: 5000 , // 5KB < 10KB default
283
+ responseBodySize: 15000 , // 15KB > 10KB default
284
+ );
285
+
286
+ when (mBuildInfo.isAndroid).thenReturn (true );
287
+ when (mManager.obfuscateLog (any)).thenAnswer ((invocation) async {
288
+ final inputData = invocation.positionalArguments[0 ] as NetworkData ;
289
+ return inputData;
290
+ });
291
+ when (mManager.omitLog (largeResponseData)).thenReturn (false );
292
+ when (mManager.didRequestBodyExceedSizeLimit (largeResponseData))
293
+ .thenAnswer ((_) async => false );
294
+ when (mManager.didResponseBodyExceedSizeLimit (largeResponseData))
295
+ .thenAnswer ((_) async => true );
296
+
297
+ await logger.networkLogInternal (largeResponseData);
298
+
299
+ // Verify that obfuscateLog was called with modified data
300
+ verify (mManager.obfuscateLog (argThat (
301
+ predicate <NetworkData >((processedData) =>
302
+ processedData.requestBody == largeResponseData.requestBody &&
303
+ processedData.responseBody ==
304
+ '[RESPONSE_BODY_REPLACED] - Size: 15000 exceeds limit' ),
305
+ ))).called (1 );
306
+
307
+ // Verify that networkLog was called
308
+ verify (mInstabugHost.networkLog (any)).called (1 );
309
+ verify (mApmHost.networkLogAndroid (any)).called (1 );
310
+ });
311
+
312
+ test ('should replace both bodies when both exceed size limit' , () async {
313
+ final largeBothData = data.copyWith (
314
+ requestBodySize: 15000 , // 15KB > 10KB default
315
+ responseBodySize: 15000 , // 15KB > 10KB default
316
+ );
317
+
318
+ when (mBuildInfo.isAndroid).thenReturn (true );
319
+ when (mManager.obfuscateLog (any)).thenAnswer ((invocation) async {
320
+ final inputData = invocation.positionalArguments[0 ] as NetworkData ;
321
+ return inputData;
322
+ });
323
+ when (mManager.omitLog (largeBothData)).thenReturn (false );
324
+ when (mManager.didRequestBodyExceedSizeLimit (largeBothData))
325
+ .thenAnswer ((_) async => true );
326
+ when (mManager.didResponseBodyExceedSizeLimit (largeBothData))
327
+ .thenAnswer ((_) async => true );
328
+
329
+ await logger.networkLogInternal (largeBothData);
330
+
331
+ // Verify that obfuscateLog was called with modified data
332
+ verify (mManager.obfuscateLog (argThat (
333
+ predicate <NetworkData >((processedData) =>
334
+ processedData.requestBody ==
335
+ '[REQUEST_BODY_REPLACED] - Size: 15000 exceeds limit' &&
336
+ processedData.responseBody ==
337
+ '[RESPONSE_BODY_REPLACED] - Size: 15000 exceeds limit' ),
338
+ ))).called (1 );
339
+
340
+ // Verify that networkLog was called
341
+ verify (mInstabugHost.networkLog (any)).called (1 );
342
+ verify (mApmHost.networkLogAndroid (any)).called (1 );
343
+ });
344
+
345
+ test ('should not replace bodies when both are within size limit' , () async {
346
+ final smallData = data.copyWith (
347
+ requestBodySize: 5000 , // 5KB < 10KB default
348
+ responseBodySize: 5000 , // 5KB < 10KB default
349
+ );
350
+
351
+ when (mBuildInfo.isAndroid).thenReturn (true );
352
+ when (mManager.obfuscateLog (any)).thenAnswer ((invocation) async {
353
+ final inputData = invocation.positionalArguments[0 ] as NetworkData ;
354
+ return inputData;
355
+ });
356
+ when (mManager.omitLog (smallData)).thenReturn (false );
357
+ when (mManager.didRequestBodyExceedSizeLimit (smallData))
358
+ .thenAnswer ((_) async => false );
359
+ when (mManager.didResponseBodyExceedSizeLimit (smallData))
360
+ .thenAnswer ((_) async => false );
361
+
362
+ await logger.networkLogInternal (smallData);
363
+
364
+ // Verify that obfuscateLog was called with original data
365
+ verify (mManager.obfuscateLog (smallData)).called (1 );
366
+
367
+ // Verify that networkLog was called
368
+ verify (mInstabugHost.networkLog (any)).called (1 );
369
+ verify (mApmHost.networkLogAndroid (any)).called (1 );
370
+ });
371
+
372
+ test ('should not log when data should be omitted' , () async {
373
+ final largeData = data.copyWith (
374
+ requestBodySize: 15000 , // 15KB > 10KB default
375
+ );
376
+
377
+ when (mBuildInfo.isAndroid).thenReturn (true );
378
+ when (mManager.omitLog (largeData)).thenReturn (true );
379
+
380
+ await logger.networkLogInternal (largeData);
381
+
382
+ // Verify that omitLog was called
383
+ verify (mManager.omitLog (largeData)).called (1 );
384
+
385
+ // Verify that size limit checks were not called
386
+ verifyNever (mManager.didRequestBodyExceedSizeLimit (any));
387
+ verifyNever (mManager.didResponseBodyExceedSizeLimit (any));
388
+
389
+ // Verify that networkLog was not called
390
+ verifyNever (mInstabugHost.networkLog (any));
391
+ verifyNever (mApmHost.networkLogAndroid (any));
392
+ });
393
+ });
242
394
}
0 commit comments