From 76bce18a6037d25162812dab6fbd4a5f2f962362 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Wed, 25 Jun 2025 17:55:35 +0300 Subject: [PATCH 01/13] feat: add network body max size APIs in Android - Added `onNetworkLogBodyMaxSizeChange` method to `FeatureFlagsFlutterApi` in Dart. - Implemented `getNetworkBodyMaxSize` method in `InstabugApi` to retrieve network log character limit. - Updated `InstabugApiTest` with a new test for `getNetworkBodyMaxSize`. --- .../instabug/flutter/modules/InstabugApi.java | 22 +++++++++++++++++++ .../com/instabug/flutter/InstabugApiTest.java | 11 ++++++++++ pigeons/instabug.api.dart | 5 +++++ 3 files changed, 38 insertions(+) diff --git a/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java b/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java index edfde055a..f942b6c83 100644 --- a/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java +++ b/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java @@ -472,6 +472,11 @@ public void reply(Void reply) { } }); + + featureFlagsFlutterApi.onNetworkLogBodyMaxSizeChange( + (long) featuresState.getNetworkLogCharLimit(), + reply -> {} + ); } }); } @@ -509,4 +514,21 @@ public void setNetworkLogBodyEnabled(@NonNull Boolean isEnabled) { e.printStackTrace(); } } + + @Override + public void getNetworkBodyMaxSize(@NonNull InstabugPigeon.Result result) { + ThreadManager.runOnMainThread( + new Runnable() { + @Override + public void run() { + try { + long networkCharLimit = InternalCore.INSTANCE.get_networkLogCharLimit(); + result.success(networkCharLimit); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + ); + } } diff --git a/android/src/test/java/com/instabug/flutter/InstabugApiTest.java b/android/src/test/java/com/instabug/flutter/InstabugApiTest.java index 97b9cdf7b..9e16b21c0 100644 --- a/android/src/test/java/com/instabug/flutter/InstabugApiTest.java +++ b/android/src/test/java/com/instabug/flutter/InstabugApiTest.java @@ -658,4 +658,15 @@ public void testSetNetworkLogBodyDisabled() { mInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(false)); } + + @Test + public void testGetNetworkBodyMaxSize() { + int expected = 10240; + InstabugPigeon.Result result = makeResult((actual) -> assertEquals((Long) (long) expected, actual)); + + mockkObject(new InternalCore[]{InternalCore.INSTANCE}, false); + every(mockKMatcherScope -> InternalCore.INSTANCE.get_networkLogCharLimit()).returns(expected); + + api.getNetworkBodyMaxSize(result); + } } diff --git a/pigeons/instabug.api.dart b/pigeons/instabug.api.dart index 275306987..897603951 100644 --- a/pigeons/instabug.api.dart +++ b/pigeons/instabug.api.dart @@ -7,6 +7,8 @@ abstract class FeatureFlagsFlutterApi { bool isW3cExternalGeneratedHeaderEnabled, bool isW3cCaughtHeaderEnabled, ); + + void onNetworkLogBodyMaxSizeChange(int networkBodyMaxSize); } @HostApi() @@ -76,4 +78,7 @@ abstract class InstabugHostApi { void willRedirectToStore(); void setNetworkLogBodyEnabled(bool isEnabled); + + @async + int? getNetworkBodyMaxSize(); } From c9d0ac69945ed3ef91d53de7b2ed8cbac3f30229 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 1 Jul 2025 15:15:58 +0300 Subject: [PATCH 02/13] feat: add network body max size APIs in iOS - Updated Instabug podspec to version 15.0.1. - Added `getNetworkBodyMaxSize` method in `InstabugApi` for retrieving network log body size. - Introduced a new test case for `getNetworkBodyMaxSize` in `InstabugApiTests`. - Updated .gitignore files to include project-specific and Android-related paths. --- .gitignore | 3 +++ example/.gitignore | 3 +++ example/ios/InstabugTests/InstabugApiTests.m | 18 ++++++++++++++++++ ios/Classes/Modules/InstabugApi.m | 5 +++++ ios/Classes/Util/IBGNetworkLogger+CP.h | 2 ++ 5 files changed, 31 insertions(+) diff --git a/.gitignore b/.gitignore index 071964ca9..ef70b75a0 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,9 @@ android/gradlew.bat **/ios/ServiceDefinitions.json **/ios/Runner/GeneratedPluginRegistrant.* +# Project specific +/PRDs/ + # Exceptions to above rules. !**/ios/**/default.mode1v3 !**/ios/**/default.mode2v3 diff --git a/example/.gitignore b/example/.gitignore index 9d532b18a..5fae00ed2 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -39,3 +39,6 @@ app.*.symbols # Obfuscation related app.*.map.json + +# Android related +/android/app/.cxx/ \ No newline at end of file diff --git a/example/ios/InstabugTests/InstabugApiTests.m b/example/ios/InstabugTests/InstabugApiTests.m index 9f2c04373..fef8e5981 100644 --- a/example/ios/InstabugTests/InstabugApiTests.m +++ b/example/ios/InstabugTests/InstabugApiTests.m @@ -611,4 +611,22 @@ - (void)testisW3CFeatureFlagsEnabled { } +- (void)testGetNetworkBodyMaxSize { + id mock = OCMClassMock([IBGNetworkLogger class]); + double expectedValue = 10240.0; + + OCMStub([mock getNetworkBodyMaxSize]).andReturn(expectedValue); + + XCTestExpectation *expectation = [self expectationWithDescription:@"Call resolve block"]; + RCTPromiseResolveBlock resolve = ^(NSNumber *result) { + XCTAssertEqual(result.doubleValue, expectedValue); + [expectation fulfill]; + }; + + [self.instabugBridge getNetworkBodyMaxSize:resolve :nil]; + [self waitForExpectationsWithTimeout:1.0 handler:nil]; + + OCMVerify(ClassMethod([mock getNetworkBodyMaxSize])); +} + @end diff --git a/ios/Classes/Modules/InstabugApi.m b/ios/Classes/Modules/InstabugApi.m index 3bdc465f0..b30503742 100644 --- a/ios/Classes/Modules/InstabugApi.m +++ b/ios/Classes/Modules/InstabugApi.m @@ -396,4 +396,9 @@ - (void)setNetworkLogBodyEnabledIsEnabled:(NSNumber *)isEnabled IBGNetworkLogger.logBodyEnabled = [isEnabled boolValue]; } +- (void)getNetworkBodyMaxSizeWithCompletion:(nonnull void (^)(NSNumber * _Nullable, FlutterError * _Nullable))completion { + completion(@(IBGNetworkLogger.getNetworkBodyMaxSize), nil); +} + + @end diff --git a/ios/Classes/Util/IBGNetworkLogger+CP.h b/ios/Classes/Util/IBGNetworkLogger+CP.h index 54cb9d7ef..3670f5f8b 100644 --- a/ios/Classes/Util/IBGNetworkLogger+CP.h +++ b/ios/Classes/Util/IBGNetworkLogger+CP.h @@ -49,6 +49,8 @@ NS_ASSUME_NONNULL_BEGIN duration:(int64_t) duration gqlQueryName:(NSString * _Nullable)gqlQueryName; ++ (double)getNetworkBodyMaxSize; + @end NS_ASSUME_NONNULL_END From 96306fe718cdc8d84f237fa1b310767342b69983 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 1 Jul 2025 15:19:09 +0300 Subject: [PATCH 03/13] feat: add body size checks inside network manager and cache retrieved in feature flags manager - Added `_networkBodyMaxSize` to `FeatureFlagsManager` for managing network body size limits. - Introduced `didRequestBodyExceedSizeLimit` and `didResponseBodyExceedSizeLimit` methods in `NetworkManager` to validate request and response body sizes against the limit. - Created `InstabugConstants` for standardized logging messages related to network body size limits. - Implemented caching for network body size retrieval to optimize performance. --- lib/src/utils/feature_flags_manager.dart | 8 ++ lib/src/utils/instabug_constants.dart | 31 ++++++++ lib/src/utils/network_manager.dart | 94 ++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 lib/src/utils/instabug_constants.dart diff --git a/lib/src/utils/feature_flags_manager.dart b/lib/src/utils/feature_flags_manager.dart index b81dc9777..30c3c97ea 100644 --- a/lib/src/utils/feature_flags_manager.dart +++ b/lib/src/utils/feature_flags_manager.dart @@ -42,6 +42,9 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { bool _isAndroidW3CExternalTraceID = false; bool _isAndroidW3CExternalGeneratedHeader = false; bool _isAndroidW3CCaughtHeader = false; + int _networkBodyMaxSize = 0; + + int get networkBodyMaxSize => _networkBodyMaxSize; Future getW3CFeatureFlagsHeader() async { if (IBGBuildInfo.instance.isAndroid) { @@ -89,4 +92,9 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { _isAndroidW3CExternalTraceID = isW3cExternalTraceIDEnabled; _isAndroidW3CExternalGeneratedHeader = isW3cExternalGeneratedHeaderEnabled; } + + @override + void onNetworkLogBodyMaxSizeChange(int networkBodyMaxSize) { + _networkBodyMaxSize = networkBodyMaxSize; + } } diff --git a/lib/src/utils/instabug_constants.dart b/lib/src/utils/instabug_constants.dart new file mode 100644 index 000000000..fb6dc8abb --- /dev/null +++ b/lib/src/utils/instabug_constants.dart @@ -0,0 +1,31 @@ +/// Constants used throughout the Instabug Flutter SDK +class InstabugConstants { + InstabugConstants._(); + + // Network logging constants + static const String networkLoggerTag = 'NetworkLogger'; + static const String networkManagerTag = 'NetworkManager'; + + // Network body replacement messages + static const String requestBodyReplacedPrefix = '[REQUEST_BODY_REPLACED]'; + static const String responseBodyReplacedPrefix = '[RESPONSE_BODY_REPLACED]'; + static const String exceedsLimitSuffix = 'exceeds limit'; + + /// Generates a request body replacement message + static String getRequestBodyReplacementMessage(int size) { + return '$requestBodyReplacedPrefix - Size: $size $exceedsLimitSuffix'; + } + + /// Generates a response body replacement message + static String getResponseBodyReplacementMessage(int size) { + return '$responseBodyReplacedPrefix - Size: $size $exceedsLimitSuffix'; + } + + /// Generates a network body size limit exceeded log message + static String getNetworkBodyLimitExceededMessage({ + required String type, + required int bodySize, + }) { + return 'Network body size limit exceeded for $type - Size: $bodySize'; + } +} diff --git a/lib/src/utils/network_manager.dart b/lib/src/utils/network_manager.dart index 7aaf8f563..1a32a4503 100644 --- a/lib/src/utils/network_manager.dart +++ b/lib/src/utils/network_manager.dart @@ -1,6 +1,10 @@ import 'dart:async'; import 'package:instabug_flutter/instabug_flutter.dart'; +import 'package:instabug_flutter/src/generated/instabug.api.g.dart'; +import 'package:instabug_flutter/src/utils/feature_flags_manager.dart'; +import 'package:instabug_flutter/src/utils/instabug_constants.dart'; +import 'package:instabug_flutter/src/utils/instabug_logger.dart'; typedef ObfuscateLogCallback = FutureOr Function(NetworkData data); typedef OmitLogCallback = FutureOr Function(NetworkData data); @@ -10,6 +14,8 @@ typedef OmitLogCallback = FutureOr Function(NetworkData data); class NetworkManager { ObfuscateLogCallback? _obfuscateLogCallback; OmitLogCallback? _omitLogCallback; + int? _cachedNetworkBodyMaxSize; + final _host = InstabugHostApi(); // ignore: use_setters_to_change_properties void setObfuscateLogCallback(ObfuscateLogCallback callback) { @@ -36,4 +42,92 @@ class NetworkManager { return _omitLogCallback!(data); } + + /// Checks if network request body exceeds backend size limits + /// + /// Returns true if request body size exceeds the limit + Future didRequestBodyExceedSizeLimit(NetworkData data) async { + try { + final limit = await _getNetworkBodyMaxSize(); + if (limit == null) { + return false; // If we can't get the limit, don't block logging + } + + final requestExceeds = data.requestBodySize > limit; + if (requestExceeds) { + InstabugLogger.I.d( + InstabugConstants.getNetworkBodyLimitExceededMessage( + type: 'request', + bodySize: data.requestBodySize, + ), + tag: InstabugConstants.networkManagerTag, + ); + } + + return requestExceeds; + } catch (error) { + InstabugLogger.I.e( + 'Error checking network request body size limit: $error', + tag: InstabugConstants.networkManagerTag, + ); + return false; // Don't block logging on error + } + } + + /// Checks if network response body exceeds backend size limits + /// + /// Returns true if response body size exceeds the limit + Future didResponseBodyExceedSizeLimit(NetworkData data) async { + try { + final limit = await _getNetworkBodyMaxSize(); + if (limit == null) { + return false; // If we can't get the limit, don't block logging + } + + final responseExceeds = data.responseBodySize > limit; + if (responseExceeds) { + InstabugLogger.I.d( + InstabugConstants.getNetworkBodyLimitExceededMessage( + type: 'response', + bodySize: data.responseBodySize, + ), + tag: InstabugConstants.networkManagerTag, + ); + } + + return responseExceeds; + } catch (error) { + InstabugLogger.I.e( + 'Error checking network response body size limit: $error', + tag: InstabugConstants.networkManagerTag, + ); + return false; // Don't block logging on error + } + } + + /// Gets the network body max size from native SDK, with caching + Future _getNetworkBodyMaxSize() async { + if (_cachedNetworkBodyMaxSize != null) { + return _cachedNetworkBodyMaxSize; + } + + final ffmNetworkBodyLimit = FeatureFlagsManager().networkBodyMaxSize; + + if (ffmNetworkBodyLimit > 0) { + _cachedNetworkBodyMaxSize = ffmNetworkBodyLimit; + return ffmNetworkBodyLimit; + } + + try { + final limit = await _host.getNetworkBodyMaxSize(); + _cachedNetworkBodyMaxSize = limit; + return limit; + } catch (error) { + InstabugLogger.I.e( + 'Failed to get network body max size from native API: $error', + tag: InstabugConstants.networkManagerTag, + ); + return null; + } + } } From efd961d4891ef485678471fd14ba38aa49e4070c Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 1 Jul 2025 20:59:21 +0300 Subject: [PATCH 04/13] feat: utilize network manager size checker APIs inside `network_logger.dart` - Added early checks for request and response body size limits in `networkLogInternal`. - Implemented truncation of request/response bodies with warning messages if size limits are exceeded. - Logged truncation events using `InstabugLogger` for better visibility into network logging behavior. --- lib/src/modules/network_logger.dart | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/src/modules/network_logger.dart b/lib/src/modules/network_logger.dart index b7acc74c2..a71314d63 100644 --- a/lib/src/modules/network_logger.dart +++ b/lib/src/modules/network_logger.dart @@ -6,6 +6,8 @@ import 'package:instabug_flutter/src/models/network_data.dart'; import 'package:instabug_flutter/src/models/w3c_header.dart'; import 'package:instabug_flutter/src/modules/apm.dart'; import 'package:instabug_flutter/src/utils/feature_flags_manager.dart'; +import 'package:instabug_flutter/src/utils/instabug_constants.dart'; +import 'package:instabug_flutter/src/utils/instabug_logger.dart'; import 'package:instabug_flutter/src/utils/iterable_ext.dart'; import 'package:instabug_flutter/src/utils/network_manager.dart'; import 'package:instabug_flutter/src/utils/w3c_header_utils.dart'; @@ -86,7 +88,34 @@ class NetworkLogger { Future networkLogInternal(NetworkData data) async { final omit = await _manager.omitLog(data); if (omit) return; - final obfuscated = await _manager.obfuscateLog(data); + + // Check size limits early to avoid processing large bodies + final requestExceeds = await _manager.didRequestBodyExceedSizeLimit(data); + final responseExceeds = await _manager.didResponseBodyExceedSizeLimit(data); + + var processedData = data; + if (requestExceeds || responseExceeds) { + // Replace bodies with warning messages + processedData = data.copyWith( + requestBody: requestExceeds + ? InstabugConstants.getRequestBodyReplacementMessage( + data.requestBodySize) + : data.requestBody, + responseBody: responseExceeds + ? InstabugConstants.getResponseBodyReplacementMessage( + data.responseBodySize) + : data.responseBody, + ); + + // Log the truncation event. + final isBothExceeds = requestExceeds && responseExceeds; + InstabugLogger.I.e( + "Truncated network ${isBothExceeds ? 'request and response' : requestExceeds ? 'request' : 'response'} body", + tag: InstabugConstants.networkLoggerTag, + ); + } + + final obfuscated = await _manager.obfuscateLog(processedData); await _host.networkLog(obfuscated.toJson()); await APM.networkLogAndroid(obfuscated); } From d73e7d5aa8f8b4aaf8eb319f1a11c34277eee072 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 1 Jul 2025 21:45:47 +0300 Subject: [PATCH 05/13] chore: add default value of 10KB as a fallback, add network body size specific tests - Introduced a default network body max size of 10KB to improve logging consistency. - Updated error handling to set the cached size to the default when native API retrieval fails. - Added unit tests for `didRequestBodyExceedSizeLimit` and `didResponseBodyExceedSizeLimit` to ensure proper size limit checks for request and response bodies. --- lib/src/utils/network_manager.dart | 8 +- test/network_logger_test.dart | 152 +++++++++++++++++++++++++++++ test/network_manager_test.dart | 76 +++++++++++++++ 3 files changed, 234 insertions(+), 2 deletions(-) diff --git a/lib/src/utils/network_manager.dart b/lib/src/utils/network_manager.dart index 1a32a4503..aecbd9098 100644 --- a/lib/src/utils/network_manager.dart +++ b/lib/src/utils/network_manager.dart @@ -15,6 +15,7 @@ class NetworkManager { ObfuscateLogCallback? _obfuscateLogCallback; OmitLogCallback? _omitLogCallback; int? _cachedNetworkBodyMaxSize; + int _defaultNetworkBodyMaxSize = 10240; // in bytes final _host = InstabugHostApi(); // ignore: use_setters_to_change_properties @@ -124,10 +125,13 @@ class NetworkManager { return limit; } catch (error) { InstabugLogger.I.e( - 'Failed to get network body max size from native API: $error', + 'Failed to get network body max size from native API: $error' + '\n' + 'Setting it to the default value of $_defaultNetworkBodyMaxSize bytes = ${_defaultNetworkBodyMaxSize / 1024} KB', tag: InstabugConstants.networkManagerTag, ); - return null; + _cachedNetworkBodyMaxSize = _defaultNetworkBodyMaxSize; + return _defaultNetworkBodyMaxSize; } } } diff --git a/test/network_logger_test.dart b/test/network_logger_test.dart index cbdc2db93..8557b0f46 100644 --- a/test/network_logger_test.dart +++ b/test/network_logger_test.dart @@ -60,6 +60,10 @@ void main() { "isW3cCaughtHeaderEnabled": true, }), ); + when(mManager.didRequestBodyExceedSizeLimit(any)) + .thenAnswer((_) async => false); + when(mManager.didResponseBodyExceedSizeLimit(any)) + .thenAnswer((_) async => false); }); test('[networkLog] should call 1 host method on iOS', () async { @@ -239,4 +243,152 @@ void main() { mInstabugHost.setNetworkLogBodyEnabled(enabled), ).called(1); }); + + group('[networkLogInternal] body size limit tests', () { + test('should replace request body when it exceeds size limit', () async { + final largeRequestData = data.copyWith( + requestBodySize: 15000, // 15KB > 10KB default + responseBodySize: 5000, // 5KB < 10KB default + ); + + when(mBuildInfo.isAndroid).thenReturn(true); + when(mManager.obfuscateLog(any)).thenAnswer((invocation) async { + final inputData = invocation.positionalArguments[0] as NetworkData; + return inputData; + }); + when(mManager.omitLog(largeRequestData)).thenReturn(false); + when(mManager.didRequestBodyExceedSizeLimit(largeRequestData)) + .thenAnswer((_) async => true); + when(mManager.didResponseBodyExceedSizeLimit(largeRequestData)) + .thenAnswer((_) async => false); + + await logger.networkLogInternal(largeRequestData); + + // Verify that obfuscateLog was called with modified data + verify(mManager.obfuscateLog(argThat( + predicate((processedData) => + processedData.requestBody == + '[REQUEST_BODY_REPLACED] - Size: 15000 exceeds limit' && + processedData.responseBody == largeRequestData.responseBody), + ))).called(1); + + // Verify that networkLog was called + verify(mInstabugHost.networkLog(any)).called(1); + verify(mApmHost.networkLogAndroid(any)).called(1); + }); + + test('should replace response body when it exceeds size limit', () async { + final largeResponseData = data.copyWith( + requestBodySize: 5000, // 5KB < 10KB default + responseBodySize: 15000, // 15KB > 10KB default + ); + + when(mBuildInfo.isAndroid).thenReturn(true); + when(mManager.obfuscateLog(any)).thenAnswer((invocation) async { + final inputData = invocation.positionalArguments[0] as NetworkData; + return inputData; + }); + when(mManager.omitLog(largeResponseData)).thenReturn(false); + when(mManager.didRequestBodyExceedSizeLimit(largeResponseData)) + .thenAnswer((_) async => false); + when(mManager.didResponseBodyExceedSizeLimit(largeResponseData)) + .thenAnswer((_) async => true); + + await logger.networkLogInternal(largeResponseData); + + // Verify that obfuscateLog was called with modified data + verify(mManager.obfuscateLog(argThat( + predicate((processedData) => + processedData.requestBody == largeResponseData.requestBody && + processedData.responseBody == + '[RESPONSE_BODY_REPLACED] - Size: 15000 exceeds limit'), + ))).called(1); + + // Verify that networkLog was called + verify(mInstabugHost.networkLog(any)).called(1); + verify(mApmHost.networkLogAndroid(any)).called(1); + }); + + test('should replace both bodies when both exceed size limit', () async { + final largeBothData = data.copyWith( + requestBodySize: 15000, // 15KB > 10KB default + responseBodySize: 15000, // 15KB > 10KB default + ); + + when(mBuildInfo.isAndroid).thenReturn(true); + when(mManager.obfuscateLog(any)).thenAnswer((invocation) async { + final inputData = invocation.positionalArguments[0] as NetworkData; + return inputData; + }); + when(mManager.omitLog(largeBothData)).thenReturn(false); + when(mManager.didRequestBodyExceedSizeLimit(largeBothData)) + .thenAnswer((_) async => true); + when(mManager.didResponseBodyExceedSizeLimit(largeBothData)) + .thenAnswer((_) async => true); + + await logger.networkLogInternal(largeBothData); + + // Verify that obfuscateLog was called with modified data + verify(mManager.obfuscateLog(argThat( + predicate((processedData) => + processedData.requestBody == + '[REQUEST_BODY_REPLACED] - Size: 15000 exceeds limit' && + processedData.responseBody == + '[RESPONSE_BODY_REPLACED] - Size: 15000 exceeds limit'), + ))).called(1); + + // Verify that networkLog was called + verify(mInstabugHost.networkLog(any)).called(1); + verify(mApmHost.networkLogAndroid(any)).called(1); + }); + + test('should not replace bodies when both are within size limit', () async { + final smallData = data.copyWith( + requestBodySize: 5000, // 5KB < 10KB default + responseBodySize: 5000, // 5KB < 10KB default + ); + + when(mBuildInfo.isAndroid).thenReturn(true); + when(mManager.obfuscateLog(any)).thenAnswer((invocation) async { + final inputData = invocation.positionalArguments[0] as NetworkData; + return inputData; + }); + when(mManager.omitLog(smallData)).thenReturn(false); + when(mManager.didRequestBodyExceedSizeLimit(smallData)) + .thenAnswer((_) async => false); + when(mManager.didResponseBodyExceedSizeLimit(smallData)) + .thenAnswer((_) async => false); + + await logger.networkLogInternal(smallData); + + // Verify that obfuscateLog was called with original data + verify(mManager.obfuscateLog(smallData)).called(1); + + // Verify that networkLog was called + verify(mInstabugHost.networkLog(any)).called(1); + verify(mApmHost.networkLogAndroid(any)).called(1); + }); + + test('should not log when data should be omitted', () async { + final largeData = data.copyWith( + requestBodySize: 15000, // 15KB > 10KB default + ); + + when(mBuildInfo.isAndroid).thenReturn(true); + when(mManager.omitLog(largeData)).thenReturn(true); + + await logger.networkLogInternal(largeData); + + // Verify that omitLog was called + verify(mManager.omitLog(largeData)).called(1); + + // Verify that size limit checks were not called + verifyNever(mManager.didRequestBodyExceedSizeLimit(any)); + verifyNever(mManager.didResponseBodyExceedSizeLimit(any)); + + // Verify that networkLog was not called + verifyNever(mInstabugHost.networkLog(any)); + verifyNever(mApmHost.networkLogAndroid(any)); + }); + }); } diff --git a/test/network_manager_test.dart b/test/network_manager_test.dart index 31776c7ea..daad165dc 100644 --- a/test/network_manager_test.dart +++ b/test/network_manager_test.dart @@ -13,6 +13,8 @@ void main() { url: "https://httpbin.org/get", method: "GET", startTime: DateTime.now(), + requestBodySize: 1000, + responseBodySize: 2000, ); late NetworkManager manager; @@ -76,4 +78,78 @@ void main() { expect(result, equals(omit)); }); + + group('[didRequestBodyExceedSizeLimit]', () { + test('should return false when request body size is within default limit', + () async { + final smallData = + data.copyWith(requestBodySize: 5000); // 5KB < 10KB default + + final result = await manager.didRequestBodyExceedSizeLimit(smallData); + + expect(result, isFalse); + }); + + test('should return true when request body size exceeds default limit', + () async { + final largeData = + data.copyWith(requestBodySize: 15000); // 15KB > 10KB default + + final result = await manager.didRequestBodyExceedSizeLimit(largeData); + + expect(result, isTrue); + }); + + test('should return false when request body size equals default limit', + () async { + final exactData = data.copyWith(requestBodySize: 10240); // Exactly 10KB + + final result = await manager.didRequestBodyExceedSizeLimit(exactData); + + expect(result, isFalse); + }); + + test('should handle errors gracefully and return false', () async { + final result = await manager.didRequestBodyExceedSizeLimit(data); + + expect(result, isA()); + }); + }); + + group('[didResponseBodyExceedSizeLimit]', () { + test('should return false when response body size is within default limit', + () async { + final smallData = + data.copyWith(responseBodySize: 5000); // 5KB < 10KB default + + final result = await manager.didResponseBodyExceedSizeLimit(smallData); + + expect(result, isFalse); + }); + + test('should return true when response body size exceeds default limit', + () async { + final largeData = + data.copyWith(responseBodySize: 15000); // 15KB > 10KB default + + final result = await manager.didResponseBodyExceedSizeLimit(largeData); + + expect(result, isTrue); + }); + + test('should return false when response body size equals default limit', + () async { + final exactData = data.copyWith(responseBodySize: 10240); // Exactly 10KB + + final result = await manager.didResponseBodyExceedSizeLimit(exactData); + + expect(result, isFalse); + }); + + test('should handle errors gracefully and return false', () async { + final result = await manager.didResponseBodyExceedSizeLimit(data); + + expect(result, isA()); + }); + }); } From d3b8628d431cb1874447c9ed53e255d090e0b358 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Tue, 1 Jul 2025 22:00:50 +0300 Subject: [PATCH 06/13] chore: run `dart format .`, and add new `example/pubspec.lock` --- lib/src/utils/feature_flags_manager.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/utils/feature_flags_manager.dart b/lib/src/utils/feature_flags_manager.dart index 30c3c97ea..28b1098c4 100644 --- a/lib/src/utils/feature_flags_manager.dart +++ b/lib/src/utils/feature_flags_manager.dart @@ -92,7 +92,7 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { _isAndroidW3CExternalTraceID = isW3cExternalTraceIDEnabled; _isAndroidW3CExternalGeneratedHeader = isW3cExternalGeneratedHeaderEnabled; } - + @override void onNetworkLogBodyMaxSizeChange(int networkBodyMaxSize) { _networkBodyMaxSize = networkBodyMaxSize; From 5b06977ebd36f43e0724bae17afaf4f9093e997b Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Wed, 2 Jul 2025 21:01:54 +0300 Subject: [PATCH 07/13] fix: reference the correct iOS SDK and the correct podfile setup --- example/ios/Podfile.lock | 4 ++-- .../Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme | 1 + ios/instabug_flutter.podspec | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 619d1436c..7bbc162c3 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,7 +1,7 @@ PODS: - Flutter (1.0.0) - Instabug (15.1.1) - - instabug_flutter (15.0.1): + - instabug_flutter (15.1.1): - Flutter - Instabug (= 15.1.1) - OCMock (3.6) @@ -25,7 +25,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 Instabug: 3e7af445c14d7823fcdecba223f09b5f7c0c6ce1 - instabug_flutter: e4e366434313bab3a2db123c1501ca6247dc950b + instabug_flutter: 30aec1138f5d9c99d175e4f4ad49189ed844b72a OCMock: 5ea90566be239f179ba766fd9fbae5885040b992 PODFILE CHECKSUM: 4d0aaaf6a444f68024f992999ff2c2ee26baa6ec diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 0b15932d1..b02ebfdd2 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -68,6 +68,7 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUValidationMode = "1" allowLocationSimulation = "YES"> diff --git a/ios/instabug_flutter.podspec b/ios/instabug_flutter.podspec index 2d898f9c6..d4a553d78 100644 --- a/ios/instabug_flutter.podspec +++ b/ios/instabug_flutter.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'instabug_flutter' - s.version = '15.0.1' + s.version = '15.1.1' s.summary = 'Flutter plugin for integrating the Instabug SDK.' s.author = 'Instabug' s.homepage = 'https://www.instabug.com/platforms/flutter' From 08e9c891d68764f5d68fdc59644ba47c41845d01 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Thu, 3 Jul 2025 04:09:18 +0300 Subject: [PATCH 08/13] fix: update network body max size handling and caching - Changed the return type of `getNetworkBodyMaxSize` from `int?` to `double?` in the API and updated related method calls accordingly. - Renamed `registerW3CFlagsListener` to `registerFeatureFlagsListener` for consistency across the codebase. - Introduced a callback mechanism in `FeatureFlagsManager` to handle changes in network body max size, ensuring proper cache management in `NetworkManager`. - Updated tests to reflect the new method names and ensure functionality remains intact. --- .../instabug/flutter/modules/InstabugApi.java | 4 ++-- lib/src/modules/instabug.dart | 2 +- lib/src/utils/feature_flags_manager.dart | 21 ++++++++++++++++++- lib/src/utils/network_manager.dart | 21 +++++++++++++++++-- pigeons/instabug.api.dart | 2 +- test/feature_flags_manager_test.dart | 4 ++-- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java b/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java index f942b6c83..b77aa316f 100644 --- a/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java +++ b/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java @@ -516,13 +516,13 @@ public void setNetworkLogBodyEnabled(@NonNull Boolean isEnabled) { } @Override - public void getNetworkBodyMaxSize(@NonNull InstabugPigeon.Result result) { + public void getNetworkBodyMaxSize(@NonNull InstabugPigeon.Result result) { ThreadManager.runOnMainThread( new Runnable() { @Override public void run() { try { - long networkCharLimit = InternalCore.INSTANCE.get_networkLogCharLimit(); + double networkCharLimit = InternalCore.INSTANCE.get_networkLogCharLimit(); result.success(networkCharLimit); } catch (Exception e) { e.printStackTrace(); diff --git a/lib/src/modules/instabug.dart b/lib/src/modules/instabug.dart index 6bba8ed1f..1b11e3904 100644 --- a/lib/src/modules/instabug.dart +++ b/lib/src/modules/instabug.dart @@ -191,7 +191,7 @@ class Instabug { invocationEvents.mapToString(), debugLogsLevel.toString(), ); - return FeatureFlagsManager().registerW3CFlagsListener(); + return FeatureFlagsManager().registerFeatureFlagsListener(); } /// Sets a [callback] to be called wehenever a screen name is captured to mask diff --git a/lib/src/utils/feature_flags_manager.dart b/lib/src/utils/feature_flags_manager.dart index 28b1098c4..1c40c1e87 100644 --- a/lib/src/utils/feature_flags_manager.dart +++ b/lib/src/utils/feature_flags_manager.dart @@ -9,6 +9,8 @@ typedef OnW3CFeatureFlagChange = void Function( bool isW3cCaughtHeaderEnabled, ); +typedef OnNetworkBodyMaxSizeChangeCallback = void Function(); + class FeatureFlagsManager implements FeatureFlagsFlutterApi { // Access the singleton instance factory FeatureFlagsManager() { @@ -23,6 +25,10 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { // Host API instance static InstabugHostApi _host = InstabugHostApi(); + // Callback for network body max size changes + static OnNetworkBodyMaxSizeChangeCallback? + _onNetworkBodyMaxSizeChangeCallback; + /// @nodoc @visibleForTesting // Setter for the host API @@ -38,6 +44,13 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { // since it breaks the singleton pattern } + /// Sets the callback for network body max size changes + // ignore: avoid_setters_without_getters + set onNetworkBodyMaxSizeChangeCallback( + OnNetworkBodyMaxSizeChangeCallback callback) { + _onNetworkBodyMaxSizeChangeCallback = callback; + } + // Internal state flags bool _isAndroidW3CExternalTraceID = false; bool _isAndroidW3CExternalGeneratedHeader = false; @@ -67,9 +80,10 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { ); } - Future registerW3CFlagsListener() async { + Future registerFeatureFlagsListener() async { FeatureFlagsFlutterApi.setup(this); // Use 'this' instead of _instance + // W3C Feature Flags final featureFlags = await _host.isW3CFeatureFlagsEnabled(); _isAndroidW3CCaughtHeader = featureFlags['isW3cCaughtHeaderEnabled'] ?? false; @@ -78,6 +92,10 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { _isAndroidW3CExternalGeneratedHeader = featureFlags['isW3cExternalGeneratedHeaderEnabled'] ?? false; + // Network Body Max Size + final networkBodyMaxSize = await _host.getNetworkBodyMaxSize(); + _networkBodyMaxSize = networkBodyMaxSize?.toInt() ?? 0; + return _host.registerFeatureFlagChangeListener(); } @@ -96,5 +114,6 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { @override void onNetworkLogBodyMaxSizeChange(int networkBodyMaxSize) { _networkBodyMaxSize = networkBodyMaxSize; + _onNetworkBodyMaxSizeChangeCallback?.call(); } } diff --git a/lib/src/utils/network_manager.dart b/lib/src/utils/network_manager.dart index aecbd9098..f5bc182b5 100644 --- a/lib/src/utils/network_manager.dart +++ b/lib/src/utils/network_manager.dart @@ -18,6 +18,14 @@ class NetworkManager { int _defaultNetworkBodyMaxSize = 10240; // in bytes final _host = InstabugHostApi(); + NetworkManager() { + // Register for network body max size changes + FeatureFlagsManager().onNetworkBodyMaxSizeChangeCallback = + () { + clearNetworkBodyMaxSizeCache(); + }; + } + // ignore: use_setters_to_change_properties void setObfuscateLogCallback(ObfuscateLogCallback callback) { _obfuscateLogCallback = callback; @@ -109,6 +117,7 @@ class NetworkManager { /// Gets the network body max size from native SDK, with caching Future _getNetworkBodyMaxSize() async { if (_cachedNetworkBodyMaxSize != null) { + print('[Kamal] _cachedNetworkBodyMaxSize: $_cachedNetworkBodyMaxSize'); return _cachedNetworkBodyMaxSize; } @@ -116,13 +125,15 @@ class NetworkManager { if (ffmNetworkBodyLimit > 0) { _cachedNetworkBodyMaxSize = ffmNetworkBodyLimit; + print('[Kamal] ffmNetworkBodyLimit: $ffmNetworkBodyLimit'); return ffmNetworkBodyLimit; } try { final limit = await _host.getNetworkBodyMaxSize(); - _cachedNetworkBodyMaxSize = limit; - return limit; + _cachedNetworkBodyMaxSize = limit?.toInt(); + print('[Kamal] limit: $limit'); + return limit?.toInt(); } catch (error) { InstabugLogger.I.e( 'Failed to get network body max size from native API: $error' @@ -131,7 +142,13 @@ class NetworkManager { tag: InstabugConstants.networkManagerTag, ); _cachedNetworkBodyMaxSize = _defaultNetworkBodyMaxSize; + print('[Kamal] _defaultNetworkBodyMaxSize: $_defaultNetworkBodyMaxSize'); return _defaultNetworkBodyMaxSize; } } + + /// Clears the cached network body max size + void clearNetworkBodyMaxSizeCache() { + _cachedNetworkBodyMaxSize = null; + } } diff --git a/pigeons/instabug.api.dart b/pigeons/instabug.api.dart index 897603951..505eebf41 100644 --- a/pigeons/instabug.api.dart +++ b/pigeons/instabug.api.dart @@ -80,5 +80,5 @@ abstract class InstabugHostApi { void setNetworkLogBodyEnabled(bool isEnabled); @async - int? getNetworkBodyMaxSize(); + double? getNetworkBodyMaxSize(); } diff --git a/test/feature_flags_manager_test.dart b/test/feature_flags_manager_test.dart index 1a78f666c..2ae699f28 100644 --- a/test/feature_flags_manager_test.dart +++ b/test/feature_flags_manager_test.dart @@ -54,7 +54,7 @@ void main() { "isW3cCaughtHeaderEnabled": true, }), ); - await FeatureFlagsManager().registerW3CFlagsListener(); + await FeatureFlagsManager().registerFeatureFlagsListener(); final isW3CExternalTraceID = await FeatureFlagsManager().getW3CFeatureFlagsHeader(); @@ -75,7 +75,7 @@ void main() { }), ); - await FeatureFlagsManager().registerW3CFlagsListener(); + await FeatureFlagsManager().registerFeatureFlagsListener(); verify( mInstabugHost.registerFeatureFlagChangeListener(), From cdeee205f2b2669a3693f8494952b9ff579f5561 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Thu, 3 Jul 2025 04:16:17 +0300 Subject: [PATCH 09/13] chore: update CHANGELOG to include backend network body size limit support --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 039ad6ae1..693d27c06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Added +- Add support for respecting backend network body size limits. ([#593](https://github.com/Instabug/Instabug-Flutter/pull/593)) + - Add support for xCode 16. ([#574](https://github.com/Instabug/Instabug-Flutter/pull/574)) - Add support for BugReporting user consents. ([#573](https://github.com/Instabug/Instabug-Flutter/pull/573)) From 87b7736a3df8fcc0cddf693f1b599b099453233a Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Thu, 3 Jul 2025 04:50:46 +0300 Subject: [PATCH 10/13] fix: flutter and android tests --- .../src/test/java/com/instabug/flutter/InstabugApiTest.java | 6 +++--- test/feature_flags_manager_test.dart | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/android/src/test/java/com/instabug/flutter/InstabugApiTest.java b/android/src/test/java/com/instabug/flutter/InstabugApiTest.java index 9e16b21c0..cd925a495 100644 --- a/android/src/test/java/com/instabug/flutter/InstabugApiTest.java +++ b/android/src/test/java/com/instabug/flutter/InstabugApiTest.java @@ -661,11 +661,11 @@ public void testSetNetworkLogBodyDisabled() { @Test public void testGetNetworkBodyMaxSize() { - int expected = 10240; - InstabugPigeon.Result result = makeResult((actual) -> assertEquals((Long) (long) expected, actual)); + double expected = 10240; + InstabugPigeon.Result result = makeResult((actual) -> assertEquals((Double) expected, actual)); mockkObject(new InternalCore[]{InternalCore.INSTANCE}, false); - every(mockKMatcherScope -> InternalCore.INSTANCE.get_networkLogCharLimit()).returns(expected); + every(mockKMatcherScope -> InternalCore.INSTANCE.get_networkLogCharLimit()).returns((int) expected); api.getNetworkBodyMaxSize(result); } diff --git a/test/feature_flags_manager_test.dart b/test/feature_flags_manager_test.dart index 2ae699f28..e2e9fdb4d 100644 --- a/test/feature_flags_manager_test.dart +++ b/test/feature_flags_manager_test.dart @@ -54,6 +54,9 @@ void main() { "isW3cCaughtHeaderEnabled": true, }), ); + when(mInstabugHost.getNetworkBodyMaxSize()).thenAnswer( + (_) => Future.value(10240), + ); await FeatureFlagsManager().registerFeatureFlagsListener(); final isW3CExternalTraceID = @@ -74,6 +77,9 @@ void main() { "isW3cCaughtHeaderEnabled": true, }), ); + when(mInstabugHost.getNetworkBodyMaxSize()).thenAnswer( + (_) => Future.value(10240), + ); await FeatureFlagsManager().registerFeatureFlagsListener(); From 794517108957d0b77c39372473c9154d44bcea98 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Thu, 3 Jul 2025 14:12:19 +0300 Subject: [PATCH 11/13] fix: fix ios and flutter failing tests --- example/ios/InstabugTests/InstabugApiTests.m | 20 +++++++++----------- test/instabug_test.dart | 3 +++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/example/ios/InstabugTests/InstabugApiTests.m b/example/ios/InstabugTests/InstabugApiTests.m index fef8e5981..08b86d011 100644 --- a/example/ios/InstabugTests/InstabugApiTests.m +++ b/example/ios/InstabugTests/InstabugApiTests.m @@ -612,21 +612,19 @@ - (void)testisW3CFeatureFlagsEnabled { } - (void)testGetNetworkBodyMaxSize { - id mock = OCMClassMock([IBGNetworkLogger class]); double expectedValue = 10240.0; + XCTestExpectation *expectation = [self expectationWithDescription:@"Call completion handler"]; + + OCMStub([self.mNetworkLogger getNetworkBodyMaxSize]).andReturn(expectedValue); - OCMStub([mock getNetworkBodyMaxSize]).andReturn(expectedValue); - - XCTestExpectation *expectation = [self expectationWithDescription:@"Call resolve block"]; - RCTPromiseResolveBlock resolve = ^(NSNumber *result) { - XCTAssertEqual(result.doubleValue, expectedValue); + [self.api getNetworkBodyMaxSizeWithCompletion:^(NSNumber *actual, FlutterError *error) { [expectation fulfill]; - }; - - [self.instabugBridge getNetworkBodyMaxSize:resolve :nil]; - [self waitForExpectationsWithTimeout:1.0 handler:nil]; + XCTAssertEqual(actual.doubleValue, expectedValue); + XCTAssertNil(error); + }]; - OCMVerify(ClassMethod([mock getNetworkBodyMaxSize])); + OCMVerify([self.mNetworkLogger getNetworkBodyMaxSize]); + [self waitForExpectations:@[expectation] timeout:5.0]; } @end diff --git a/test/instabug_test.dart b/test/instabug_test.dart index e2fd7d298..1c3ad4106 100644 --- a/test/instabug_test.dart +++ b/test/instabug_test.dart @@ -78,6 +78,9 @@ void main() { "isW3cCaughtHeaderEnabled": true, }), ); + when(mHost.getNetworkBodyMaxSize()).thenAnswer( + (_) => Future.value(10240), + ); await Instabug.init( token: token, invocationEvents: events, From 5b7ccbb1988475613c3874276f59981502012d03 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Thu, 3 Jul 2025 14:12:31 +0300 Subject: [PATCH 12/13] chore: run dart format --- lib/src/utils/network_manager.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/utils/network_manager.dart b/lib/src/utils/network_manager.dart index f5bc182b5..3c7972529 100644 --- a/lib/src/utils/network_manager.dart +++ b/lib/src/utils/network_manager.dart @@ -20,8 +20,7 @@ class NetworkManager { NetworkManager() { // Register for network body max size changes - FeatureFlagsManager().onNetworkBodyMaxSizeChangeCallback = - () { + FeatureFlagsManager().onNetworkBodyMaxSizeChangeCallback = () { clearNetworkBodyMaxSizeCache(); }; } From fa2279f26f021c150153653ed36d17bfe04d24d8 Mon Sep 17 00:00:00 2001 From: Mohamed Kamal Date: Thu, 3 Jul 2025 14:40:37 +0300 Subject: [PATCH 13/13] fix: improve formatting to align with linter --- lib/src/modules/network_logger.dart | 6 ++- lib/src/utils/feature_flags_manager.dart | 3 +- lib/src/utils/network_manager.dart | 6 +-- test/network_logger_test.dart | 56 ++++++++++++++++-------- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/lib/src/modules/network_logger.dart b/lib/src/modules/network_logger.dart index a71314d63..9155ed9a2 100644 --- a/lib/src/modules/network_logger.dart +++ b/lib/src/modules/network_logger.dart @@ -99,11 +99,13 @@ class NetworkLogger { processedData = data.copyWith( requestBody: requestExceeds ? InstabugConstants.getRequestBodyReplacementMessage( - data.requestBodySize) + data.requestBodySize, + ) : data.requestBody, responseBody: responseExceeds ? InstabugConstants.getResponseBodyReplacementMessage( - data.responseBodySize) + data.responseBodySize, + ) : data.responseBody, ); diff --git a/lib/src/utils/feature_flags_manager.dart b/lib/src/utils/feature_flags_manager.dart index 1c40c1e87..11f03a3ac 100644 --- a/lib/src/utils/feature_flags_manager.dart +++ b/lib/src/utils/feature_flags_manager.dart @@ -47,7 +47,8 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi { /// Sets the callback for network body max size changes // ignore: avoid_setters_without_getters set onNetworkBodyMaxSizeChangeCallback( - OnNetworkBodyMaxSizeChangeCallback callback) { + OnNetworkBodyMaxSizeChangeCallback callback, + ) { _onNetworkBodyMaxSizeChangeCallback = callback; } diff --git a/lib/src/utils/network_manager.dart b/lib/src/utils/network_manager.dart index 3c7972529..6025af364 100644 --- a/lib/src/utils/network_manager.dart +++ b/lib/src/utils/network_manager.dart @@ -15,7 +15,7 @@ class NetworkManager { ObfuscateLogCallback? _obfuscateLogCallback; OmitLogCallback? _omitLogCallback; int? _cachedNetworkBodyMaxSize; - int _defaultNetworkBodyMaxSize = 10240; // in bytes + final int _defaultNetworkBodyMaxSize = 10240; // in bytes final _host = InstabugHostApi(); NetworkManager() { @@ -116,7 +116,6 @@ class NetworkManager { /// Gets the network body max size from native SDK, with caching Future _getNetworkBodyMaxSize() async { if (_cachedNetworkBodyMaxSize != null) { - print('[Kamal] _cachedNetworkBodyMaxSize: $_cachedNetworkBodyMaxSize'); return _cachedNetworkBodyMaxSize; } @@ -124,14 +123,12 @@ class NetworkManager { if (ffmNetworkBodyLimit > 0) { _cachedNetworkBodyMaxSize = ffmNetworkBodyLimit; - print('[Kamal] ffmNetworkBodyLimit: $ffmNetworkBodyLimit'); return ffmNetworkBodyLimit; } try { final limit = await _host.getNetworkBodyMaxSize(); _cachedNetworkBodyMaxSize = limit?.toInt(); - print('[Kamal] limit: $limit'); return limit?.toInt(); } catch (error) { InstabugLogger.I.e( @@ -141,7 +138,6 @@ class NetworkManager { tag: InstabugConstants.networkManagerTag, ); _cachedNetworkBodyMaxSize = _defaultNetworkBodyMaxSize; - print('[Kamal] _defaultNetworkBodyMaxSize: $_defaultNetworkBodyMaxSize'); return _defaultNetworkBodyMaxSize; } } diff --git a/test/network_logger_test.dart b/test/network_logger_test.dart index 8557b0f46..df9951f5e 100644 --- a/test/network_logger_test.dart +++ b/test/network_logger_test.dart @@ -265,12 +265,18 @@ void main() { await logger.networkLogInternal(largeRequestData); // Verify that obfuscateLog was called with modified data - verify(mManager.obfuscateLog(argThat( - predicate((processedData) => - processedData.requestBody == - '[REQUEST_BODY_REPLACED] - Size: 15000 exceeds limit' && - processedData.responseBody == largeRequestData.responseBody), - ))).called(1); + verify( + mManager.obfuscateLog( + argThat( + predicate( + (processedData) => + processedData.requestBody == + '[REQUEST_BODY_REPLACED] - Size: 15000 exceeds limit' && + processedData.responseBody == largeRequestData.responseBody, + ), + ), + ), + ).called(1); // Verify that networkLog was called verify(mInstabugHost.networkLog(any)).called(1); @@ -297,12 +303,18 @@ void main() { await logger.networkLogInternal(largeResponseData); // Verify that obfuscateLog was called with modified data - verify(mManager.obfuscateLog(argThat( - predicate((processedData) => - processedData.requestBody == largeResponseData.requestBody && - processedData.responseBody == - '[RESPONSE_BODY_REPLACED] - Size: 15000 exceeds limit'), - ))).called(1); + verify( + mManager.obfuscateLog( + argThat( + predicate( + (processedData) => + processedData.requestBody == largeResponseData.requestBody && + processedData.responseBody == + '[RESPONSE_BODY_REPLACED] - Size: 15000 exceeds limit', + ), + ), + ), + ).called(1); // Verify that networkLog was called verify(mInstabugHost.networkLog(any)).called(1); @@ -329,13 +341,19 @@ void main() { await logger.networkLogInternal(largeBothData); // Verify that obfuscateLog was called with modified data - verify(mManager.obfuscateLog(argThat( - predicate((processedData) => - processedData.requestBody == - '[REQUEST_BODY_REPLACED] - Size: 15000 exceeds limit' && - processedData.responseBody == - '[RESPONSE_BODY_REPLACED] - Size: 15000 exceeds limit'), - ))).called(1); + verify( + mManager.obfuscateLog( + argThat( + predicate( + (processedData) => + processedData.requestBody == + '[REQUEST_BODY_REPLACED] - Size: 15000 exceeds limit' && + processedData.responseBody == + '[RESPONSE_BODY_REPLACED] - Size: 15000 exceeds limit', + ), + ), + ), + ).called(1); // Verify that networkLog was called verify(mInstabugHost.networkLog(any)).called(1);