Skip to content

Commit fe5886c

Browse files
committed
fix tests
1 parent a27f991 commit fe5886c

File tree

9 files changed

+120
-108
lines changed

9 files changed

+120
-108
lines changed

common/src/main/java/com/microsoft/identity/common/internal/platform/AndroidPlatformUtil.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@
5353
import com.microsoft.identity.common.java.flighting.CommonFlight;
5454
import com.microsoft.identity.common.java.flighting.CommonFlightsManager;
5555
import com.microsoft.identity.common.java.logging.Logger;
56-
import com.microsoft.identity.common.java.ui.BrowserDescriptor;
5756
import com.microsoft.identity.common.java.util.IPlatformUtil;
5857
import com.microsoft.identity.common.java.util.StringUtil;
5958

6059
import java.security.NoSuchAlgorithmException;
6160
import java.util.AbstractMap;
6261
import java.util.ArrayList;
63-
import java.util.HashSet;
6462
import java.util.List;
6563
import java.util.Map;
6664

@@ -80,52 +78,6 @@ public class AndroidPlatformUtil implements IPlatformUtil {
8078
@Nullable
8179
private final Activity mActivity;
8280

83-
/**
84-
* List of System Browsers which can be used from broker, currently only Chrome is supported.
85-
* This information here is populated from the default browser safe-list in MSAL.
86-
*
87-
* @return List of BrowserDescriptors which are considered safe for the broker.
88-
*/
89-
@Override
90-
public List<BrowserDescriptor> getBrowserSafeListForBroker() {
91-
List<BrowserDescriptor> browserDescriptors = new ArrayList<>();
92-
browserDescriptors.add(getBrowserDescriptorForChrome());
93-
return browserDescriptors;
94-
}
95-
96-
/**
97-
* Return a list of BrowserDescriptors that are considered safe for the Switch to browser flow.
98-
*/
99-
@Override
100-
public List<BrowserDescriptor> getBrowserSafeListForSwitchBrowser() {
101-
List<BrowserDescriptor> browserDescriptors = new ArrayList<>();
102-
browserDescriptors.add(getBrowserDescriptorForChrome());
103-
browserDescriptors.add(getBrowserDescriptorForEdge());
104-
return browserDescriptors;
105-
}
106-
107-
private BrowserDescriptor getBrowserDescriptorForChrome() {
108-
final HashSet<String> signatureHashes = new HashSet<>();
109-
signatureHashes.add("7fmduHKTdHHrlMvldlEqAIlSfii1tl35bxj1OXN5Ve8c4lU6URVu4xtSHc3BVZxS6WWJnxMDhIfQN0N0K2NDJg==");
110-
return new BrowserDescriptor(
111-
"com.android.chrome",
112-
signatureHashes,
113-
null,
114-
null
115-
);
116-
}
117-
118-
private BrowserDescriptor getBrowserDescriptorForEdge() {
119-
final HashSet<String> edgeSignatureHashes = new HashSet<>();
120-
edgeSignatureHashes.add("Ivy-Rk6ztai_IudfbyUrSHugzRqAtHWslFvHT0PTvLMsEKLUIgv7ZZbVxygWy_M5mOPpfjZrd3vOx3t-cA6fVQ==");
121-
return new BrowserDescriptor(
122-
"com.microsoft.emmx",
123-
edgeSignatureHashes,
124-
null,
125-
null
126-
);
127-
}
128-
12981
@Nullable
13082
@Override
13183
public String getInstalledCompanyPortalVersion() {

common/src/main/java/com/microsoft/identity/common/internal/request/MsalBrokerRequestAdapter.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import com.microsoft.identity.common.java.opentelemetry.SpanExtension;
5858
import com.microsoft.identity.common.java.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationResult;
5959
import com.microsoft.identity.common.java.providers.oauth2.AuthorizationResult;
60-
import com.microsoft.identity.common.java.ui.BrowserDescriptor;
6160
import com.microsoft.identity.common.java.util.BrokerProtocolVersionUtil;
6261
import com.microsoft.identity.common.java.util.ObjectMapper;
6362
import com.microsoft.identity.common.java.authorities.AzureActiveDirectoryAuthority;
@@ -77,9 +76,6 @@
7776
import com.microsoft.identity.common.logging.Logger;
7877

7978
import java.io.IOException;
80-
import java.util.ArrayList;
81-
import java.util.HashSet;
82-
import java.util.List;
8379

8480
public class MsalBrokerRequestAdapter implements IBrokerRequestAdapter {
8581

@@ -490,27 +486,6 @@ private boolean getMultipleCloudsSupported(@NonNull final TokenCommandParameters
490486
}
491487
}
492488

493-
/**
494-
* List of System Browsers which can be used from broker, currently only Chrome is supported.
495-
* This information here is populated from the default browser safelist in MSAL.
496-
*
497-
* @return
498-
*/
499-
public static List<BrowserDescriptor> getBrowserSafeListForBroker() {
500-
List<BrowserDescriptor> browserDescriptors = new ArrayList<>();
501-
final HashSet<String> signatureHashes = new HashSet<String>();
502-
signatureHashes.add("7fmduHKTdHHrlMvldlEqAIlSfii1tl35bxj1OXN5Ve8c4lU6URVu4xtSHc3BVZxS6WWJnxMDhIfQN0N0K2NDJg==");
503-
final BrowserDescriptor chrome = new BrowserDescriptor(
504-
"com.android.chrome",
505-
signatureHashes,
506-
null,
507-
null
508-
);
509-
browserDescriptors.add(chrome);
510-
511-
return browserDescriptors;
512-
}
513-
514489
/**
515490
* adds required broker protocol version key in request bundle if not null.
516491
*/

common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import com.microsoft.identity.common.java.constants.FidoConstants;
6161
import com.microsoft.identity.common.java.flighting.CommonFlight;
6262
import com.microsoft.identity.common.java.flighting.CommonFlightsManager;
63+
import com.microsoft.identity.common.java.ui.BrowserDescriptor;
6364
import com.microsoft.identity.common.java.ui.webview.authorization.IAuthorizationCompletionCallback;
6465
import com.microsoft.identity.common.java.challengehandlers.PKeyAuthChallenge;
6566
import com.microsoft.identity.common.java.challengehandlers.PKeyAuthChallengeFactory;
@@ -73,7 +74,6 @@
7374

7475
import java.net.URISyntaxException;
7576
import java.security.Principal;
76-
import java.util.Collections;
7777
import java.util.HashMap;
7878
import java.util.Locale;
7979
import java.util.Map;
@@ -343,7 +343,10 @@ protected boolean processSwitchBrowserRequest(@NonNull final WebView view, @NonN
343343
final Context context = view.getContext();
344344
final CustomTabsManager ctManager = new CustomTabsManager(context);
345345
final SwitchBrowserChallenge challenge = SwitchBrowserChallenge.constructFromUri(uri);
346-
final Browser browser = new BrowserSelector(context).select(Collections.emptyList(), null);
346+
final Browser browser = new BrowserSelector(context).select(
347+
BrowserDescriptor.getBrowserSafeListForSwitchBrowser(),
348+
null
349+
);
347350
if (browser != null && challenge != null) {
348351
final SwitchBrowserHandler handler = new SwitchBrowserHandler(context,ctManager, browser);
349352
return handler.processChallenge(challenge);

common/src/main/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/SwitchBrowserHandler.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SwitchBrowserHandler(
6363
}
6464
browserIntent.setPackage(browser.packageName)
6565
browserIntent.setData(challenge.uri)
66+
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
6667
context.startActivity(browserIntent)
6768
return true
6869
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// All rights reserved.
3+
//
4+
// This code is licensed under the MIT License.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files(the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions :
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
package com.microsoft.identity.common.internal.ipc.mock
24+
25+
import com.microsoft.identity.common.internal.ui.browser.BrowserSelector
26+
import com.microsoft.identity.common.java.browser.Browser
27+
import com.microsoft.identity.common.java.ui.BrowserDescriptor
28+
import org.robolectric.annotation.Implementation
29+
import org.robolectric.annotation.Implements
30+
31+
@Implements(BrowserSelector::class)
32+
class ShadowBrowserSelector {
33+
34+
@Implementation
35+
fun select(
36+
browserSafeList: List<BrowserDescriptor>,
37+
preferredBrowserDescriptor: BrowserDescriptor?) : Browser? {
38+
if (browserSafeList.isEmpty()) {
39+
return null
40+
}
41+
for (browser in browserSafeList) {
42+
if (browser.packageName == preferredBrowserDescriptor?.packageName) {
43+
return Browser(
44+
browser.packageName,
45+
browser.signatureHashes,
46+
browser.versionUpperBound,
47+
false
48+
)
49+
}
50+
}
51+
52+
val selectedBrowser = browserSafeList.first()
53+
return Browser(
54+
selectedBrowser.packageName,
55+
selectedBrowser.signatureHashes,
56+
selectedBrowser.versionUpperBound,
57+
false
58+
)
59+
}
60+
}

common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
package com.microsoft.identity.common.internal.ui.webview;
2424

2525
import android.content.Context;
26-
import android.net.Uri;
2726
import android.webkit.WebView;
2827

2928
import androidx.annotation.NonNull;
3029
import androidx.test.core.app.ApplicationProvider;
3130

3231
import com.microsoft.identity.common.adal.internal.AuthenticationConstants;
32+
import com.microsoft.identity.common.internal.ipc.mock.ShadowBrowserSelector;
3333
import com.microsoft.identity.common.internal.providers.oauth2.AuthorizationActivity;
3434
import com.microsoft.identity.common.internal.providers.oauth2.WebViewAuthorizationFragment;
3535
import com.microsoft.identity.common.java.ui.webview.authorization.IAuthorizationCompletionCallback;
@@ -39,6 +39,7 @@
3939
import org.junit.Test;
4040
import org.junit.runner.RunWith;
4141
import org.robolectric.RobolectricTestRunner;
42+
import org.robolectric.annotation.Config;
4243

4344
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.AUTHENTICATOR_MFA_LINKING_PREFIX;
4445
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.COMPANY_PORTAL_APP_PACKAGE_NAME;
@@ -52,6 +53,7 @@
5253

5354

5455
@RunWith(RobolectricTestRunner.class)
56+
@Config(shadows = {ShadowBrowserSelector.class})
5557
public class AzureActiveDirectoryWebViewClientTest {
5658
private WebView mMockWebView;
5759
private AzureActiveDirectoryWebViewClient mWebViewClient;
@@ -89,10 +91,6 @@ public class AzureActiveDirectoryWebViewClientTest {
8991
AuthenticationConstants.SWITCH_BROWSER.CODE + "=" + SWITCH_BROWSER_CODE + "&" +
9092
AuthenticationConstants.SWITCH_BROWSER.ACTION + "=" + SWITCH_BROWSER_ACTION;
9193

92-
private static final String TEST_SWITCH_BROWSER_URL =
93-
"https://" + SWITCH_BROWSER_ACTION_URI + SWITCH_BROWSER_ACTION_URI_PATHS + "?" +
94-
AuthenticationConstants.SWITCH_BROWSER.CODE + "=" + SWITCH_BROWSER_CODE;
95-
9694
@Before
9795
public void setup() {
9896
final AuthorizationActivity activity = mock(AuthorizationActivity.class);
@@ -105,8 +103,6 @@ public void setup() {
105103
when(activity.getApplicationContext()).thenReturn(context);
106104
when(activity.getFragment()).thenReturn(fragment);
107105
when(activity.getPackageManager()).thenReturn(context.getPackageManager());
108-
//when(fragment.constructSwitchBrowserUri(SWITCH_BROWSER_ACTION_URI + SWITCH_BROWSER_ACTION_URI_PATHS, params)).thenReturn(Uri.parse(TEST_SWITCH_BROWSER_URL));
109-
//when(fragment.launchWebBrowserIntent(Uri.parse(TEST_SWITCH_BROWSER_URL))).thenReturn(true);
110106
mMockWebView = new WebView(context);
111107
mWebViewClient = new AzureActiveDirectoryWebViewClient(
112108
activity,

common4j/src/main/com/microsoft/identity/common/java/ui/BrowserDescriptor.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
import com.google.gson.annotations.SerializedName;
2626

2727
import java.io.Serializable;
28+
import java.util.ArrayList;
2829
import java.util.Collections;
30+
import java.util.HashSet;
31+
import java.util.List;
2932
import java.util.Set;
3033

3134
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -39,16 +42,16 @@ public class BrowserDescriptor implements Serializable {
3942
private static final long serialVersionUID = 3745812401643512530L;
4043

4144
@SerializedName("browser_package_name")
42-
private String mPackageName;
45+
final private String mPackageName;
4346

4447
@SerializedName("browser_signature_hashes")
45-
private Set<String> mSignatureHashes;
48+
final private Set<String> mSignatureHashes;
4649

4750
@SerializedName("browser_version_lower_bound")
48-
private String mVersionLowerBound;
51+
final private String mVersionLowerBound;
4952

5053
@SerializedName("browser_version_upper_bound")
51-
private String mVersionUpperBound;
54+
final private String mVersionUpperBound;
5255

5356
public BrowserDescriptor(
5457
@NonNull final String packageName,
@@ -71,4 +74,48 @@ public BrowserDescriptor(
7174
mVersionLowerBound = versionLowerBound;
7275
mVersionUpperBound = versionUpperBound;
7376
}
77+
78+
static private BrowserDescriptor getBrowserDescriptorForEdge() {
79+
final HashSet<String> edgeSignatureHashes = new HashSet<>();
80+
edgeSignatureHashes.add("Ivy-Rk6ztai_IudfbyUrSHugzRqAtHWslFvHT0PTvLMsEKLUIgv7ZZbVxygWy_M5mOPpfjZrd3vOx3t-cA6fVQ==");
81+
return new BrowserDescriptor(
82+
"com.microsoft.emmx",
83+
edgeSignatureHashes,
84+
null,
85+
null
86+
);
87+
}
88+
89+
static private BrowserDescriptor getBrowserDescriptorForChrome() {
90+
final HashSet<String> signatureHashes = new HashSet<>();
91+
signatureHashes.add("7fmduHKTdHHrlMvldlEqAIlSfii1tl35bxj1OXN5Ve8c4lU6URVu4xtSHc3BVZxS6WWJnxMDhIfQN0N0K2NDJg==");
92+
return new BrowserDescriptor(
93+
"com.android.chrome",
94+
signatureHashes,
95+
null,
96+
null
97+
);
98+
}
99+
100+
/**
101+
* Return a list of BrowserDescriptors that are considered safe for the Switch to browser flow.
102+
*/
103+
static public List<BrowserDescriptor> getBrowserSafeListForSwitchBrowser() {
104+
List<BrowserDescriptor> browserDescriptors = new ArrayList<>();
105+
browserDescriptors.add(getBrowserDescriptorForChrome());
106+
browserDescriptors.add(getBrowserDescriptorForEdge());
107+
return browserDescriptors;
108+
}
109+
110+
/**
111+
* List of System Browsers which can be used from broker, currently only Chrome is supported.
112+
* This information here is populated from the default browser safe-list in MSAL.
113+
*
114+
* @return List of BrowserDescriptors which are considered safe for the broker.
115+
*/
116+
static public List<BrowserDescriptor> getBrowserSafeListForBroker() {
117+
List<BrowserDescriptor> browserDescriptors = new ArrayList<>();
118+
browserDescriptors.add(getBrowserDescriptorForChrome());
119+
return browserDescriptors;
120+
}
74121
}

common4j/src/main/com/microsoft/identity/common/java/util/IPlatformUtil.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.microsoft.identity.common.java.commands.ICommand;
2626
import com.microsoft.identity.common.java.exception.ClientException;
2727
import com.microsoft.identity.common.java.exception.ErrorStrings;
28-
import com.microsoft.identity.common.java.ui.BrowserDescriptor;
2928

3029
import java.security.NoSuchAlgorithmException;
3130
import java.util.List;
@@ -37,17 +36,6 @@
3736
import edu.umd.cs.findbugs.annotations.Nullable;
3837

3938
public interface IPlatformUtil {
40-
41-
/**
42-
* Return a list of BrowserDescriptors that are considered safe for the given platform.
43-
*/
44-
List<BrowserDescriptor> getBrowserSafeListForBroker();
45-
46-
/**
47-
* Return a list of BrowserDescriptors that are considered safe for the Switch to browser flow.
48-
*/
49-
List<BrowserDescriptor> getBrowserSafeListForSwitchBrowser();
50-
5139
/**
5240
* Gets version of the installed Company Portal app.
5341
* Returns null if the app is not installed, the value cannot be retrieved, or this operation is not supported.

common4j/src/testFixtures/java/com/microsoft/identity/common/components/MockPlatformComponentsFactory.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,6 @@ public String generate() {
131131
};
132132

133133
public static final IPlatformUtil NON_FUNCTIONAL_PLATFORM_UTIL = new IPlatformUtil() {
134-
@Override
135-
public List<BrowserDescriptor> getBrowserSafeListForBroker() {
136-
throw new UnsupportedOperationException();
137-
}
138-
139-
@Override
140-
public List<BrowserDescriptor> getBrowserSafeListForSwitchBrowser() {
141-
throw new UnsupportedOperationException();
142-
}
143-
144134
@Nullable
145135
@Override
146136
public String getInstalledCompanyPortalVersion() {

0 commit comments

Comments
 (0)