diff --git a/android/native.gradle b/android/native.gradle index 3241dc5f24..b7790876e1 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '14.3.0' + version: '14.3.0.6760192-SNAPSHOT' ] dependencies { diff --git a/android/src/main/java/com/instabug/reactlibrary/Constants.java b/android/src/main/java/com/instabug/reactlibrary/Constants.java index 9f1a0cf355..f5b5847004 100644 --- a/android/src/main/java/com/instabug/reactlibrary/Constants.java +++ b/android/src/main/java/com/instabug/reactlibrary/Constants.java @@ -13,7 +13,7 @@ final class Constants { final static String IBG_ON_FEATURES_UPDATED_CALLBACK = "IBGOnFeatureUpdatedCallback"; final static String IBG_NETWORK_LOGGER_HANDLER = "IBGNetworkLoggerHandler"; - final static String IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK = "IBGOnNewW3CFlagsUpdateReceivedCallback"; + final static String IBG_ON_FEATURE_FLAGS_UPDATE_RECEIVED_CALLBACK = "IBGOnNewFeatureFlagsUpdateReceivedCallback"; final static String IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION = "IBGSessionReplayOnSyncCallback"; diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java index 991dc97259..17f48656fe 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java @@ -1159,10 +1159,10 @@ public void run() { } /** - * Register a listener for W3C flags value change + * Register a listener for feature flags value change */ @ReactMethod - public void registerW3CFlagsChangeListener() { + public void registerFeatureFlagsChangeListener() { MainThreadHandler.runOnMainThread(new Runnable() { @Override @@ -1175,8 +1175,9 @@ public void invoke(@NonNull CoreFeaturesState featuresState) { params.putBoolean("isW3ExternalTraceIDEnabled", featuresState.isW3CExternalTraceIdEnabled()); params.putBoolean("isW3ExternalGeneratedHeaderEnabled", featuresState.isAttachingGeneratedHeaderEnabled()); params.putBoolean("isW3CaughtHeaderEnabled", featuresState.isAttachingCapturedHeaderEnabled()); + params.putInt("networkBodyLimit",featuresState.getNetworkLogCharLimit()); - sendEvent(Constants.IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK, params); + sendEvent(Constants.IBG_ON_FEATURE_FLAGS_UPDATE_RECEIVED_CALLBACK, params); } }); } catch (Exception e) { @@ -1306,7 +1307,7 @@ public void run() { } }); } - /** + /** * Sets the auto mask screenshots types. * @@ -1331,4 +1332,23 @@ public void run() { }); } + + /** + * Get network body size limit + */ + @ReactMethod + public void getNetworkBodyMaxSize(Promise promise) { + + MainThreadHandler.runOnMainThread(new Runnable() { + @Override + public void run() { + try { + promise.resolve(InternalCore.INSTANCE.get_networkLogCharLimit()); + } catch (Exception e) { + e.printStackTrace(); + promise.resolve(false); + } + } + }); + } } diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java index 3083410f3d..f4f6f9bc10 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java @@ -686,9 +686,22 @@ public void testEnableAutoMasking(){ String maskTextInputs = "textInputs"; String maskMedia = "media"; String maskNone = "none"; - + rnModule.enableAutoMasking(JavaOnlyArray.of(maskLabel, maskMedia, maskTextInputs,maskNone)); - + mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING)); } + + @Test + public void testGetNetworkBodyMaxSize_resolvesPromiseWithExpectedValue() { + Promise promise = mock(Promise.class); + InternalCore internalAPM = mock(InternalCore.class); + int expected = 10240; + when(internalAPM.get_networkLogCharLimit()).thenReturn(expected); + + rnModule.getNetworkBodyMaxSize(promise); + + verify(promise).resolve(expected); + } + } diff --git a/examples/default/android/build.gradle b/examples/default/android/build.gradle index 5729e78c9e..0a4de84963 100644 --- a/examples/default/android/build.gradle +++ b/examples/default/android/build.gradle @@ -24,7 +24,7 @@ buildscript { classpath("com.android.tools.build:gradle:8.1.0") classpath("com.facebook.react:react-native-gradle-plugin") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") - classpath("com.instabug.library:instabug-plugin:14.1.0.6273967-SNAPSHOT") + classpath("com.instabug.library:instabug-plugin:14.3.0.6760192-SNAPSHOT") } } diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index 76b4cbc0cb..ded37c3af9 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -634,4 +634,23 @@ - (void)testSetNetworkLogBodyEnabled { OCMVerify([mock setLogBodyEnabled:isEnabled]); } +- (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/examples/default/ios/Podfile b/examples/default/ios/Podfile index ea3be9c257..ef9550e04e 100644 --- a/examples/default/ios/Podfile +++ b/examples/default/ios/Podfile @@ -16,7 +16,7 @@ target 'InstabugExample' do rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => rn_maps_path # add this line - pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/sanity/15.0.1/Instabug.podspec' + pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec' # Flags change depending on the env values. flags = get_default_flags() diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 9cde707ae3..61884fc186 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -1770,7 +1770,7 @@ DEPENDENCIES: - fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - - Instabug (from `https://ios-releases.instabug.com/custom/sanity/15.0.1/Instabug.podspec`) + - Instabug (from `https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec`) - instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`) - OCMock - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) @@ -1869,7 +1869,7 @@ EXTERNAL SOURCES: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2024-08-15-RNv0.75.1-4b3bf912cc0f705b51b71ce1a5b8bd79b93a451b Instabug: - :podspec: https://ios-releases.instabug.com/custom/sanity/15.0.1/Instabug.podspec + :podspec: https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec instabug-reactnative-ndk: :path: "../node_modules/instabug-reactnative-ndk" RCT-Folly: @@ -2024,7 +2024,7 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0 - Instabug: 9e81b71be68626dafc74759f3458f7c5894dd2e1 + Instabug: ba6587d15ad5e3ffa265afc8174ff83af4eed29d instabug-reactnative-ndk: d765ac289d56e8896398d02760d9abf2562fc641 OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74 RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740 @@ -2100,6 +2100,6 @@ SPEC CHECKSUMS: SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d Yoga: 055f92ad73f8c8600a93f0e25ac0b2344c3b07e6 -PODFILE CHECKSUM: a1b532d67a1a86843e1f086101751ad55afa52da +PODFILE CHECKSUM: f7f8d2b03a0b566cb0f5b4b422469af0a1a278b1 COCOAPODS: 1.14.0 diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index 1220028577..ceef8bc19d 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -50,7 +50,7 @@ export const App: React.FC = () => { token: 'deb1910a7342814af4e4c9210c786f35', invocationEvents: [InvocationEvent.floatingButton], debugLogsLevel: LogLevel.verbose, - networkInterceptionMode: NetworkInterceptionMode.native, + networkInterceptionMode: NetworkInterceptionMode.javascript, }); CrashReporting.setNDKCrashesEnabled(true); diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index 8d6efcf69c..1fe5505d3b 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -140,5 +140,6 @@ w3cExternalTraceAttributes:(NSDictionary * _Nullable)w3cExternalTraceAttributes; - (void)removeAllFeatureFlags; - (void)setNetworkLogBodyEnabled:(BOOL)isEnabled; - (void)enableAutoMasking:(NSArray *)autoMaskingTypes; +- (void)getNetworkBodyMaxSize:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject; @end diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index a2c75aa551..a48851ba88 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -452,6 +452,10 @@ + (BOOL)iOSVersionIsLessThan:(NSString *)iOSVersion { [Instabug setAutoMaskScreenshots: autoMaskingOptions]; }; +RCT_EXPORT_METHOD(getNetworkBodyMaxSize:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) { + resolve(@(IBGNetworkLogger.getNetworkBodyMaxSize)); +} + RCT_EXPORT_METHOD(setNetworkLogBodyEnabled:(BOOL)isEnabled) { IBGNetworkLogger.logBodyEnabled = isEnabled; } diff --git a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h index d0fd44992b..b5e923f84e 100644 --- a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h +++ b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h @@ -61,6 +61,7 @@ NS_ASSUME_NONNULL_BEGIN + (void)setCPRequestAsyncObfuscationHandler:(void (^)(NSURLRequest * requestToBeObfuscated, void (^ completion)(NSURLRequest * obfuscatedRequest)))asyncObfuscationHandler; + (void)setCPRequestFilteringHandler:(void (^)(NSURLRequest * request, void (^completion)(BOOL keep)))requestFilteringHandler; + (void)setCPResponseFilteringHandler:(void (^)(NSURLResponse * response, void (^comppletion)(BOOL keep)))responseFilteringHandler; ++ (double)getNetworkBodyMaxSize; @end diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index 1bcd5bf8b5..f7d582e70e 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -16,7 +16,7 @@ import type { NavigationAction, NavigationState as NavigationStateV4 } from 'rea import type { InstabugConfig } from '../models/InstabugConfig'; import Report from '../models/Report'; import { emitter, NativeEvents, NativeInstabug } from '../native/NativeInstabug'; -import { registerW3CFlagsListener } from '../utils/FeatureFlags'; +import { registerFeatureFlagsListener } from '../utils/FeatureFlags'; import { AutoMaskingType, ColorTheme, @@ -87,7 +87,7 @@ function reportCurrentViewForAndroid(screenName: string | null) { export const init = async (config: InstabugConfig) => { if (Platform.OS === 'android') { // Add android feature flags listener for android - registerW3CFlagsListener(); + registerFeatureFlagsListener(); addOnFeatureUpdatedListener(config); } else { isNativeInterceptionFeatureEnabled = await NativeNetworkLogger.isNativeInterceptionEnabled(); @@ -871,20 +871,21 @@ export const componentDidAppearListener = (event: ComponentDidAppearEvent) => { }; /** - * Sets listener to W3ExternalTraceID flag changes + * Sets listener to feature flag changes * @param handler A callback that gets the update value of the flag */ -export const _registerW3CFlagsChangeListener = ( +export const _registerFeatureFlagsChangeListener = ( handler: (payload: { isW3ExternalTraceIDEnabled: boolean; isW3ExternalGeneratedHeaderEnabled: boolean; isW3CaughtHeaderEnabled: boolean; + networkBodyLimit: number; }) => void, ) => { - emitter.addListener(NativeEvents.ON_W3C_FLAGS_CHANGE, (payload) => { + emitter.addListener(NativeEvents.ON_FEATURE_FLAGS_CHANGE, (payload) => { handler(payload); }); - NativeInstabug.registerW3CFlagsChangeListener(); + NativeInstabug.registerFeatureFlagsChangeListener(); }; /** diff --git a/src/modules/NetworkLogger.ts b/src/modules/NetworkLogger.ts index 8de927c663..4bd334f568 100644 --- a/src/modules/NetworkLogger.ts +++ b/src/modules/NetworkLogger.ts @@ -45,7 +45,9 @@ export const setEnabled = (isEnabled: boolean) => { xhr.setOnDoneCallback(async (network) => { // eslint-disable-next-line no-new-func const predicate = Function('network', 'return ' + _requestFilterExpression); + if (!predicate(network)) { + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); try { if (_networkDataObfuscationHandler) { network = await _networkDataObfuscationHandler(network); @@ -57,14 +59,28 @@ export const setEnabled = (isEnabled: boolean) => { return; } } - if (network.requestBodySize > InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES) { - network.requestBody = InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE; - Logger.warn('IBG-RN:', InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE); + if (network.requestBodySize > MAX_NETWORK_BODY_SIZE_IN_BYTES) { + network.requestBody = `${InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`; + Logger.warn( + 'IBG-RN:', + `${InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`, + ); } - if (network.responseBodySize > InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES) { - network.responseBody = InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE; - Logger.warn('IBG-RN:', InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE); + if (network.responseBodySize > MAX_NETWORK_BODY_SIZE_IN_BYTES) { + network.responseBody = `${InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`; + Logger.warn( + 'IBG-RN:', + `${InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`, + ); } if (network.requestBody && isContentTypeNotAllowed(network.requestContentType)) { diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index c9204a4c59..7032bbc07f 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -152,11 +152,12 @@ export interface InstabugNativeModule extends NativeModule { isW3CaughtHeaderEnabled(): Promise; - // W3C Feature Flags Listener for Android - registerW3CFlagsChangeListener(): void; + // Feature Flags Listener for Android + registerFeatureFlagsChangeListener(): void; setOnFeaturesUpdatedListener(handler?: (params: any) => void): void; // android only enableAutoMasking(autoMaskingTypes: AutoMaskingType[]): void; + getNetworkBodyMaxSize(): Promise; } export const NativeInstabug = NativeModules.Instabug; @@ -164,7 +165,7 @@ export const NativeInstabug = NativeModules.Instabug; export enum NativeEvents { PRESENDING_HANDLER = 'IBGpreSendingHandler', IBG_ON_FEATURES_UPDATED_CALLBACK = 'IBGOnFeatureUpdatedCallback', - ON_W3C_FLAGS_CHANGE = 'IBGOnNewW3CFlagsUpdateReceivedCallback', + ON_FEATURE_FLAGS_CHANGE = 'IBGOnNewFeatureFlagsUpdateReceivedCallback', } export const emitter = new NativeEventEmitter(NativeInstabug); diff --git a/src/utils/FeatureFlags.ts b/src/utils/FeatureFlags.ts index 479ab7ba47..f9c644e990 100644 --- a/src/utils/FeatureFlags.ts +++ b/src/utils/FeatureFlags.ts @@ -1,18 +1,20 @@ import { NativeInstabug } from '../native/NativeInstabug'; -import { _registerW3CFlagsChangeListener } from '../modules/Instabug'; +import { _registerFeatureFlagsChangeListener } from '../modules/Instabug'; export const FeatureFlags = { isW3ExternalTraceID: () => NativeInstabug.isW3ExternalTraceIDEnabled(), isW3ExternalGeneratedHeader: () => NativeInstabug.isW3ExternalGeneratedHeaderEnabled(), isW3CaughtHeader: () => NativeInstabug.isW3CaughtHeaderEnabled(), + networkLogLimit: () => NativeInstabug.getNetworkBodyMaxSize(), }; -export const registerW3CFlagsListener = () => { - _registerW3CFlagsChangeListener( +export const registerFeatureFlagsListener = () => { + _registerFeatureFlagsChangeListener( (res: { isW3ExternalTraceIDEnabled: boolean; isW3ExternalGeneratedHeaderEnabled: boolean; isW3CaughtHeaderEnabled: boolean; + networkBodyLimit: number; }) => { FeatureFlags.isW3ExternalTraceID = async () => { return res.isW3ExternalTraceIDEnabled; @@ -23,6 +25,9 @@ export const registerW3CFlagsListener = () => { FeatureFlags.isW3CaughtHeader = async () => { return res.isW3CaughtHeaderEnabled; }; + FeatureFlags.networkLogLimit = async () => { + return res.networkBodyLimit; + }; }, ); }; diff --git a/src/utils/InstabugConstants.ts b/src/utils/InstabugConstants.ts index 5d576c15b1..4d8fca4864 100644 --- a/src/utils/InstabugConstants.ts +++ b/src/utils/InstabugConstants.ts @@ -4,9 +4,9 @@ const InstabugConstants = { // TODO: dyanmically get the max size from the native SDK and update the error message to reflect the dynamic size. MAX_NETWORK_BODY_SIZE_IN_BYTES: 1024 * 10, // 10 KB MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE: - 'The response body has not been logged because it exceeds the maximum size of 10 Kb', + 'The response body has not been logged because it exceeds the maximum size of ', MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE: - 'The request body has not been logged because it exceeds the maximum size of 10 Kb', + 'The request body has not been logged because it exceeds the maximum size of ', SET_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE: 'IBG-RN: Expected key and value passed to setUserAttribute to be of type string', REMOVE_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE: diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index 05d817b353..391a00a381 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -72,10 +72,11 @@ const mockInstabug: InstabugNativeModule = { isW3ExternalTraceIDEnabled: jest.fn(), isW3ExternalGeneratedHeaderEnabled: jest.fn(), isW3CaughtHeaderEnabled: jest.fn(), - registerW3CFlagsChangeListener: jest.fn(), + registerFeatureFlagsChangeListener: jest.fn(), setNetworkLogBodyEnabled: jest.fn(), setOnFeaturesUpdatedListener: jest.fn(), enableAutoMasking: jest.fn(), + getNetworkBodyMaxSize: jest.fn().mockResolvedValue(10240), // 10 KB }; export default mockInstabug; diff --git a/test/modules/Instabug.spec.ts b/test/modules/Instabug.spec.ts index 904cefb7d7..753bf53c4e 100644 --- a/test/modules/Instabug.spec.ts +++ b/test/modules/Instabug.spec.ts @@ -902,17 +902,17 @@ describe('Instabug Module', () => { it('should register W3C flag listener', async () => { const callback = jest.fn(); - Instabug._registerW3CFlagsChangeListener(callback); + Instabug._registerFeatureFlagsChangeListener(callback); - expect(NativeInstabug.registerW3CFlagsChangeListener).toBeCalledTimes(1); + expect(NativeInstabug.registerFeatureFlagsChangeListener).toBeCalledTimes(1); }); it('should invoke callback on emitting the event IBGOnNewW3CFlagsUpdateReceivedCallback', () => { const callback = jest.fn(); - Instabug._registerW3CFlagsChangeListener(callback); - emitter.emit(NativeEvents.ON_W3C_FLAGS_CHANGE); + Instabug._registerFeatureFlagsChangeListener(callback); + emitter.emit(NativeEvents.ON_FEATURE_FLAGS_CHANGE); - expect(emitter.listenerCount(NativeEvents.ON_W3C_FLAGS_CHANGE)).toBe(1); + expect(emitter.listenerCount(NativeEvents.ON_FEATURE_FLAGS_CHANGE)).toBe(1); expect(callback).toHaveBeenCalled(); }); diff --git a/test/modules/NetworkLogger.spec.ts b/test/modules/NetworkLogger.spec.ts index be567b8d1f..3c95024a59 100644 --- a/test/modules/NetworkLogger.spec.ts +++ b/test/modules/NetworkLogger.spec.ts @@ -77,22 +77,23 @@ describe('NetworkLogger Module', () => { expect(Interceptor.disableInterception).toBeCalledTimes(1); }); - it('should report the network log', () => { + it('should report the network log', async () => { Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(clone(network))); + .mockImplementation(async (callback) => await callback(clone(network))); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toBeCalledTimes(1); expect(reportNetworkLog).toBeCalledWith(network); + expect(NativeInstabug.getNetworkBodyMaxSize).toBeCalledTimes(1); }); it('should send log network when setNetworkDataObfuscationHandler is set', async () => { const randomString = '28930q938jqhd'; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(clone(network))); + .mockImplementation(async (callback) => await callback(clone(network))); NetworkLogger.setNetworkDataObfuscationHandler((networkData) => { networkData.requestHeaders.token = randomString; return Promise.resolve(networkData); @@ -168,7 +169,7 @@ describe('NetworkLogger Module', () => { consoleSpy.mockRestore(); }); - it('should omit request body if its content type is not allowed', () => { + it('should omit request body if its content type is not allowed', async () => { const consoleWarn = jest.spyOn(Logger, 'warn').mockImplementation(); jest.mocked(isContentTypeNotAllowed).mockReturnValueOnce(true); @@ -179,9 +180,9 @@ describe('NetworkLogger Module', () => { Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith({ ...networkData, @@ -193,7 +194,7 @@ describe('NetworkLogger Module', () => { consoleWarn.mockRestore(); }); - it('should omit response body if its content type is not allowed', () => { + it('should omit response body if its content type is not allowed', async () => { const consoleWarn = jest.spyOn(Logger, 'warn').mockImplementation(); jest.mocked(isContentTypeNotAllowed).mockReturnValueOnce(true); @@ -204,9 +205,9 @@ describe('NetworkLogger Module', () => { Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith({ ...networkData, @@ -218,23 +219,26 @@ describe('NetworkLogger Module', () => { consoleWarn.mockRestore(); }); - it('should omit request body if its size exceeds the maximum allowed size', () => { + it('should omit request body if its size exceeds the maximum allowed size', async () => { const consoleWarn = jest.spyOn(Logger, 'warn').mockImplementation(); + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); const networkData = { ...network, - requestBodySize: InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES + 1, + requestBodySize: MAX_NETWORK_BODY_SIZE_IN_BYTES + 1, }; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith({ ...networkData, - requestBody: InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE, + requestBody: `${InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`, }); expect(consoleWarn).toBeCalledTimes(1); @@ -242,38 +246,43 @@ describe('NetworkLogger Module', () => { consoleWarn.mockRestore(); }); - it('should not omit request body if its size does not exceed the maximum allowed size', () => { + it('should not omit request body if its size does not exceed the maximum allowed size', async () => { + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); + const networkData = { ...network, - requestBodySize: InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES, + requestBodySize: MAX_NETWORK_BODY_SIZE_IN_BYTES, }; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith(networkData); }); - it('should omit response body if its size exceeds the maximum allowed size', () => { + it('should omit response body if its size exceeds the maximum allowed size', async () => { const consoleWarn = jest.spyOn(Logger, 'warn').mockImplementation(); + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); const networkData = { ...network, - responseBodySize: InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES + 1, + responseBodySize: MAX_NETWORK_BODY_SIZE_IN_BYTES + 1, }; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith({ ...networkData, - responseBody: InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE, + responseBody: `${InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`, }); expect(consoleWarn).toBeCalledTimes(1); @@ -281,17 +290,19 @@ describe('NetworkLogger Module', () => { consoleWarn.mockRestore(); }); - it('should not omit response body if its size does not exceed the maximum allowed size', () => { + it('should not omit response body if its size does not exceed the maximum allowed size', async () => { + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); + const networkData = { ...network, - responseBodySize: InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES, + responseBodySize: MAX_NETWORK_BODY_SIZE_IN_BYTES, }; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith(networkData); });