Skip to content

Commit 1d1417d

Browse files
committed
feat: enabling network logs auto masking
1 parent 010f89d commit 1d1417d

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/modules/NetworkLogger.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { RequestHandler } from '@apollo/client';
33
import InstabugConstants from '../utils/InstabugConstants';
44
import xhr, { NetworkData, ProgressCallback } from '../utils/XhrNetworkInterceptor';
55
import { reportNetworkLog, isContentTypeNotAllowed } from '../utils/InstabugUtils';
6+
import { NativeInstabug } from '../native/NativeInstabug';
67

78
export type { NetworkData };
89

@@ -101,3 +102,12 @@ export const apolloLinkRequestHandler: RequestHandler = (operation, forward) =>
101102

102103
return forward(operation);
103104
};
105+
106+
/**
107+
* Sets whether network logs sensitive information should be masked.
108+
* It is disabled by default.
109+
* @param isEnabled
110+
*/
111+
export const setAutoMaskingEnabled = (isEnabled: boolean) => {
112+
NativeInstabug.setAutoMaskingEnabled(isEnabled);
113+
};

src/native/NativeInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface InstabugNativeModule extends NativeModule {
7070
): void;
7171

7272
setNetworkLoggingEnabled(isEnabled: boolean): void;
73+
setAutoMaskingEnabled(isEnabled: boolean): void;
7374

7475
// Repro Steps APIs //
7576
setReproStepsConfig(

test/mocks/mockInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const mockInstabug: InstabugNativeModule = {
6969
addFileAttachmentWithDataToReport: jest.fn(),
7070
setNetworkLoggingEnabled: jest.fn(),
7171
willRedirectToStore: jest.fn(),
72+
setAutoMaskingEnabled: jest.fn(),
7273
};
7374

7475
export default mockInstabug;

test/modules/NetworkLogger.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as NetworkLogger from '../../src/modules/NetworkLogger';
77
import Interceptor from '../../src/utils/XhrNetworkInterceptor';
88
import { isContentTypeNotAllowed, reportNetworkLog } from '../../src/utils/InstabugUtils';
99
import InstabugConstants from '../../src/utils/InstabugConstants';
10+
import { NativeInstabug } from '../../src/native/NativeInstabug';
1011

1112
const clone = <T>(obj: T): T => {
1213
return JSON.parse(JSON.stringify(obj));
@@ -276,4 +277,11 @@ describe('NetworkLogger Module', () => {
276277

277278
expect(reportNetworkLog).toHaveBeenCalledWith(networkData);
278279
});
280+
281+
it('should call the native method setAutoMaskingEnabled', () => {
282+
NetworkLogger.setAutoMaskingEnabled(true);
283+
284+
expect(NativeInstabug.setAutoMaskingEnabled).toBeCalledTimes(1);
285+
expect(NativeInstabug.setAutoMaskingEnabled).toBeCalledWith(true);
286+
});
279287
});

0 commit comments

Comments
 (0)