diff --git a/CHANGELOG.md b/CHANGELOG.md index 70fdddc34..a7347f4e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased](https://github.com/Instabug/Instabug-Flutter/compare/v14.0.0...dev) + +### Added + +- Add support enable/disable the automatic masking of sensitive information in network logs. ([#534](https://github.com/Instabug/Instabug-Flutter/pull/534)). + ## [14.0.0](https://github.com/Instabug/Instabug-Flutter/compare/v13.4.0...v14.0.0) (November 18, 2024) ### Added diff --git a/android/build.gradle b/android/build.gradle index ebaccfa51..ac3a66999 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -44,11 +44,11 @@ android { } dependencies { - api 'com.instabug.library:instabug:14.0.0' + api 'com.instabug.library:instabug:14.0.0.6423071-SNAPSHOT' testImplementation 'junit:junit:4.13.2' - testImplementation "org.mockito:mockito-inline:3.12.1" + testImplementation "org.mockito:mockito-inline:5.0.0" testImplementation "io.mockk:mockk:1.13.13" - + testImplementation 'org.robolectric:robolectric:4.12.2' } // add upload_symbols task 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 7a8549718..cdfec9d0c 100644 --- a/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java +++ b/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java @@ -492,4 +492,16 @@ public Map isW3CFeatureFlagsEnabled() { public void willRedirectToStore() { Instabug.willRedirectToStore(); } + + @Override + public void setAutoMaskingEnabled(@NonNull Boolean isEnabled) { + try { + if (isEnabled) + Instabug.setNetworkAutoMaskingState(Feature.State.ENABLED); + else + Instabug.setNetworkAutoMaskingState(Feature.State.DISABLED); + } 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 3d0b15ed4..cec1432c9 100644 --- a/android/src/test/java/com/instabug/flutter/InstabugApiTest.java +++ b/android/src/test/java/com/instabug/flutter/InstabugApiTest.java @@ -622,7 +622,20 @@ public void testWillRedirectToStore() { api.willRedirectToStore(); mInstabug.verify(Instabug::willRedirectToStore); } + @Test + public void testSetAutoMaskingEnabledGivenFalse() { + boolean isEnabled = false; + api.setAutoMaskingEnabled(isEnabled); + mInstabug.verify(() -> Instabug.setNetworkAutoMaskingState(Feature.State.DISABLED)); + } + @Test + public void testSetAutoMaskingEnabledGivenTrue() { + boolean isEnabled = true; + + api.setAutoMaskingEnabled(isEnabled); + mInstabug.verify(() -> Instabug.setNetworkAutoMaskingState(Feature.State.ENABLED)); + } @Test public void isW3CFeatureFlagsEnabled() { diff --git a/example/ios/InstabugTests/InstabugApiTests.m b/example/ios/InstabugTests/InstabugApiTests.m index 6c9544d71..211288266 100644 --- a/example/ios/InstabugTests/InstabugApiTests.m +++ b/example/ios/InstabugTests/InstabugApiTests.m @@ -451,6 +451,14 @@ - (void)testWillRedirectToAppStore { OCMVerify([self.mInstabug willRedirectToAppStore]); } +- (void)testSetAutoMaskingEnabled { + NSNumber *isEnabled = @1; + FlutterError *error; + [self.api setAutoMaskingEnabledIsEnabled:isEnabled error:&error]; + + OCMVerify([self.mNetworkLogger setAutoMaskingEnabled:YES]); +} + - (void)testNetworkLogWithW3Caught { NSString *url = @"https://example.com"; NSString *requestBody = @"hi"; diff --git a/example/ios/Podfile b/example/ios/Podfile index cdffbc5db..aa77f7b43 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -27,6 +27,7 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe flutter_ios_podfile_setup target 'Runner' do + pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-MOB-16539-NetworkConfigHandler/14.0.0/Instabug.podspec' use_frameworks! use_modular_headers! diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index f6cd7d9de..f63453502 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,33 +1,35 @@ PODS: - Flutter (1.0.0) - Instabug (14.0.0) - - instabug_flutter (13.4.0): + - instabug_flutter (14.0.0): - Flutter - Instabug (= 14.0.0) - OCMock (3.6) DEPENDENCIES: - Flutter (from `Flutter`) + - Instabug (from `https://ios-releases.instabug.com/custom/feature-MOB-16539-NetworkConfigHandler/14.0.0/Instabug.podspec`) - instabug_flutter (from `.symlinks/plugins/instabug_flutter/ios`) - OCMock (= 3.6) SPEC REPOS: trunk: - - Instabug - OCMock EXTERNAL SOURCES: Flutter: :path: Flutter + Instabug: + :podspec: https://ios-releases.instabug.com/custom/feature-MOB-16539-NetworkConfigHandler/14.0.0/Instabug.podspec instabug_flutter: :path: ".symlinks/plugins/instabug_flutter/ios" SPEC CHECKSUMS: Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 - Instabug: a0beffc01658773e2fac549845782f8937707dc4 - instabug_flutter: 71ec9d13d57a4958cabab59fe06792cade3bf754 + Instabug: d727e5d85ca7ae8571eeb0754086a2df7b096b19 + instabug_flutter: ff8ab5ff34a476b1d2d887478ec190cda962b973 OCMock: 5ea90566be239f179ba766fd9fbae5885040b992 -PODFILE CHECKSUM: 8f7552fd115ace1988c3db54a69e4a123c448f84 +PODFILE CHECKSUM: 1ed6d7606fbc661422f116efe43de9d8d1666637 -COCOAPODS: 1.16.2 +COCOAPODS: 1.15.2 diff --git a/ios/Classes/Modules/InstabugApi.m b/ios/Classes/Modules/InstabugApi.m index 8cdd336d1..f3f9bfe0a 100644 --- a/ios/Classes/Modules/InstabugApi.m +++ b/ios/Classes/Modules/InstabugApi.m @@ -341,6 +341,10 @@ - (void)willRedirectToStoreWithError:(FlutterError * _Nullable __autoreleasing * [Instabug willRedirectToAppStore]; } +- (void)setAutoMaskingEnabledIsEnabled:(NSNumber *)isEnabled error:(FlutterError *_Nullable *_Nonnull)error { + IBGNetworkLogger.autoMaskingEnabled = [isEnabled boolValue]; +} + - (void)addFeatureFlagsFeatureFlagsMap:(nonnull NSDictionary *)featureFlagsMap error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { NSMutableArray *featureFlags = [NSMutableArray array]; for(id key in featureFlagsMap){ diff --git a/lib/src/modules/network_logger.dart b/lib/src/modules/network_logger.dart index 14e524f87..bffad7c77 100644 --- a/lib/src/modules/network_logger.dart +++ b/lib/src/modules/network_logger.dart @@ -126,4 +126,10 @@ class NetworkLogger { } return null; } + + /// Enables or disables network logs sensitive information auto masking. + /// [boolean] isEnabled + static Future setAutoMaskingEnabled(bool isEnabled) async { + return _host.setAutoMaskingEnabled(isEnabled); + } } diff --git a/pigeons/instabug.api.dart b/pigeons/instabug.api.dart index c0187acb9..f885ad5a1 100644 --- a/pigeons/instabug.api.dart +++ b/pigeons/instabug.api.dart @@ -74,4 +74,6 @@ abstract class InstabugHostApi { Map isW3CFeatureFlagsEnabled(); void willRedirectToStore(); + + void setAutoMaskingEnabled(bool isEnabled); } diff --git a/test/network_logger_test.dart b/test/network_logger_test.dart index 77f5de51d..511531f63 100644 --- a/test/network_logger_test.dart +++ b/test/network_logger_test.dart @@ -229,4 +229,14 @@ void main() { await logger.networkLog(networkData); expect(networkData.requestHeaders['traceparent'], 'test'); }); + + test('[setAutoMaskingEnabled] should call host method', () async { + const enabled = true; + + await NetworkLogger.setAutoMaskingEnabled(enabled); + + verify( + mInstabugHost.setAutoMaskingEnabled(enabled), + ).called(1); + }); }