-
Notifications
You must be signed in to change notification settings - Fork 50
Added tests for intercepting cross cloud redirect url scenario , Fixes AB#3179147 #2605
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f9a4008
tests for overriding redirect url in cross cloud
somalaya 091f832
indentation fix
somalaya d81a141
added cross cloud handler test
somalaya fbd2357
removed unused imports
somalaya a079bab
added newline
somalaya a5ee03c
Merge branch 'dev' into somalaya/crossCloudChallengeTests
somalaya 7b2cd3c
test modified
somalaya 9a84237
Merge branch 'dev' into somalaya/crossCloudChallengeTests
somalaya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...t/identity/common/internal/ui/webview/challengehandlers/CrossCloudChallengeHandlerTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // 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<String, String> | ||
| 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 success`() { | ||
| 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) | ||
| 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) | ||
| 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 | ||
| ) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you already have test for processChallenge, why add test for modifyHeadersWithRefreshTokenCredential (and make it non private)?
If there's some extra that's getting tested that can be tested on processChallenge itself.