Skip to content

Commit 2bfb786

Browse files
committed
Remove allowedProtocols passing between modules
1. Only place to check if the url is allowed is through the Util method which checks the allowedProtocols list from config. 2. Removed method signatures that were introduced because of this 3. Test methods update 4. Logs if the url was blocked
1 parent ce2dcaf commit 2bfb786

File tree

6 files changed

+19
-37
lines changed

6 files changed

+19
-37
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableActionRunner.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,12 @@ class IterableActionRunner {
1818
static IterableActionRunnerImpl instance = new IterableActionRunnerImpl();
1919

2020
static boolean executeAction(@NonNull Context context, @Nullable IterableAction action, @NonNull IterableActionSource source) {
21-
return instance.executeAction(context, action, source, IterableApi.getInstance().config.allowedProtocols);
22-
}
23-
24-
static boolean executeAction(@NonNull Context context, @Nullable IterableAction action, @NonNull IterableActionSource source, @NonNull String[] allowedProtocols) {
25-
return instance.executeAction(context, action, source, allowedProtocols);
21+
return instance.executeAction(context, action, source);
2622
}
2723

2824
static class IterableActionRunnerImpl {
2925
private static final String TAG = "IterableActionRunner";
3026

31-
boolean executeAction(@NonNull Context context, @Nullable IterableAction action, @NonNull IterableActionSource source) {
32-
return executeAction(context, action, source, IterableApi.getInstance().config.allowedProtocols);
33-
}
34-
3527
/**
3628
* Execute an {@link IterableAction} as a response to push action
3729
*
@@ -40,15 +32,15 @@ boolean executeAction(@NonNull Context context, @Nullable IterableAction action,
4032
* @param allowedProtocols protocols that the SDK is allowed to open in addition to `https`
4133
* @return `true` if the action was handled, `false` if it was not
4234
*/
43-
boolean executeAction(@NonNull Context context, @Nullable IterableAction action, @NonNull IterableActionSource source, @NonNull String[] allowedProtocols) {
35+
boolean executeAction(@NonNull Context context, @Nullable IterableAction action, @NonNull IterableActionSource source) {
4436
if (action == null) {
4537
return false;
4638
}
4739

4840
IterableActionContext actionContext = new IterableActionContext(action, source);
4941

5042
if (action.isOfType(IterableAction.ACTION_TYPE_OPEN_URL)) {
51-
return openUri(context, Uri.parse(action.getData()), actionContext, allowedProtocols);
43+
return openUri(context, Uri.parse(action.getData()), actionContext);
5244
} else {
5345
return callCustomActionIfSpecified(action, actionContext);
5446
}
@@ -65,10 +57,9 @@ boolean executeAction(@NonNull Context context, @Nullable IterableAction action,
6557
* @return `true` if the action was handled, or an activity was found for this URL
6658
* `false` if the handler did not handle this URL and no activity was found to open it with
6759
*/
68-
private boolean openUri(@NonNull Context context, @NonNull Uri uri, @NonNull IterableActionContext actionContext, String[] allowedProtocols) {
60+
private boolean openUri(@NonNull Context context, @NonNull Uri uri, @NonNull IterableActionContext actionContext) {
6961
// Handle URL: check for deep links within the app
70-
if (!IterableUtil.isUrlOpenAllowed(uri.toString(), allowedProtocols)) {
71-
IterableLogger.e(TAG, "URL was not in the allowed protocols list");
62+
if (!IterableUtil.isUrlOpenAllowed(uri.toString())) {
7263
return false;
7364
}
7465

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public void setUserId(@Nullable String userId) {
402402
* or the original url if it is not an Iterable link.
403403
*/
404404
public void getAndTrackDeepLink(@NonNull String uri, @NonNull IterableHelper.IterableActionHandler onCallback) {
405-
IterableDeeplinkManager.getAndTrackDeeplink(uri, onCallback, config.allowedProtocols);
405+
IterableDeeplinkManager.getAndTrackDeeplink(uri, onCallback);
406406
}
407407

408408
/**
@@ -427,7 +427,7 @@ public void execute(String originalUrl) {
427427
IterableAction action = IterableAction.actionOpenUrl(originalUrl);
428428
IterableActionRunner.executeAction(getInstance().getMainActivityContext(), action, IterableActionSource.APP_LINK);
429429
}
430-
}, sharedInstance.config.allowedProtocols);
430+
});
431431
return true;
432432
} else {
433433
IterableAction action = IterableAction.actionOpenUrl(uri);

iterableapi/src/main/java/com/iterable/iterableapi/IterableDeeplinkManager.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,8 @@ class IterableDeeplinkManager {
2222
* @param callback The callback to execute the original URL is retrieved
2323
*/
2424
static void getAndTrackDeeplink(@Nullable String url, @NonNull IterableHelper.IterableActionHandler callback) {
25-
IterableDeeplinkManager.getAndTrackDeeplink(url, callback, new String[0]);
26-
}
27-
28-
/**
29-
* Tracks a link click and passes the redirected URL to the callback
30-
* @param url The URL that was clicked
31-
* @param callback The callback to execute the original URL is retrieved
32-
* @param allowedProtocols a list of protocols (on top of `https`) to allow opening
33-
*/
34-
static void getAndTrackDeeplink(@Nullable String url, @NonNull IterableHelper.IterableActionHandler callback, @NonNull String[] allowedProtocols) {
3525
if (url != null) {
36-
if (!IterableUtil.isUrlOpenAllowed(url, allowedProtocols)) {
37-
IterableLogger.e(TAG, "URL was not in the allowed protocols list");
26+
if (!IterableUtil.isUrlOpenAllowed(url)) {
3827
return;
3928
}
4029

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,17 @@ public void handleInAppClick(@NonNull IterableInAppMessage message, @Nullable Ur
271271
if (urlString.startsWith(IterableConstants.URL_SCHEME_ACTION)) {
272272
// This is an action:// URL, pass that to the custom action handler
273273
String actionName = urlString.replace(IterableConstants.URL_SCHEME_ACTION, "");
274-
IterableActionRunner.executeAction(context, IterableAction.actionCustomAction(actionName), IterableActionSource.IN_APP, IterableApi.getInstance().config.allowedProtocols);
274+
IterableActionRunner.executeAction(context, IterableAction.actionCustomAction(actionName), IterableActionSource.IN_APP);
275275
} else if (urlString.startsWith(IterableConstants.URL_SCHEME_ITBL)) {
276276
// Handle itbl:// URLs, pass that to the custom action handler for compatibility
277277
String actionName = urlString.replace(IterableConstants.URL_SCHEME_ITBL, "");
278-
IterableActionRunner.executeAction(context, IterableAction.actionCustomAction(actionName), IterableActionSource.IN_APP, IterableApi.getInstance().config.allowedProtocols);
278+
IterableActionRunner.executeAction(context, IterableAction.actionCustomAction(actionName), IterableActionSource.IN_APP);
279279
} else if (urlString.startsWith(IterableConstants.URL_SCHEME_ITERABLE)) {
280280
// Handle iterable:// URLs - reserved for actions defined by the SDK only
281281
String actionName = urlString.replace(IterableConstants.URL_SCHEME_ITERABLE, "");
282282
handleIterableCustomAction(actionName, message);
283283
} else {
284-
IterableActionRunner.executeAction(context, IterableAction.actionOpenUrl(urlString), IterableActionSource.IN_APP, IterableApi.getInstance().config.allowedProtocols);
284+
IterableActionRunner.executeAction(context, IterableAction.actionOpenUrl(urlString), IterableActionSource.IN_APP);
285285
}
286286
}
287287
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableUtil.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,19 @@ boolean writeFile(File file, String content) {
279279
}
280280
}
281281

282-
static boolean isUrlOpenAllowed(@NonNull String url, @NonNull String[] allowedProtocols) {
282+
static boolean isUrlOpenAllowed(@NonNull String url) {
283283
String urlProtocol = url.split("://")[0];
284-
if(urlProtocol.equals("https")){
284+
if (urlProtocol.equals("https")) {
285285
return true;
286286
}
287-
for (String allowedProtocol : allowedProtocols) {
287+
288+
for (String allowedProtocol : IterableApi.getInstance().config.allowedProtocols) {
288289
if (urlProtocol.equals(allowedProtocol)) {
289290
return true;
290291
}
291292
}
292293

294+
IterableLogger.d(TAG, urlProtocol + " is not in the allowed protocols");
293295
return false;
294296
}
295297
}

iterableapi/src/test/java/com/iterable/iterableapi/IterablePushActionReceiverTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void testTrackPushOpenWithCustomAction() throws Exception {
8080

8181
// Verify that IterableActionRunner was called with the proper action
8282
ArgumentCaptor<IterableAction> capturedAction = ArgumentCaptor.forClass(IterableAction.class);
83-
verify(actionRunnerMock).executeAction(any(Context.class), capturedAction.capture(), eq(IterableActionSource.PUSH), eq(new String[0]));
83+
verify(actionRunnerMock).executeAction(any(Context.class), capturedAction.capture(), eq(IterableActionSource.PUSH));
8484
assertEquals("customAction", capturedAction.getValue().getType());
8585

8686
// Verify that the main app activity was launched
@@ -133,7 +133,7 @@ public void testPushActionWithTextInput() throws Exception {
133133

134134
// Verify that IterableActionRunner was called with the proper action
135135
ArgumentCaptor<IterableAction> actionCaptor = ArgumentCaptor.forClass(IterableAction.class);
136-
verify(actionRunnerMock).executeAction(any(Context.class), actionCaptor.capture(), eq(IterableActionSource.PUSH), eq(new String[0]));
136+
verify(actionRunnerMock).executeAction(any(Context.class), actionCaptor.capture(), eq(IterableActionSource.PUSH));
137137
IterableAction capturedAction = actionCaptor.getValue();
138138
assertEquals("handleTextInput", capturedAction.getType());
139139
assertEquals("input text", capturedAction.userInput);
@@ -151,7 +151,7 @@ public void testLegacyDeepLinkPayload() throws Exception {
151151

152152
// Verify that IterableActionRunner was called with openUrl action
153153
ArgumentCaptor<IterableAction> capturedAction = ArgumentCaptor.forClass(IterableAction.class);
154-
verify(actionRunnerMock).executeAction(any(Context.class), capturedAction.capture(), eq(IterableActionSource.PUSH), eq(new String[0]));
154+
verify(actionRunnerMock).executeAction(any(Context.class), capturedAction.capture(), eq(IterableActionSource.PUSH));
155155
assertEquals("openUrl", capturedAction.getValue().getType());
156156
assertEquals("https://example.com", capturedAction.getValue().getData());
157157
}

0 commit comments

Comments
 (0)