diff --git a/CHANGELOG.md b/CHANGELOG.md index 97d6bab09..e789b3820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...dev) + +### Added + +- Add support for enable/disable capturing network body. ([#1362](https://github.com/Instabug/Instabug-React-Native/pull/1362)) + # Changelog ## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...dev) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java index 8644dda7c..8a0b4ee1b 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java @@ -1294,4 +1294,21 @@ public void run() { }); } + /** + * Enables or disables capturing network body. + * @param isEnabled A boolean to enable/disable capturing network body. + */ + @ReactMethod + public void setNetworkLogBodyEnabled(final boolean isEnabled) { + MainThreadHandler.runOnMainThread(new Runnable() { + @Override + public void run() { + try { + Instabug.setNetworkLogBodyEnabled(isEnabled); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } } diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java index 7f289b610..c9cb92a9a 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java @@ -676,4 +676,18 @@ public void testEnableAutoMasking(){ mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING)); } + + @Test + public void testSetNetworkLogBodyEnabled() { + rnModule.setNetworkLogBodyEnabled(true); + + mockInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(true)); + } + + @Test + public void testSetNetworkLogBodyDisabled() { + rnModule.setNetworkLogBodyEnabled(false); + + mockInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(false)); + } } diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index 4dc32729c..df61d21f3 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -625,4 +625,13 @@ - (void)testEnableAutoMasking { OCMVerify([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]); } +- (void)testSetNetworkLogBodyEnabled { + id mock = OCMClassMock([IBGNetworkLogger class]); + BOOL isEnabled = YES; + + OCMStub([mock setLogBodyEnabled:isEnabled]); + [self.instabugBridge setNetworkLogBodyEnabled:isEnabled]; + OCMVerify([mock setLogBodyEnabled:isEnabled]); +} + @end diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index a65b8a0fe..bd28cecd7 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -139,5 +139,6 @@ w3cExternalTraceAttributes:(NSDictionary * _Nullable)w3cExternalTraceAttributes; - (void)removeFeatureFlags:(NSArray *)featureFlags; - (void)removeAllFeatureFlags; - (void)enableAutoMasking:(NSArray *)autoMaskingTypes; +- (void)setNetworkLogBodyEnabled:(BOOL)isEnabled; @end diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index 38e3ed68d..8db47da64 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -451,4 +451,7 @@ + (BOOL)iOSVersionIsLessThan:(NSString *)iOSVersion { [Instabug setAutoMaskScreenshots: autoMaskingOptions]; }; +RCT_EXPORT_METHOD(setNetworkLogBodyEnabled:(BOOL)isEnabled) { + IBGNetworkLogger.logBodyEnabled = isEnabled; +} @end diff --git a/src/modules/NetworkLogger.ts b/src/modules/NetworkLogger.ts index 1e40b9fa9..4e6b6d379 100644 --- a/src/modules/NetworkLogger.ts +++ b/src/modules/NetworkLogger.ts @@ -5,6 +5,7 @@ import xhr, { NetworkData, ProgressCallback } from '../utils/XhrNetworkIntercept import { isContentTypeNotAllowed, reportNetworkLog } from '../utils/InstabugUtils'; import { InstabugRNConfig } from '../utils/config'; import { Logger } from '../utils/logger'; +import { NativeInstabug } from '../native/NativeInstabug'; export type { NetworkData }; @@ -114,3 +115,11 @@ export const apolloLinkRequestHandler: RequestHandler = (operation, forward) => return forward(operation); }; + +/** + * Sets whether network body logs will be captured or not. + * @param isEnabled + */ +export const setNetworkLogBodyEnabled = (isEnabled: boolean) => { + NativeInstabug.setNetworkLogBodyEnabled(isEnabled); +}; diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index 6c4170f86..6b915e7f9 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -73,6 +73,7 @@ export interface InstabugNativeModule extends NativeModule { ): void; setNetworkLoggingEnabled(isEnabled: boolean): void; + setNetworkLogBodyEnabled(isEnabled: boolean): void; // Repro Steps APIs // setReproStepsConfig( diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index c0655cb77..bc1166b83 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -74,6 +74,7 @@ const mockInstabug: InstabugNativeModule = { isW3CaughtHeaderEnabled: jest.fn(), registerW3CFlagsChangeListener: jest.fn(), enableAutoMasking: jest.fn(), + setNetworkLogBodyEnabled: jest.fn(), }; export default mockInstabug; diff --git a/test/modules/NetworkLogger.spec.ts b/test/modules/NetworkLogger.spec.ts index dbf35eddb..d46b10aff 100644 --- a/test/modules/NetworkLogger.spec.ts +++ b/test/modules/NetworkLogger.spec.ts @@ -8,6 +8,7 @@ import Interceptor from '../../src/utils/XhrNetworkInterceptor'; import { isContentTypeNotAllowed, reportNetworkLog } from '../../src/utils/InstabugUtils'; import InstabugConstants from '../../src/utils/InstabugConstants'; import { Logger } from '../../src/utils/logger'; +import { NativeInstabug } from '../../src/native/NativeInstabug'; const clone = (obj: T): T => { return JSON.parse(JSON.stringify(obj)); @@ -282,4 +283,11 @@ describe('NetworkLogger Module', () => { expect(reportNetworkLog).toHaveBeenCalledWith(networkData); }); + + it('should call the native method setNetworkLogBodyEnabled', () => { + NetworkLogger.setNetworkLogBodyEnabled(true); + + expect(NativeInstabug.setNetworkLogBodyEnabled).toBeCalledTimes(1); + expect(NativeInstabug.setNetworkLogBodyEnabled).toBeCalledWith(true); + }); });