From f9a4008d19b1a7e956b51db3cec4a111f91fc056 Mon Sep 17 00:00:00 2001 From: Sowmya Malayanur Date: Thu, 13 Mar 2025 11:41:36 -0700 Subject: [PATCH 1/6] tests for overriding redirect url in cross cloud --- .../AzureActiveDirectoryWebViewClient.java | 22 +++++---- .../CrossCloudChallengeHandler.kt | 3 +- ...AzureActiveDirectoryWebViewClientTest.java | 45 ++++++++++++++++++- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java b/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java index 8c43255d09..16e203feb0 100644 --- a/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java +++ b/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java @@ -36,6 +36,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; +import androidx.annotation.VisibleForTesting; import androidx.lifecycle.ViewTreeLifecycleOwner; import com.microsoft.identity.common.adal.internal.AuthenticationConstants; @@ -636,23 +637,28 @@ private void processNonceAndReAttachHeaders(@NonNull final WebView view, @NonNul /** * This method is used to process the cross cloud redirect and attach the PRT header to the request. */ - private void processCloudRedirectAndPrtHeader(@NonNull final WebView view, @NonNull final String url) { + public void processCloudRedirectAndPrtHeader(@NonNull final WebView view, @NonNull final String url) { final String methodTag = TAG + ":processCloudRedirectAndPrtHeader"; final SpanContext spanContext = getActivity() instanceof AuthorizationActivity ? ((AuthorizationActivity) getActivity()).getSpanContext() : null; final Span span = spanContext != null ? OTelUtility.createSpanFromParent(SpanName.ProcessCrossCloudRedirect.name(), spanContext) : OTelUtility.createSpan(SpanName.ProcessCrossCloudRedirect.name()); + final CrossCloudChallengeHandler crossCloudChallengeHandler = new CrossCloudChallengeHandler(view, mRequestHeaders, span); + processCloudRedirectAndPrtHeaderInternal(url, crossCloudChallengeHandler, methodTag, span); + } + + @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + public void processCloudRedirectAndPrtHeaderInternal(@NonNull final String url, @NonNull final CrossCloudChallengeHandler crossCloudChallengeHandler, @NonNull final String methodTag, @NonNull final Span span) { try (final Scope scope = SpanExtension.makeCurrentSpan(span)) { - final CrossCloudChallengeHandler crossCloudChallengeHandler = new CrossCloudChallengeHandler(view, mRequestHeaders, span); crossCloudChallengeHandler.processChallenge(url); span.setStatus(StatusCode.OK); } catch (final Exception e) { - // No op if an exception happens - Logger.warn(methodTag, "Error processing cross cloud redirect and attaching PRT header." + e); - span.recordException(e); - } finally { - span.end(); - } + // No op if an exception happens + Logger.warn(methodTag, "Error processing cross cloud redirect and attaching PRT header." + e); + span.recordException(e); + } finally { + span.end(); + } } private String removeQueryParametersOrRedact(@NonNull final String url) { diff --git a/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandler.kt b/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandler.kt index 0cb32b16cf..13e38ec47e 100644 --- a/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandler.kt +++ b/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandler.kt @@ -50,7 +50,8 @@ class CrossCloudChallengeHandler( } // Updates the headers by attaching a refresh token credential header. - private fun modifyHeadersWithRefreshTokenCredential( + // Making it accessible for testing. + fun modifyHeadersWithRefreshTokenCredential( url: String, ) { val methodTag = "$TAG:modifyHeadersWithRefreshTokenCredential" diff --git a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java index cad43e475a..c77a2b6069 100644 --- a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java +++ b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java @@ -30,12 +30,18 @@ import androidx.test.core.app.ApplicationProvider; import com.microsoft.identity.common.adal.internal.AuthenticationConstants; +import com.microsoft.identity.common.internal.ui.webview.challengehandlers.CrossCloudChallengeHandler; +import com.microsoft.identity.common.java.exception.ClientException; +import com.microsoft.identity.common.java.providers.microsoft.azureactivedirectory.AzureActiveDirectory; +import com.microsoft.identity.common.java.providers.microsoft.azureactivedirectory.AzureActiveDirectoryCloud; import com.microsoft.identity.common.java.ui.webview.authorization.IAuthorizationCompletionCallback; import com.microsoft.identity.common.java.providers.RawAuthorizationResult; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; @@ -45,8 +51,12 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static io.mockk.MockKKt.mockkObject; + import java.util.HashMap; +import io.opentelemetry.api.trace.Span; + @RunWith(RobolectricTestRunner.class) public class AzureActiveDirectoryWebViewClientTest { @@ -80,9 +90,11 @@ public class AzureActiveDirectoryWebViewClientTest { private static final String TEST_MSA_HEADER_FORWARDING_NEGATIVE_URL = "https://login.blah.com/oauth20_authorize.srf"; private static final String TEST_NONCE_REDIRECT_URL = "https://login.microsoftonline.com/organizations/oAuth2/v2.0/authorize?&sso_nonce=ABCD"; + private static final String TEST_CROSS_CLOUD_REDIRECT_URL = "https://login.microsoftonline.us/organizations/oAuth2/v2.0/authorize?x=10"; + private static final String TEST_PUBLIC_CLOUD_REDIRECT_URL = "https://login.microsoftonline.com/organizations/oAuth2/v2.0/authorize?x=10"; @Before - public void setup() { + public void setup() throws ClientException { mContext = ApplicationProvider.getApplicationContext(); mMockWebView = new WebView(mContext); mActivity = Robolectric.buildActivity(Activity.class).get(); @@ -109,6 +121,10 @@ public void onPageLoaded(final String url) { HashMap dummyHeaders = new HashMap<>(); dummyHeaders.put("key", "value"); mWebViewClient.setRequestHeaders(dummyHeaders); + mWebViewClient.setRequestUrl(TEST_PUBLIC_CLOUD_REDIRECT_URL); + if (!AzureActiveDirectory.isInitialized()) { + AzureActiveDirectory.performCloudDiscovery(); + } } @Test(expected = IllegalArgumentException.class) @@ -190,4 +206,31 @@ public void testUrlOverrideHandlesHeaderForwardingRequiredUrl() { public void testUrlOverrideHandlesNonceRedirectUrl() { assertTrue(mWebViewClient.shouldOverrideUrlLoading(mMockWebView, TEST_NONCE_REDIRECT_URL)); } + + @Test + public void testUrlOverrideHandlesCrossCloudRedirectUrl() { + assertTrue(mWebViewClient.shouldOverrideUrlLoading(mMockWebView, TEST_CROSS_CLOUD_REDIRECT_URL)); + } + + @Test + public void testProcessCloudRedirectAndPrtHeaderInternalSuccess() { + CrossCloudChallengeHandler mockCrossCloudChallengeHandler = Mockito.mock(CrossCloudChallengeHandler.class); + try { + mWebViewClient.processCloudRedirectAndPrtHeaderInternal(TEST_CROSS_CLOUD_REDIRECT_URL, mockCrossCloudChallengeHandler, "methodTag", Span.current()); + } catch (Exception e) { + Assert.fail("Unexpected exception occured " + e); + } + } + + @Test + public void testProcessCloudRedirectAndPrtHeaderInternalException() { + CrossCloudChallengeHandler mockCrossCloudChallengeHandler = Mockito.mock(CrossCloudChallengeHandler.class); + Mockito.doThrow(new RuntimeException("Test Exception")).when(mockCrossCloudChallengeHandler).processChallenge(TEST_CROSS_CLOUD_REDIRECT_URL); + try { + mWebViewClient.processCloudRedirectAndPrtHeaderInternal(TEST_CROSS_CLOUD_REDIRECT_URL, mockCrossCloudChallengeHandler, "methodTag", Span.current()); + Mockito.verify(mockCrossCloudChallengeHandler, Mockito.times(1)).processChallenge(TEST_CROSS_CLOUD_REDIRECT_URL); + } catch (Exception e) { + Assert.fail("Failure is not expected. We should have caught the exception and ignored it. " + e); + } + } } From 091f832877db0fadedd32ce2bab8fa045ac5e798 Mon Sep 17 00:00:00 2001 From: Sowmya Malayanur Date: Thu, 13 Mar 2025 11:53:44 -0700 Subject: [PATCH 2/6] indentation fix --- .../webview/AzureActiveDirectoryWebViewClient.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java b/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java index 16e203feb0..79d6486b86 100644 --- a/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java +++ b/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java @@ -637,7 +637,7 @@ private void processNonceAndReAttachHeaders(@NonNull final WebView view, @NonNul /** * This method is used to process the cross cloud redirect and attach the PRT header to the request. */ - public void processCloudRedirectAndPrtHeader(@NonNull final WebView view, @NonNull final String url) { + private void processCloudRedirectAndPrtHeader(@NonNull final WebView view, @NonNull final String url) { final String methodTag = TAG + ":processCloudRedirectAndPrtHeader"; final SpanContext spanContext = getActivity() instanceof AuthorizationActivity ? ((AuthorizationActivity) getActivity()).getSpanContext() : null; @@ -653,12 +653,12 @@ public void processCloudRedirectAndPrtHeaderInternal(@NonNull final String url, crossCloudChallengeHandler.processChallenge(url); span.setStatus(StatusCode.OK); } catch (final Exception e) { - // No op if an exception happens - Logger.warn(methodTag, "Error processing cross cloud redirect and attaching PRT header." + e); - span.recordException(e); - } finally { - span.end(); - } + // No op if an exception happens + Logger.warn(methodTag, "Error processing cross cloud redirect and attaching PRT header." + e); + span.recordException(e); + } finally { + span.end(); + } } private String removeQueryParametersOrRedact(@NonNull final String url) { From d81a1419fb145de558c782fdd0dfd0438e7e4a99 Mon Sep 17 00:00:00 2001 From: Sowmya Malayanur Date: Thu, 13 Mar 2025 11:57:14 -0700 Subject: [PATCH 3/6] added cross cloud handler test --- .../CrossCloudChallengeHandlerTest.kt | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt diff --git a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt new file mode 100644 index 0000000000..26f94296fe --- /dev/null +++ b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt @@ -0,0 +1,125 @@ +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.common.internal.ui.webview.challengehandlers + +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import android.webkit.WebView +import com.microsoft.identity.common.java.broker.CommonRefreshTokenCredentialProvider +import com.microsoft.identity.common.java.opentelemetry.AttributeName +import io.mockk.every +import io.mockk.mockkObject +import io.mockk.unmockkAll +import io.opentelemetry.api.trace.Span +import org.junit.Before +import org.junit.Test +import org.mockito.Mockito.* + +@RunWith(RobolectricTestRunner::class) +class CrossCloudChallengeHandlerTest { + + private lateinit var webView: WebView + private lateinit var headers: HashMap + private lateinit var span: Span + private lateinit var crossCloudChallengeHandler: CrossCloudChallengeHandler + + @Before + fun setUp() { + webView = mock(WebView::class.java) + headers = HashMap() + span = mock(Span::class.java) + crossCloudChallengeHandler = CrossCloudChallengeHandler(webView, headers, span) + } + + @Test + fun testProcessChallenge() { + val testUrl = "https://example.com?login_hint=testuser" + crossCloudChallengeHandler.processChallenge(testUrl) + verify(webView).loadUrl(eq(testUrl), eq(headers)) + } + + @Test + fun `testProcessChallenge when exception is thrown`() { + val testUrl = "https://example.com?login_hint=testuser" + + mockkObject(CommonRefreshTokenCredentialProvider) + + // Stubbing method calls + every { + CommonRefreshTokenCredentialProvider.getRefreshTokenCredential( + testUrl, + "testuser" + ) + } throws Exception() + + try { + crossCloudChallengeHandler.processChallenge(testUrl) + } catch (e: Exception) { + verify(webView, never()).loadUrl(eq(testUrl), eq(headers)) + } + } + + @Test + fun `modifyHeadersWithRefreshTokenCredential should update headers when prt is available`() { + val url = "https://login.microsoftonline.com?login_hint=testuser" + val username = "testuser" + val refreshTokenCredential = "refreshTokenCredential" + + mockkObject(CommonRefreshTokenCredentialProvider) + + // Stubbing method calls + every { + CommonRefreshTokenCredentialProvider.getRefreshTokenCredential( + url, + username + ) + } returns refreshTokenCredential + + // Call the method + crossCloudChallengeHandler.modifyHeadersWithRefreshTokenCredential(url) + verify(span).setAttribute( + AttributeName.is_new_refresh_token_cred_header_attached.name, + true + ) + unmockkAll() + } + + @Test + fun `modifyHeadersWithRefreshTokenCredential should not update headers when login_hint is missing`() { + val url = "https://login.microsoftonline.com" + crossCloudChallengeHandler.modifyHeadersWithRefreshTokenCredential(url) + verify(span, never()).setAttribute( + AttributeName.is_new_refresh_token_cred_header_attached.name, + true + ) + } + + @Test + fun `modifyHeadersWithRefreshTokenCredential null refresh token credential`() { + val url = "https://login.microsoftonline.com?login_hint=testuser" + crossCloudChallengeHandler.modifyHeadersWithRefreshTokenCredential(url) + verify(span, never()).setAttribute( + AttributeName.is_new_refresh_token_cred_header_attached.name, + true + ) + } +} \ No newline at end of file From fbd235721f97a8925f1aa348ea0f844d1a84a1fc Mon Sep 17 00:00:00 2001 From: Sowmya Malayanur Date: Thu, 13 Mar 2025 12:00:14 -0700 Subject: [PATCH 4/6] removed unused imports --- .../ui/webview/AzureActiveDirectoryWebViewClientTest.java | 3 --- .../challengehandlers/CrossCloudChallengeHandlerTest.kt | 6 +----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java index c77a2b6069..ccd3c7acff 100644 --- a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java +++ b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java @@ -33,7 +33,6 @@ import com.microsoft.identity.common.internal.ui.webview.challengehandlers.CrossCloudChallengeHandler; import com.microsoft.identity.common.java.exception.ClientException; import com.microsoft.identity.common.java.providers.microsoft.azureactivedirectory.AzureActiveDirectory; -import com.microsoft.identity.common.java.providers.microsoft.azureactivedirectory.AzureActiveDirectoryCloud; import com.microsoft.identity.common.java.ui.webview.authorization.IAuthorizationCompletionCallback; import com.microsoft.identity.common.java.providers.RawAuthorizationResult; @@ -51,8 +50,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static io.mockk.MockKKt.mockkObject; - import java.util.HashMap; import io.opentelemetry.api.trace.Span; diff --git a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt index 26f94296fe..3ff3c45edf 100644 --- a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt +++ b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt @@ -51,7 +51,7 @@ class CrossCloudChallengeHandlerTest { } @Test - fun testProcessChallenge() { + fun `testProcessChallenge success`() { val testUrl = "https://example.com?login_hint=testuser" crossCloudChallengeHandler.processChallenge(testUrl) verify(webView).loadUrl(eq(testUrl), eq(headers)) @@ -62,8 +62,6 @@ class CrossCloudChallengeHandlerTest { val testUrl = "https://example.com?login_hint=testuser" mockkObject(CommonRefreshTokenCredentialProvider) - - // Stubbing method calls every { CommonRefreshTokenCredentialProvider.getRefreshTokenCredential( testUrl, @@ -85,8 +83,6 @@ class CrossCloudChallengeHandlerTest { val refreshTokenCredential = "refreshTokenCredential" mockkObject(CommonRefreshTokenCredentialProvider) - - // Stubbing method calls every { CommonRefreshTokenCredentialProvider.getRefreshTokenCredential( url, From a079babff888c17e54b70b82880729c6a9d86e6c Mon Sep 17 00:00:00 2001 From: Sowmya Malayanur Date: Thu, 13 Mar 2025 12:01:01 -0700 Subject: [PATCH 5/6] added newline --- .../webview/challengehandlers/CrossCloudChallengeHandlerTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt index 3ff3c45edf..56c2891269 100644 --- a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt +++ b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt @@ -118,4 +118,4 @@ class CrossCloudChallengeHandlerTest { true ) } -} \ No newline at end of file +} From 7b2cd3cfa5efc92199b4ec56d4e6b15826863ba8 Mon Sep 17 00:00:00 2001 From: Sowmya Malayanur Date: Mon, 24 Mar 2025 10:48:53 -0700 Subject: [PATCH 6/6] test modified --- .../ui/webview/AzureActiveDirectoryWebViewClient.java | 4 ++-- .../ui/webview/AzureActiveDirectoryWebViewClientTest.java | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java b/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java index 01b14c5fb8..d21b37d84c 100644 --- a/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java +++ b/common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java @@ -645,11 +645,11 @@ private void processCloudRedirectAndPrtHeader(@NonNull final WebView view, @NonN final Span span = spanContext != null ? OTelUtility.createSpanFromParent(SpanName.ProcessCrossCloudRedirect.name(), spanContext) : OTelUtility.createSpan(SpanName.ProcessCrossCloudRedirect.name()); final CrossCloudChallengeHandler crossCloudChallengeHandler = new CrossCloudChallengeHandler(view, mRequestHeaders, span); - processCloudRedirectAndPrtHeaderInternal(url, crossCloudChallengeHandler, methodTag, span); + processCloudRedirectAndPrtHeaderInternal(url, crossCloudChallengeHandler, view, methodTag, span); } @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - public void processCloudRedirectAndPrtHeaderInternal(@NonNull final String url, @NonNull final CrossCloudChallengeHandler crossCloudChallengeHandler, @NonNull final String methodTag, @NonNull final Span span) { + public void processCloudRedirectAndPrtHeaderInternal(@NonNull final String url, @NonNull final CrossCloudChallengeHandler crossCloudChallengeHandler, @NonNull final WebView view, @NonNull final String methodTag, @NonNull final Span span) { try (final Scope scope = SpanExtension.makeCurrentSpan(span)) { crossCloudChallengeHandler.processChallenge(url); span.setStatus(StatusCode.OK); diff --git a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java index 4ebe39de7e..fff4ab35a1 100644 --- a/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java +++ b/common/src/test/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClientTest.java @@ -215,7 +215,7 @@ public void testUrlOverrideHandlesCrossCloudRedirectUrl() { public void testProcessCloudRedirectAndPrtHeaderInternalSuccess() { CrossCloudChallengeHandler mockCrossCloudChallengeHandler = Mockito.mock(CrossCloudChallengeHandler.class); try { - mWebViewClient.processCloudRedirectAndPrtHeaderInternal(TEST_CROSS_CLOUD_REDIRECT_URL, mockCrossCloudChallengeHandler, "methodTag", Span.current()); + mWebViewClient.processCloudRedirectAndPrtHeaderInternal(TEST_CROSS_CLOUD_REDIRECT_URL, mockCrossCloudChallengeHandler, mMockWebView, "methodTag", Span.current()); } catch (Exception e) { Assert.fail("Unexpected exception occured " + e); } @@ -224,10 +224,12 @@ public void testProcessCloudRedirectAndPrtHeaderInternalSuccess() { @Test public void testProcessCloudRedirectAndPrtHeaderInternalException() { CrossCloudChallengeHandler mockCrossCloudChallengeHandler = Mockito.mock(CrossCloudChallengeHandler.class); + WebView mockWebView = Mockito.mock(WebView.class); Mockito.doThrow(new RuntimeException("Test Exception")).when(mockCrossCloudChallengeHandler).processChallenge(TEST_CROSS_CLOUD_REDIRECT_URL); try { - mWebViewClient.processCloudRedirectAndPrtHeaderInternal(TEST_CROSS_CLOUD_REDIRECT_URL, mockCrossCloudChallengeHandler, "methodTag", Span.current()); + mWebViewClient.processCloudRedirectAndPrtHeaderInternal(TEST_CROSS_CLOUD_REDIRECT_URL, mockCrossCloudChallengeHandler, mockWebView, "methodTag", Span.current()); Mockito.verify(mockCrossCloudChallengeHandler, Mockito.times(1)).processChallenge(TEST_CROSS_CLOUD_REDIRECT_URL); + Mockito.verify(mockWebView).loadUrl(Mockito.anyString(), Mockito.any()); } catch (Exception e) { Assert.fail("Failure is not expected. We should have caught the exception and ignored it. " + e); }