Skip to content

feat: support ignore flag secure on android. #1412

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

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
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-React-Native/compare/v15.1.0...dev)

### Added

- Add support for ignoreFlagSecure to bypass SDK screenshot security protocols on Android. ([#1394](https://github.com/Instabug/Instabug-React-Native/pull/1394))

## [15.0.1](https://github.com/Instabug/Instabug-React-Native/compare/v14.3.0...v15.0.1)

### Added
Expand Down
56 changes: 38 additions & 18 deletions android/src/main/java/com/instabug/reactlibrary/RNInstabug.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class RNInstabug {

private static RNInstabug instance;

private RNInstabug() {}
private RNInstabug() {
}


public static RNInstabug getInstance() {
Expand All @@ -36,14 +37,13 @@ public static RNInstabug getInstance() {
/**
* Initializes the SDK on the native side, which is useful for capturing startup issues specific to the native part of the app.
*
* @param application The application context.
* @param application The application context.
* @param applicationToken The app's identifying token, available on your dashboard.
* @param logLevel The level of detail in logs that you want to print.
* <p>Pick one of the log levels described in {@link LogLevel}.
* default logLevel is {@link LogLevel#ERROR}</p>
* @param InvocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
*
* @param logLevel The level of detail in logs that you want to print.
* <p>Pick one of the log levels described in {@link LogLevel}.
* default logLevel is {@link LogLevel#ERROR}</p>
* @param InvocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
* @example <p>Here's an example usage: </p>
* <blockquote><pre>
* RNInstabug.getInstance().init(
Expand All @@ -59,17 +59,24 @@ public void init(
@NonNull Application application,
@NonNull String applicationToken,
int logLevel,
Boolean ignoreSecureFlag,
@NonNull InstabugInvocationEvent... InvocationEvent
) {
) {
try {

setBaseUrlForDeprecationLogs();
setCurrentPlatform();

new Instabug.Builder(application, applicationToken)
Instabug.Builder builder = new Instabug.Builder(application, applicationToken)
.setInvocationEvents(InvocationEvent)
.setSdkDebugLogsLevel(logLevel)
.build();
.setSdkDebugLogsLevel(logLevel);

if (ignoreSecureFlag != null) {
builder.ignoreFlagSecure(ignoreSecureFlag);
}

builder.build();


// Temporarily disabling APM hot launches
APM.setHotAppLaunchEnabled(false);
Expand All @@ -80,15 +87,13 @@ public void init(
}



/**
* Initializes the SDK on the native side, which is useful for capturing startup issues specific to the native part of the app.
*
* @param application The application context.
* @param application The application context.
* @param applicationToken The app's identifying token, available on your dashboard.
* @param invocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
*
* @param invocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
* @example <p>Here's an example usage: </p>
* <blockquote><pre>
* RNInstabug.getInstance().init(
Expand All @@ -104,7 +109,7 @@ public void init(
@NonNull String applicationToken,
@NonNull InstabugInvocationEvent... invocationEvent
) {
init(application, applicationToken, LogLevel.ERROR, invocationEvent);
init(application, applicationToken, LogLevel.ERROR,null, invocationEvent);
}

@VisibleForTesting
Expand Down Expand Up @@ -160,6 +165,7 @@ public static class Builder {
* The events that trigger the SDK's user interface.
*/
private InstabugInvocationEvent[] invocationEvents;
private Boolean ignoreFlagSecure;


/**
Expand Down Expand Up @@ -210,6 +216,16 @@ public Builder setCodePushVersion(String codePushVersion) {
return this;
}

/**
* Sets flag to override SDK screenshot security behavior.
*
* @param ignoreFlagSecure flag to override SDK screenshot security behavior.
*/
public Builder ignoreFlagSecure(boolean ignoreFlagSecure) {
this.ignoreFlagSecure = ignoreFlagSecure;
return this;
}

/**
* Sets the invocation triggering events for the SDK's user interface
*
Expand Down Expand Up @@ -237,6 +253,10 @@ public void build() {
instabugBuilder.setCodePushVersion(codePushVersion);
}

if (ignoreFlagSecure != null) {
instabugBuilder.ignoreFlagSecure(ignoreFlagSecure);
}

instabugBuilder.build();

// Temporarily disabling APM hot launches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public void init(
final ReadableArray invocationEventValues,
final String logLevel,
final boolean useNativeNetworkInterception,
@Nullable final String codePushVersion
@Nullable final String codePushVersion,
final ReadableMap map
) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
Expand All @@ -166,6 +167,10 @@ public void run() {
.setInvocationEvents(invocationEvents)
.setLogLevel(parsedLogLevel);

if (map!=null&&map.hasKey("ignoreFlagSecure")) {
builder.ignoreFlagSecure(map.getBoolean("ignoreFlagSecure"));
}

if (codePushVersion != null) {
if (Instabug.isBuilt()) {
Instabug.setCodePushVersion(codePushVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.instabug.reactlibrary.util.GlobalMocks.reflected;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockConstruction;
Expand Down Expand Up @@ -62,18 +63,20 @@ public void testInitWithLogLevel() {
// Initializes Instabug with the correct token
assertEquals(token, actualToken);
when(mock.setSdkDebugLogsLevel(anyInt())).thenReturn(mock);
when(mock.ignoreFlagSecure(anyBoolean())).thenReturn(mock);
when(mock.setInvocationEvents(any())).thenReturn(mock);
});

sut.init(mContext, token, logLevel, invocationEvents);
sut.init(mContext, token, logLevel, true, invocationEvents);

Instabug.Builder builder = mInstabugBuilder.constructed().get(0);

// Here we check that it has changed to verbose value of the `logLevel` property
verify(builder).setSdkDebugLogsLevel(LogLevel.VERBOSE);
verify(builder).setInvocationEvents(invocationEvents);
verify(builder).build();
verify(builder).ignoreFlagSecure(true);

verify(builder).build();


verify(sut).setBaseUrlForDeprecationLogs();
Expand All @@ -95,7 +98,7 @@ public void testInitWithoutLogLevel() {

sut.init(mContext, token, invocationEvents);

verify(sut).init(mContext, token, defaultLogLevel, invocationEvents);
verify(sut).init(mContext, token, defaultLogLevel, null,invocationEvents);
mInstabugBuilder.close();
}

Expand Down
12 changes: 7 additions & 5 deletions examples/default/ios/InstabugTests/InstabugSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ - (void)testInit {

OCMStub([mock setCodePushVersion:codePushVersion]);

[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion];
[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion
options:nil
];
OCMVerify([mock setCodePushVersion:codePushVersion]);

OCMVerify([self.mRNInstabug initWithToken:appToken invocationEvents:floatingButtonInvocationEvent debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception]);
Expand Down Expand Up @@ -610,18 +612,18 @@ - (void) testIsW3CaughtHeaderEnabled {

- (void)testEnableAutoMasking {
id mock = OCMClassMock([Instabug class]);

NSArray *autoMaskingTypes = [NSArray arrayWithObjects:
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionLabels],
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionTextInputs],
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMedia],
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMaskNothing],
nil];

OCMStub([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);

[self.instabugBridge enableAutoMasking:autoMaskingTypes];

OCMVerify([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);
}

Expand Down
3 changes: 2 additions & 1 deletion ios/RNInstabug/InstabugReactBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

- (void)setEnabled:(BOOL)isEnabled;

- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel useNativeNetworkInterception:(BOOL)useNativeNetworkInterception codePushVersion:(NSString *)codePushVersion;
- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel useNativeNetworkInterception:(BOOL)useNativeNetworkInterception codePushVersion:(NSString *)codePushVersion
options:(nullable NSDictionary *)options;

- (void)setCodePushVersion:(NSString *)version;

Expand Down
4 changes: 3 additions & 1 deletion ios/RNInstabug/InstabugReactBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ - (dispatch_queue_t)methodQueue {
invocationEvents:(NSArray *)invocationEventsArray
debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel
useNativeNetworkInterception:(BOOL)useNativeNetworkInterception
codePushVersion:(NSString *)codePushVersion) {
codePushVersion:(NSString *)codePushVersion
options:(nullable NSDictionary *)options
) {
IBGInvocationEvent invocationEvents = 0;

for (NSNumber *boxedValue in invocationEventsArray) {
Expand Down
5 changes: 5 additions & 0 deletions src/models/InstabugConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export interface InstabugConfig {
*/
codePushVersion?: string;

/**
* An optional flag to override SDK screenshot security behavior.
*/
ignoreAndroidSecureFlag?: boolean;

/**
* An optional network interception mode, this determines whether network interception
* is done in the JavaScript side or in the native Android and iOS SDK side.
Expand Down
5 changes: 5 additions & 0 deletions src/modules/Instabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ const initializeNativeInstabug = (config: InstabugConfig) => {
shouldEnableNativeInterception &&
config.networkInterceptionMode === NetworkInterceptionMode.native,
config.codePushVersion,
config.ignoreAndroidSecureFlag != null
? {
ignoreAndroidSecureFlag: config.ignoreAndroidSecureFlag,
}
: undefined,
);
};

Expand Down
3 changes: 3 additions & 0 deletions src/native/NativeInstabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export interface InstabugNativeModule extends NativeModule {
debugLogsLevel: LogLevel,
useNativeNetworkInterception: boolean,
codePushVersion?: string,
options?: {
ignoreAndroidSecureFlag?: boolean;
},
): void;
show(): void;

Expand Down
8 changes: 8 additions & 0 deletions test/modules/Instabug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ describe('Instabug Module', () => {
invocationEvents: [InvocationEvent.floatingButton, InvocationEvent.shake],
debugLogsLevel: LogLevel.debug,
codePushVersion: '1.1.0',
ignoreAndroidSecureFlag: true,
};
const usesNativeNetworkInterception = false;

Expand All @@ -302,6 +303,7 @@ describe('Instabug Module', () => {
instabugConfig.debugLogsLevel,
usesNativeNetworkInterception,
instabugConfig.codePushVersion,
{ ignoreAndroidSecureFlag: instabugConfig.ignoreAndroidSecureFlag },
);
});

Expand All @@ -321,6 +323,7 @@ describe('Instabug Module', () => {
debugLogsLevel: LogLevel.debug,
networkInterceptionMode: NetworkInterceptionMode.native,
codePushVersion: '1.1.0',
ignoreAndroidSecureFlag: true,
};

// Stubbing Network feature flags
Expand Down Expand Up @@ -353,6 +356,7 @@ describe('Instabug Module', () => {
// usesNativeNetworkInterception should be true when using native interception mode with iOS
true,
instabugConfig.codePushVersion,
{ ignoreAndroidSecureFlag: instabugConfig.ignoreAndroidSecureFlag },
);
}
});
Expand Down Expand Up @@ -952,6 +956,7 @@ describe('Instabug iOS initialization tests', () => {
config.debugLogsLevel,
false, // Disable native interception
config.codePushVersion,
config.ignoreAndroidSecureFlag,
);
});

Expand All @@ -970,6 +975,7 @@ describe('Instabug iOS initialization tests', () => {
config.debugLogsLevel,
true, // Enable native interception
config.codePushVersion,
config.ignoreAndroidSecureFlag,
);
});

Expand All @@ -988,6 +994,7 @@ describe('Instabug iOS initialization tests', () => {
config.debugLogsLevel,
false, // Disable native interception
config.codePushVersion,
config.ignoreAndroidSecureFlag,
);
});

Expand Down Expand Up @@ -1032,6 +1039,7 @@ describe('Instabug Android initialization tests', () => {
config.debugLogsLevel,
false, // always disable native interception to insure sending network logs to core (Bugs & Crashes).
config.codePushVersion,
{ ignoreAndroidSecureFlag: config.ignoreAndroidSecureFlag },
);
});
});
Expand Down