mirror of
https://github.com/bitwarden/android.git
synced 2026-03-09 11:44:41 -05:00
Update generated SSO uri to be typed (#6329)
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Parcelable
|
||||
import androidx.browser.auth.AuthTabIntent
|
||||
import androidx.core.net.toUri
|
||||
import com.bitwarden.annotation.OmitFromCoverage
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import java.net.URLEncoder
|
||||
@@ -28,7 +29,7 @@ fun generateUriForSso(
|
||||
token: String,
|
||||
state: String,
|
||||
codeVerifier: String,
|
||||
): String {
|
||||
): Uri {
|
||||
val redirectUri = URLEncoder.encode(SSO_URI, "UTF-8")
|
||||
val encodedOrganizationIdentifier = URLEncoder.encode(organizationIdentifier, "UTF-8")
|
||||
val encodedToken = URLEncoder.encode(token, "UTF-8")
|
||||
@@ -39,7 +40,7 @@ fun generateUriForSso(
|
||||
.digest(codeVerifier.toByteArray()),
|
||||
)
|
||||
|
||||
return "$identityBaseUrl/connect/authorize" +
|
||||
val uri = "$identityBaseUrl/connect/authorize" +
|
||||
"?client_id=mobile" +
|
||||
"&redirect_uri=$redirectUri" +
|
||||
"&response_type=code" +
|
||||
@@ -50,6 +51,7 @@ fun generateUriForSso(
|
||||
"&response_mode=query" +
|
||||
"&domain_hint=$encodedOrganizationIdentifier" +
|
||||
"&ssoToken=$encodedToken"
|
||||
return uri.toUri()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.x8bit.bitwarden.ui.auth.feature.enterprisesignon
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Parcelable
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.bitwarden.data.repository.util.baseIdentityUrl
|
||||
@@ -408,7 +407,7 @@ class EnterpriseSignOnViewModel @Inject constructor(
|
||||
// a result due to user intervention
|
||||
sendAction(
|
||||
EnterpriseSignOnAction.Internal.OnGenerateUriForSsoResult(
|
||||
uri = uri.toUri(),
|
||||
uri = uri,
|
||||
scheme = "bitwarden",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.x8bit.bitwarden.data.auth.repository.util
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import org.junit.Test
|
||||
@@ -16,6 +17,17 @@ class SsoUtilsTest {
|
||||
val token = "Test Token"
|
||||
val state = "test_state"
|
||||
val codeVerifier = "test_code_verifier"
|
||||
val expectedUrl = "https://identity.bitwarden.com/connect/authorize" +
|
||||
"?client_id=mobile" +
|
||||
"&redirect_uri=bitwarden%3A%2F%2Fsso-callback" +
|
||||
"&response_type=code" +
|
||||
"&scope=api%20offline_access" +
|
||||
"&state=test_state" +
|
||||
"&code_challenge=Qq1fGD0HhxwbmeMrqaebgn1qhvKeguQPXqLdpmixaM4" +
|
||||
"&code_challenge_method=S256" +
|
||||
"&response_mode=query" +
|
||||
"&domain_hint=Test+Organization" +
|
||||
"&ssoToken=Test+Token"
|
||||
|
||||
val uri = generateUriForSso(
|
||||
identityBaseUrl = identityBaseUrl,
|
||||
@@ -24,20 +36,8 @@ class SsoUtilsTest {
|
||||
state = state,
|
||||
codeVerifier = codeVerifier,
|
||||
)
|
||||
assertEquals(
|
||||
"https://identity.bitwarden.com/connect/authorize" +
|
||||
"?client_id=mobile" +
|
||||
"&redirect_uri=bitwarden%3A%2F%2Fsso-callback" +
|
||||
"&response_type=code" +
|
||||
"&scope=api%20offline_access" +
|
||||
"&state=test_state" +
|
||||
"&code_challenge=Qq1fGD0HhxwbmeMrqaebgn1qhvKeguQPXqLdpmixaM4" +
|
||||
"&code_challenge_method=S256" +
|
||||
"&response_mode=query" +
|
||||
"&domain_hint=Test+Organization" +
|
||||
"&ssoToken=Test+Token",
|
||||
uri,
|
||||
)
|
||||
|
||||
assertEquals(Uri.parse(expectedUrl), uri)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -57,7 +57,6 @@ class EnterpriseSignOnViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
setupMockUri()
|
||||
mockkStatic(
|
||||
SavedStateHandle::toEnterpriseSignOnArgs,
|
||||
::generateUriForSso,
|
||||
@@ -69,7 +68,6 @@ class EnterpriseSignOnViewModelTest : BaseViewModelTest() {
|
||||
unmockkStatic(
|
||||
SavedStateHandle::toEnterpriseSignOnArgs,
|
||||
::generateUriForSso,
|
||||
Uri::parse,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -166,9 +164,6 @@ class EnterpriseSignOnViewModelTest : BaseViewModelTest() {
|
||||
val ssoUri: Uri = mockk()
|
||||
every {
|
||||
generateUriForSso(any(), any(), any(), any(), any())
|
||||
} returns "https://identity.bitwarden.com/sso-test"
|
||||
every {
|
||||
Uri.parse("https://identity.bitwarden.com/sso-test")
|
||||
} returns ssoUri
|
||||
|
||||
val viewModel = createViewModel(state)
|
||||
@@ -1267,23 +1262,14 @@ class EnterpriseSignOnViewModelTest : BaseViewModelTest() {
|
||||
it.trySendAction(EnterpriseSignOnAction.DialogDismiss)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupMockUri() {
|
||||
mockkStatic(Uri::class)
|
||||
val uriMock = mockk<Uri>()
|
||||
every { Uri.parse(any()) } returns uriMock
|
||||
every { uriMock.host } returns "www.bitwarden.com"
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val DEFAULT_STATE = EnterpriseSignOnState(
|
||||
dialogState = null,
|
||||
orgIdentifierInput = "",
|
||||
)
|
||||
private val DEFAULT_SSO_DATA = SsoResponseData(
|
||||
state = "abc",
|
||||
codeVerifier = "def",
|
||||
)
|
||||
private const val DEFAULT_EMAIL = "test@gmail.com"
|
||||
}
|
||||
}
|
||||
|
||||
private val DEFAULT_STATE = EnterpriseSignOnState(
|
||||
dialogState = null,
|
||||
orgIdentifierInput = "",
|
||||
)
|
||||
private val DEFAULT_SSO_DATA = SsoResponseData(
|
||||
state = "abc",
|
||||
codeVerifier = "def",
|
||||
)
|
||||
private const val DEFAULT_EMAIL = "test@gmail.com"
|
||||
|
||||
Reference in New Issue
Block a user