Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enabling network automasking #534

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ android {
}

dependencies {
api 'com.instabug.library:instabug:14.0.0'
api 'com.instabug.library:instabug:14.0.0.6407912-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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,16 @@ public Map<String, Boolean> 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();
}
}
}
13 changes: 13 additions & 0 deletions android/src/test/java/com/instabug/flutter/InstabugApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions example/ios/InstabugTests/InstabugApiTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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-16541-NetworkAutoMaskAPI/14.0.0/Instabug.podspec'
use_frameworks!
use_modular_headers!

Expand Down
14 changes: 8 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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-16541-NetworkAutoMaskAPI/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-16541-NetworkAutoMaskAPI/14.0.0/Instabug.podspec
instabug_flutter:
:path: ".symlinks/plugins/instabug_flutter/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
Instabug: a0beffc01658773e2fac549845782f8937707dc4
instabug_flutter: 71ec9d13d57a4958cabab59fe06792cade3bf754
Instabug: 3fa42ac8b4350cb632df724b14a86ebdb875aad9
instabug_flutter: ff8ab5ff34a476b1d2d887478ec190cda962b973
OCMock: 5ea90566be239f179ba766fd9fbae5885040b992

PODFILE CHECKSUM: 8f7552fd115ace1988c3db54a69e4a123c448f84
PODFILE CHECKSUM: e7d6c199070a4a2b3664012221f598abd9a35e69

COCOAPODS: 1.16.2
COCOAPODS: 1.15.2
4 changes: 4 additions & 0 deletions ios/Classes/Modules/InstabugApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *,NSString *> *)featureFlagsMap error:(FlutterError * _Nullable __autoreleasing * _Nonnull)error {
NSMutableArray<IBGFeatureFlag *> *featureFlags = [NSMutableArray array];
for(id key in featureFlagsMap){
Expand Down
6 changes: 6 additions & 0 deletions lib/src/modules/network_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ class NetworkLogger {
}
return null;
}

/// Enables or disables network logs sensitive information auto masking.
/// [boolean] isEnabled
static Future<void> setAutoMaskingEnabled(bool isEnabled) async {
return _host.setAutoMaskingEnabled(isEnabled);
}
}
2 changes: 2 additions & 0 deletions pigeons/instabug.api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ abstract class InstabugHostApi {
Map<String, bool> isW3CFeatureFlagsEnabled();

void willRedirectToStore();

void setAutoMaskingEnabled(bool isEnabled);
}
10 changes: 10 additions & 0 deletions test/network_logger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}