mirror of
https://github.com/bitwarden/android.git
synced 2025-03-16 03:08:50 +03:00
Update the HOST type cipher matching to ignore the port (#3611)
This commit is contained in:
parent
05dc220303
commit
779cd1356a
3 changed files with 10 additions and 22 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.getHostWithPortOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getHostOrNull
|
||||
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.getHostWithPortOrNull()
|
||||
val matchUriHost = matchUri.getHostWithPortOrNull()
|
||||
val loginUriHost = loginViewUri.getHostOrNull()
|
||||
val matchUriHost = matchUri.getHostOrNull()
|
||||
exactIfTrue(matchUriHost != null && loginUriHost == matchUriHost)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,22 +53,10 @@ fun String.getDomainOrNull(context: Context): String? =
|
|||
?.parseDomainOrNull(context = context)
|
||||
|
||||
/**
|
||||
* Extract the host with port from this [String] if possible, otherwise return null.
|
||||
* Extract the host from this [String] if possible, otherwise return null.
|
||||
*/
|
||||
@OmitFromCoverage
|
||||
fun String.getHostWithPortOrNull(): String? =
|
||||
this
|
||||
.toUriOrNull()
|
||||
?.let { uri ->
|
||||
val host = uri.host
|
||||
val port = uri.port
|
||||
|
||||
if (host != null && port != -1) {
|
||||
"$host:$port"
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
fun String.getHostOrNull(): String? = this.toUriOrNull()?.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.getHostWithPortOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.getHostOrNull
|
||||
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 { getHostWithPortOrNull() } returns HOST_WITH_PORT
|
||||
every { getHostOrNull() } returns HOST
|
||||
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.getHostWithPortOrNull() } returns HOST_WITH_PORT
|
||||
every { HOST_LOGIN_VIEW_URI_NOT_MATCHING.getHostWithPortOrNull() } returns null
|
||||
every { HOST_LOGIN_VIEW_URI_MATCHING.getHostOrNull() } returns HOST
|
||||
every { HOST_LOGIN_VIEW_URI_NOT_MATCHING.getHostOrNull() } 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_WITH_PORT: String = "HOST_WITH_PORT"
|
||||
private const val HOST: String = "HOST"
|
||||
|
|
Loading…
Add table
Reference in a new issue