mirror of
https://github.com/bitwarden/android.git
synced 2025-03-16 03:08:50 +03:00
PM-9135: Update host matching to include optional port value (#3623)
This commit is contained in:
parent
544eabfaa3
commit
a6bbde2bed
3 changed files with 20 additions and 10 deletions
|
@ -7,7 +7,7 @@ import com.bitwarden.vault.UriMatchType
|
|||
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
||||
import com.x8bit.bitwarden.data.platform.util.firstWithTimeoutOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getDomainOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getHostOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getHostWithPortOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getWebHostFromAndroidUriOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.isAndroidApp
|
||||
import com.x8bit.bitwarden.data.platform.util.regexOrNull
|
||||
|
@ -210,8 +210,8 @@ private fun LoginUriView.checkForMatch(
|
|||
UriMatchType.EXACT -> exactIfTrue(loginViewUri == matchUri)
|
||||
|
||||
UriMatchType.HOST -> {
|
||||
val loginUriHost = loginViewUri.getHostOrNull()
|
||||
val matchUriHost = matchUri.getHostOrNull()
|
||||
val loginUriHost = loginViewUri.getHostWithPortOrNull()
|
||||
val matchUriHost = matchUri.getHostWithPortOrNull()
|
||||
exactIfTrue(matchUriHost != null && loginUriHost == matchUriHost)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,10 +53,20 @@ fun String.getDomainOrNull(context: Context): String? =
|
|||
?.parseDomainOrNull(context = context)
|
||||
|
||||
/**
|
||||
* Extract the host from this [String] if possible, otherwise return null.
|
||||
* Extract the host with optional port from this [String] if possible, otherwise return null.
|
||||
*/
|
||||
@OmitFromCoverage
|
||||
fun String.getHostOrNull(): String? = this.toUriOrNull()?.host
|
||||
fun String.getHostWithPortOrNull(): String? {
|
||||
val uri = this.toUriOrNull() ?: return null
|
||||
return uri.host?.let { host ->
|
||||
val port = uri.port
|
||||
if (port != -1) {
|
||||
"$host:$port"
|
||||
} else {
|
||||
host
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the indices of the last occurrences of [substring] within this [String]. Return null if no
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.bitwarden.vault.UriMatchType
|
|||
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
import com.x8bit.bitwarden.data.platform.util.getDomainOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getHostOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getHostWithPortOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getWebHostFromAndroidUriOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.isAndroidApp
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
|
@ -357,7 +357,7 @@ class CipherMatchingManagerTest {
|
|||
with(uri) {
|
||||
every { isAndroidApp() } returns isAndroidApp
|
||||
every { getDomainOrNull(context = context) } returns this.takeIf { isAndroidApp }
|
||||
every { getHostOrNull() } returns HOST
|
||||
every { getHostWithPortOrNull() } returns HOST_WITH_PORT
|
||||
every {
|
||||
getWebHostFromAndroidUriOrNull()
|
||||
} returns ANDROID_APP_WEB_URL.takeIf { isAndroidApp }
|
||||
|
@ -378,8 +378,8 @@ class CipherMatchingManagerTest {
|
|||
DEFAULT_LOGIN_VIEW_URI_FIVE.getDomainOrNull(context = context)
|
||||
} returns null
|
||||
|
||||
every { HOST_LOGIN_VIEW_URI_MATCHING.getHostOrNull() } returns HOST
|
||||
every { HOST_LOGIN_VIEW_URI_NOT_MATCHING.getHostOrNull() } returns null
|
||||
every { HOST_LOGIN_VIEW_URI_MATCHING.getHostWithPortOrNull() } returns HOST_WITH_PORT
|
||||
every { HOST_LOGIN_VIEW_URI_NOT_MATCHING.getHostWithPortOrNull() } returns null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,4 +415,4 @@ private const val DEFAULT_LOGIN_VIEW_URI_FIVE: String = "DEFAULT_LOGIN_VIEW_URI_
|
|||
// Setup state for host ciphers
|
||||
private const val HOST_LOGIN_VIEW_URI_MATCHING: String = "DEFAULT_LOGIN_VIEW_URI_MATCHING"
|
||||
private const val HOST_LOGIN_VIEW_URI_NOT_MATCHING: String = "DEFAULT_LOGIN_VIEW_URI_NOT_MATCHING"
|
||||
private const val HOST: String = "HOST"
|
||||
private const val HOST_WITH_PORT: String = "HOST_WITH_PORT"
|
||||
|
|
Loading…
Add table
Reference in a new issue