mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 08:35:05 -06:00
PM-22776: Update logic for determining base domains (#5374)
This commit is contained in:
parent
6c41c358ac
commit
292a28d155
@ -3,7 +3,7 @@ package com.x8bit.bitwarden.data.platform.manager.provider
|
|||||||
import com.bitwarden.data.repository.model.Environment
|
import com.bitwarden.data.repository.model.Environment
|
||||||
import com.x8bit.bitwarden.data.platform.datasource.disk.FakeEnvironmentDiskSource
|
import com.x8bit.bitwarden.data.platform.datasource.disk.FakeEnvironmentDiskSource
|
||||||
import com.x8bit.bitwarden.data.platform.provider.BaseUrlsProviderImpl
|
import com.x8bit.bitwarden.data.platform.provider.BaseUrlsProviderImpl
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class BaseUrlsProviderTest {
|
class BaseUrlsProviderTest {
|
||||||
@ -16,8 +16,8 @@ class BaseUrlsProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `getBaseApiUrl should return correct api URL when preAuthEnvironmentUrlData is set`() {
|
fun `getBaseApiUrl should return correct api URL when preAuthEnvironmentUrlData is set`() {
|
||||||
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = Environment.Eu.environmentUrlData
|
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = Environment.Eu.environmentUrlData
|
||||||
Assertions.assertEquals(
|
assertEquals(
|
||||||
"https://vault.bitwarden.eu/api",
|
"https://api.bitwarden.eu",
|
||||||
baseUrlsManager.getBaseApiUrl(),
|
baseUrlsManager.getBaseApiUrl(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -25,8 +25,8 @@ class BaseUrlsProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `getBaseApiUrl should return default value when preAuthEnvironmentUrlData is null`() {
|
fun `getBaseApiUrl should return default value when preAuthEnvironmentUrlData is null`() {
|
||||||
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = null
|
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = null
|
||||||
Assertions.assertEquals(
|
assertEquals(
|
||||||
"https://vault.bitwarden.com/api",
|
"https://api.bitwarden.com",
|
||||||
baseUrlsManager.getBaseApiUrl(),
|
baseUrlsManager.getBaseApiUrl(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -34,8 +34,8 @@ class BaseUrlsProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `getBaseIdentityUrl should return correct api URL when preAuthEnvironmentUrlData is set`() {
|
fun `getBaseIdentityUrl should return correct api URL when preAuthEnvironmentUrlData is set`() {
|
||||||
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = Environment.Eu.environmentUrlData
|
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = Environment.Eu.environmentUrlData
|
||||||
Assertions.assertEquals(
|
assertEquals(
|
||||||
"https://vault.bitwarden.eu/identity",
|
"https://identity.bitwarden.eu",
|
||||||
baseUrlsManager.getBaseIdentityUrl(),
|
baseUrlsManager.getBaseIdentityUrl(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -43,8 +43,8 @@ class BaseUrlsProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `getBaseIdentityUrl should return default value when preAuthEnvironmentUrlData is null`() {
|
fun `getBaseIdentityUrl should return default value when preAuthEnvironmentUrlData is null`() {
|
||||||
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = null
|
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = null
|
||||||
Assertions.assertEquals(
|
assertEquals(
|
||||||
"https://vault.bitwarden.com/identity",
|
"https://identity.bitwarden.com",
|
||||||
baseUrlsManager.getBaseIdentityUrl(),
|
baseUrlsManager.getBaseIdentityUrl(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -52,8 +52,8 @@ class BaseUrlsProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `getBaseEventsUrl should return correct api URL when preAuthEnvironmentUrlData is set`() {
|
fun `getBaseEventsUrl should return correct api URL when preAuthEnvironmentUrlData is set`() {
|
||||||
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = Environment.Eu.environmentUrlData
|
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = Environment.Eu.environmentUrlData
|
||||||
Assertions.assertEquals(
|
assertEquals(
|
||||||
"https://vault.bitwarden.eu/events",
|
"https://events.bitwarden.eu",
|
||||||
baseUrlsManager.getBaseEventsUrl(),
|
baseUrlsManager.getBaseEventsUrl(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -61,8 +61,8 @@ class BaseUrlsProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `getBaseEventsUrl should return default value when preAuthEnvironmentUrlData is null`() {
|
fun `getBaseEventsUrl should return default value when preAuthEnvironmentUrlData is null`() {
|
||||||
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = null
|
fakeEnvironmentDiskSource.preAuthEnvironmentUrlData = null
|
||||||
Assertions.assertEquals(
|
assertEquals(
|
||||||
"https://vault.bitwarden.com/events",
|
"https://events.bitwarden.com",
|
||||||
baseUrlsManager.getBaseEventsUrl(),
|
baseUrlsManager.getBaseEventsUrl(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1159,7 +1159,7 @@ class SearchViewModelTest : BaseViewModelTest() {
|
|||||||
every {
|
every {
|
||||||
ciphers.toViewState(
|
ciphers.toViewState(
|
||||||
searchTerm = "",
|
searchTerm = "",
|
||||||
baseIconUrl = "https://vault.bitwarden.com/icons",
|
baseIconUrl = "https://icons.bitwarden.net",
|
||||||
isIconLoadingDisabled = false,
|
isIconLoadingDisabled = false,
|
||||||
isAutofill = false,
|
isAutofill = false,
|
||||||
hasMasterPassword = true,
|
hasMasterPassword = true,
|
||||||
@ -1261,7 +1261,7 @@ class SearchViewModelTest : BaseViewModelTest() {
|
|||||||
every {
|
every {
|
||||||
ciphers.toViewState(
|
ciphers.toViewState(
|
||||||
searchTerm = "",
|
searchTerm = "",
|
||||||
baseIconUrl = "https://vault.bitwarden.com/icons",
|
baseIconUrl = "https://icons.bitwarden.net",
|
||||||
isIconLoadingDisabled = false,
|
isIconLoadingDisabled = false,
|
||||||
isAutofill = false,
|
isAutofill = false,
|
||||||
hasMasterPassword = true,
|
hasMasterPassword = true,
|
||||||
@ -1373,7 +1373,7 @@ class SearchViewModelTest : BaseViewModelTest() {
|
|||||||
every {
|
every {
|
||||||
ciphers.toViewState(
|
ciphers.toViewState(
|
||||||
searchTerm = "",
|
searchTerm = "",
|
||||||
baseIconUrl = "https://vault.bitwarden.com/icons",
|
baseIconUrl = "https://icons.bitwarden.net",
|
||||||
isIconLoadingDisabled = false,
|
isIconLoadingDisabled = false,
|
||||||
isAutofill = false,
|
isAutofill = false,
|
||||||
hasMasterPassword = true,
|
hasMasterPassword = true,
|
||||||
@ -1488,7 +1488,7 @@ class SearchViewModelTest : BaseViewModelTest() {
|
|||||||
every {
|
every {
|
||||||
ciphers.toViewState(
|
ciphers.toViewState(
|
||||||
searchTerm = "",
|
searchTerm = "",
|
||||||
baseIconUrl = "https://vault.bitwarden.com/icons",
|
baseIconUrl = "https://icons.bitwarden.net",
|
||||||
isIconLoadingDisabled = false,
|
isIconLoadingDisabled = false,
|
||||||
isAutofill = false,
|
isAutofill = false,
|
||||||
hasMasterPassword = true,
|
hasMasterPassword = true,
|
||||||
@ -1663,7 +1663,7 @@ class SearchViewModelTest : BaseViewModelTest() {
|
|||||||
every {
|
every {
|
||||||
ciphers.toViewState(
|
ciphers.toViewState(
|
||||||
searchTerm = "",
|
searchTerm = "",
|
||||||
baseIconUrl = "https://vault.bitwarden.com/icons",
|
baseIconUrl = "https://icons.bitwarden.net",
|
||||||
isIconLoadingDisabled = false,
|
isIconLoadingDisabled = false,
|
||||||
isAutofill = true,
|
isAutofill = true,
|
||||||
hasMasterPassword = true,
|
hasMasterPassword = true,
|
||||||
@ -1697,7 +1697,7 @@ private val DEFAULT_STATE: SearchState = SearchState(
|
|||||||
dialogState = null,
|
dialogState = null,
|
||||||
vaultFilterData = null,
|
vaultFilterData = null,
|
||||||
baseWebSendUrl = "https://send.bitwarden.com/#",
|
baseWebSendUrl = "https://send.bitwarden.com/#",
|
||||||
baseIconUrl = "https://vault.bitwarden.com/icons",
|
baseIconUrl = "https://icons.bitwarden.net",
|
||||||
isIconLoadingDisabled = false,
|
isIconLoadingDisabled = false,
|
||||||
hasMasterPassword = true,
|
hasMasterPassword = true,
|
||||||
totpData = null,
|
totpData = null,
|
||||||
|
|||||||
@ -1848,7 +1848,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
|||||||
secondSubtitleTestTag = "PasskeySite",
|
secondSubtitleTestTag = "PasskeySite",
|
||||||
subtitleTestTag = "PasskeyName",
|
subtitleTestTag = "PasskeyName",
|
||||||
iconData = IconData.Network(
|
iconData = IconData.Network(
|
||||||
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
|
uri = "https://icons.bitwarden.net/www.mockuri.com/icon.png",
|
||||||
fallbackIconRes = R.drawable.ic_bw_passkey,
|
fallbackIconRes = R.drawable.ic_bw_passkey,
|
||||||
),
|
),
|
||||||
isAutofill = true,
|
isAutofill = true,
|
||||||
@ -1980,7 +1980,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
|||||||
secondSubtitleTestTag = "PasskeySite",
|
secondSubtitleTestTag = "PasskeySite",
|
||||||
subtitleTestTag = "PasskeyName",
|
subtitleTestTag = "PasskeyName",
|
||||||
iconData = IconData.Network(
|
iconData = IconData.Network(
|
||||||
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
|
uri = "https://icons.bitwarden.net/www.mockuri.com/icon.png",
|
||||||
fallbackIconRes = R.drawable.ic_bw_passkey,
|
fallbackIconRes = R.drawable.ic_bw_passkey,
|
||||||
),
|
),
|
||||||
isCredentialCreation = true,
|
isCredentialCreation = true,
|
||||||
|
|||||||
@ -578,7 +578,7 @@ class VaultItemListingDataExtensionsTest {
|
|||||||
secondSubtitleTestTag = "PasskeySite",
|
secondSubtitleTestTag = "PasskeySite",
|
||||||
subtitleTestTag = "PasskeyName",
|
subtitleTestTag = "PasskeyName",
|
||||||
iconData = IconData.Network(
|
iconData = IconData.Network(
|
||||||
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
|
uri = "https://icons.bitwarden.net/www.mockuri.com/icon.png",
|
||||||
fallbackIconRes = R.drawable.ic_bw_passkey,
|
fallbackIconRes = R.drawable.ic_bw_passkey,
|
||||||
),
|
),
|
||||||
isAutofill = true,
|
isAutofill = true,
|
||||||
@ -665,7 +665,7 @@ class VaultItemListingDataExtensionsTest {
|
|||||||
secondSubtitleTestTag = "PasskeySite",
|
secondSubtitleTestTag = "PasskeySite",
|
||||||
subtitleTestTag = "PasskeyName",
|
subtitleTestTag = "PasskeyName",
|
||||||
iconData = IconData.Network(
|
iconData = IconData.Network(
|
||||||
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
|
uri = "https://icons.bitwarden.net/www.mockuri.com/icon.png",
|
||||||
fallbackIconRes = R.drawable.ic_bw_passkey,
|
fallbackIconRes = R.drawable.ic_bw_passkey,
|
||||||
),
|
),
|
||||||
isAutofill = true,
|
isAutofill = true,
|
||||||
|
|||||||
@ -30,7 +30,7 @@ fun createMockDisplayItemForCipher(
|
|||||||
subtitle = subtitle,
|
subtitle = subtitle,
|
||||||
subtitleTestTag = "CipherSubTitleLabel",
|
subtitleTestTag = "CipherSubTitleLabel",
|
||||||
iconData = IconData.Network(
|
iconData = IconData.Network(
|
||||||
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
|
uri = "https://icons.bitwarden.net/www.mockuri.com/icon.png",
|
||||||
fallbackIconRes = R.drawable.ic_globe,
|
fallbackIconRes = R.drawable.ic_globe,
|
||||||
),
|
),
|
||||||
extraIconList = persistentListOf(
|
extraIconList = persistentListOf(
|
||||||
|
|||||||
@ -562,7 +562,7 @@ class VaultDataExtensionsTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val expected = IconData.Network(
|
val expected = IconData.Network(
|
||||||
uri = "https://vault.bitwarden.com/icons/www.mockuri1.com/icon.png",
|
uri = "https://icons.bitwarden.net/www.mockuri1.com/icon.png",
|
||||||
fallbackIconRes = R.drawable.ic_globe,
|
fallbackIconRes = R.drawable.ic_globe,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -593,7 +593,7 @@ class VaultDataExtensionsTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val expected = IconData.Network(
|
val expected = IconData.Network(
|
||||||
uri = "https://vault.bitwarden.com/icons/www.mockuri1.com/icon.png",
|
uri = "https://icons.bitwarden.net/www.mockuri1.com/icon.png",
|
||||||
fallbackIconRes = R.drawable.ic_bw_passkey,
|
fallbackIconRes = R.drawable.ic_bw_passkey,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -767,7 +767,7 @@ class VaultDataExtensionsTest {
|
|||||||
id = "mockId-1",
|
id = "mockId-1",
|
||||||
name = mockCipher.name.asText(),
|
name = mockCipher.name.asText(),
|
||||||
startIcon = IconData.Network(
|
startIcon = IconData.Network(
|
||||||
uri = "https://vault.bitwarden.com/icons/www.mockuri1.com/icon.png",
|
uri = "https://icons.bitwarden.net/www.mockuri1.com/icon.png",
|
||||||
fallbackIconRes = R.drawable.ic_globe,
|
fallbackIconRes = R.drawable.ic_globe,
|
||||||
),
|
),
|
||||||
startIconTestTag = "LoginCipherIcon",
|
startIconTestTag = "LoginCipherIcon",
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.bitwarden.data.datasource.disk.model
|
package com.bitwarden.data.datasource.disk.model
|
||||||
|
|
||||||
|
import com.bitwarden.data.repository.model.EnvironmentRegion
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -41,6 +42,16 @@ data class EnvironmentUrlDataJson(
|
|||||||
@SerialName("events")
|
@SerialName("events")
|
||||||
val events: String? = null,
|
val events: String? = null,
|
||||||
) {
|
) {
|
||||||
|
/**
|
||||||
|
* Returns the [EnvironmentRegion] based on the base domain for the US or EU environments.
|
||||||
|
*/
|
||||||
|
val environmentRegion: EnvironmentRegion
|
||||||
|
get() = when (base) {
|
||||||
|
DEFAULT_US.base -> EnvironmentRegion.UNITED_STATES
|
||||||
|
DEFAULT_EU.base -> EnvironmentRegion.EUROPEAN_UNION
|
||||||
|
else -> EnvironmentRegion.SELF_HOSTED
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("UndocumentedPublicClass")
|
@Suppress("UndocumentedPublicClass")
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.bitwarden.data.repository.model
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of the environment regions used within the app.
|
||||||
|
*/
|
||||||
|
enum class EnvironmentRegion {
|
||||||
|
UNITED_STATES,
|
||||||
|
EUROPEAN_UNION,
|
||||||
|
SELF_HOSTED,
|
||||||
|
}
|
||||||
@ -2,38 +2,62 @@ package com.bitwarden.data.repository.util
|
|||||||
|
|
||||||
import com.bitwarden.data.datasource.disk.model.EnvironmentUrlDataJson
|
import com.bitwarden.data.datasource.disk.model.EnvironmentUrlDataJson
|
||||||
import com.bitwarden.data.repository.model.Environment
|
import com.bitwarden.data.repository.model.Environment
|
||||||
|
import com.bitwarden.data.repository.model.EnvironmentRegion
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
private const val DEFAULT_API_URL: String = "https://api.bitwarden.com"
|
private const val DEFAULT_US_API_URL: String = "https://api.bitwarden.com"
|
||||||
private const val DEFAULT_EVENTS_URL: String = "https://events.bitwarden.com"
|
private const val DEFAULT_EU_API_URL: String = "https://api.bitwarden.eu"
|
||||||
private const val DEFAULT_IDENTITY_URL: String = "https://identity.bitwarden.com"
|
private const val DEFAULT_US_EVENTS_URL: String = "https://events.bitwarden.com"
|
||||||
private const val DEFAULT_WEB_VAULT_URL: String = "https://vault.bitwarden.com"
|
private const val DEFAULT_EU_EVENTS_URL: String = "https://events.bitwarden.eu"
|
||||||
private const val DEFAULT_WEB_SEND_URL: String = "https://send.bitwarden.com/#"
|
private const val DEFAULT_US_IDENTITY_URL: String = "https://identity.bitwarden.com"
|
||||||
private const val DEFAULT_ICON_URL: String = "https://icons.bitwarden.net"
|
private const val DEFAULT_EU_IDENTITY_URL: String = "https://identity.bitwarden.eu"
|
||||||
|
private const val DEFAULT_US_WEB_VAULT_URL: String = "https://vault.bitwarden.com"
|
||||||
|
private const val DEFAULT_EU_WEB_VAULT_URL: String = "https://vault.bitwarden.eu"
|
||||||
|
private const val DEFAULT_US_WEB_SEND_URL: String = "https://send.bitwarden.com/#"
|
||||||
|
private const val DEFAULT_US_ICON_URL: String = "https://icons.bitwarden.net"
|
||||||
|
private const val DEFAULT_EU_ICON_URL: String = "https://icons.bitwarden.eu"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the base api URL or the default value if one is not present.
|
* Returns the base api URL or the default value if one is not present.
|
||||||
*/
|
*/
|
||||||
val EnvironmentUrlDataJson.baseApiUrl: String
|
val EnvironmentUrlDataJson.baseApiUrl: String
|
||||||
get() = this.base.sanitizeUrl?.let { "$it/api" }
|
get() = when (this.environmentRegion) {
|
||||||
?: this.api.sanitizeUrl
|
EnvironmentRegion.UNITED_STATES -> DEFAULT_US_API_URL
|
||||||
?: DEFAULT_API_URL
|
EnvironmentRegion.EUROPEAN_UNION -> DEFAULT_EU_API_URL
|
||||||
|
EnvironmentRegion.SELF_HOSTED -> {
|
||||||
|
this.api.sanitizeUrl
|
||||||
|
?: this.base.sanitizeUrl?.let { "$it/api" }
|
||||||
|
?: DEFAULT_US_API_URL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the base events URL or the default value if one is not present.
|
* Returns the base events URL or the default value if one is not present.
|
||||||
*/
|
*/
|
||||||
val EnvironmentUrlDataJson.baseEventsUrl: String
|
val EnvironmentUrlDataJson.baseEventsUrl: String
|
||||||
get() = this.base.sanitizeUrl?.let { "$it/events" }
|
get() = when (this.environmentRegion) {
|
||||||
?: this.events.sanitizeUrl
|
EnvironmentRegion.UNITED_STATES -> DEFAULT_US_EVENTS_URL
|
||||||
?: DEFAULT_EVENTS_URL
|
EnvironmentRegion.EUROPEAN_UNION -> DEFAULT_EU_EVENTS_URL
|
||||||
|
EnvironmentRegion.SELF_HOSTED -> {
|
||||||
|
this.events.sanitizeUrl
|
||||||
|
?: this.base.sanitizeUrl?.let { "$it/events" }
|
||||||
|
?: DEFAULT_US_EVENTS_URL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the base identity URL or the default value if one is not present.
|
* Returns the base identity URL or the default value if one is not present.
|
||||||
*/
|
*/
|
||||||
val EnvironmentUrlDataJson.baseIdentityUrl: String
|
val EnvironmentUrlDataJson.baseIdentityUrl: String
|
||||||
get() = this.identity.sanitizeUrl
|
get() = when (this.environmentRegion) {
|
||||||
?: this.base.sanitizeUrl?.let { "$it/identity" }
|
EnvironmentRegion.UNITED_STATES -> DEFAULT_US_IDENTITY_URL
|
||||||
?: DEFAULT_IDENTITY_URL
|
EnvironmentRegion.EUROPEAN_UNION -> DEFAULT_EU_IDENTITY_URL
|
||||||
|
EnvironmentRegion.SELF_HOSTED -> {
|
||||||
|
this.identity.sanitizeUrl
|
||||||
|
?: this.base.sanitizeUrl?.let { "$it/identity" }
|
||||||
|
?: DEFAULT_US_IDENTITY_URL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the base web vault URL. This will check for a custom [EnvironmentUrlDataJson.webVault]
|
* Returns the base web vault URL. This will check for a custom [EnvironmentUrlDataJson.webVault]
|
||||||
@ -41,8 +65,11 @@ val EnvironmentUrlDataJson.baseIdentityUrl: String
|
|||||||
* null or blank.
|
* null or blank.
|
||||||
*/
|
*/
|
||||||
val EnvironmentUrlDataJson.baseWebVaultUrlOrNull: String?
|
val EnvironmentUrlDataJson.baseWebVaultUrlOrNull: String?
|
||||||
get() = this.webVault.sanitizeUrl
|
get() = when (this.environmentRegion) {
|
||||||
?: this.base.sanitizeUrl
|
EnvironmentRegion.UNITED_STATES -> DEFAULT_US_WEB_VAULT_URL
|
||||||
|
EnvironmentRegion.EUROPEAN_UNION -> DEFAULT_EU_WEB_VAULT_URL
|
||||||
|
EnvironmentRegion.SELF_HOSTED -> this.webVault.sanitizeUrl ?: this.base.sanitizeUrl
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the base web vault URL or the default value if one is not present.
|
* Returns the base web vault URL or the default value if one is not present.
|
||||||
@ -50,25 +77,18 @@ val EnvironmentUrlDataJson.baseWebVaultUrlOrNull: String?
|
|||||||
* See [baseWebVaultUrlOrNull] for more details.
|
* See [baseWebVaultUrlOrNull] for more details.
|
||||||
*/
|
*/
|
||||||
val EnvironmentUrlDataJson.baseWebVaultUrlOrDefault: String
|
val EnvironmentUrlDataJson.baseWebVaultUrlOrDefault: String
|
||||||
get() = this.baseWebVaultUrlOrNull ?: DEFAULT_WEB_VAULT_URL
|
get() = this.baseWebVaultUrlOrNull ?: DEFAULT_US_WEB_VAULT_URL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the base web send URL or the default value if one is not present.
|
* Returns the base web send URL or the default value if one is not present.
|
||||||
*/
|
*/
|
||||||
val EnvironmentUrlDataJson.baseWebSendUrl: String
|
val EnvironmentUrlDataJson.baseWebSendUrl: String
|
||||||
get() =
|
get() = when (this.environmentRegion) {
|
||||||
this
|
EnvironmentRegion.UNITED_STATES -> DEFAULT_US_WEB_SEND_URL
|
||||||
.baseWebVaultUrlOrNull
|
EnvironmentRegion.EUROPEAN_UNION,
|
||||||
?.let {
|
EnvironmentRegion.SELF_HOSTED,
|
||||||
// Only on US Cloud we should use the default web send URL
|
-> this.baseWebVaultUrlOrNull?.let { "$it/#/send/" } ?: DEFAULT_US_WEB_SEND_URL
|
||||||
// On all other server instances we should use the base web send URL
|
}
|
||||||
if (it == DEFAULT_WEB_VAULT_URL) {
|
|
||||||
DEFAULT_WEB_SEND_URL
|
|
||||||
} else {
|
|
||||||
"$it/#/send/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?: DEFAULT_WEB_SEND_URL
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the base web vault import URL or the default value if one is not present.
|
* Returns the base web vault import URL or the default value if one is not present.
|
||||||
@ -83,9 +103,15 @@ val EnvironmentUrlDataJson.toBaseWebVaultImportUrl: String
|
|||||||
* Returns a base icon url based on the environment or the default value if values are missing.
|
* Returns a base icon url based on the environment or the default value if values are missing.
|
||||||
*/
|
*/
|
||||||
val EnvironmentUrlDataJson.baseIconUrl: String
|
val EnvironmentUrlDataJson.baseIconUrl: String
|
||||||
get() = this.icon.sanitizeUrl
|
get() = when (this.environmentRegion) {
|
||||||
?: this.base.sanitizeUrl?.let { "$it/icons" }
|
EnvironmentRegion.UNITED_STATES -> DEFAULT_US_ICON_URL
|
||||||
?: DEFAULT_ICON_URL
|
EnvironmentRegion.EUROPEAN_UNION -> DEFAULT_EU_ICON_URL
|
||||||
|
EnvironmentRegion.SELF_HOSTED -> {
|
||||||
|
this.icon.sanitizeUrl
|
||||||
|
?: this.base.sanitizeUrl?.let { "$it/icons" }
|
||||||
|
?: DEFAULT_US_ICON_URL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the appropriate pre-defined labels for environments matching the known US/EU values.
|
* Returns the appropriate pre-defined labels for environments matching the known US/EU values.
|
||||||
|
|||||||
@ -8,18 +8,18 @@ import org.junit.jupiter.api.Test
|
|||||||
|
|
||||||
class EnvironmentUrlsDataJsonExtensionsTest {
|
class EnvironmentUrlsDataJsonExtensionsTest {
|
||||||
@Test
|
@Test
|
||||||
fun `baseApiUrl should return base if it is present`() {
|
fun `baseApiUrl should return api if it is present`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"base/api",
|
"api",
|
||||||
DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA.baseApiUrl,
|
DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA.baseApiUrl,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `baseApiUrl should return api value if base is empty`() {
|
fun `baseApiUrl should return base value if api is empty`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"api",
|
"base/api",
|
||||||
DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA.copy(base = "").baseApiUrl,
|
DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA.copy(api = "").baseApiUrl,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,18 +32,18 @@ class EnvironmentUrlsDataJsonExtensionsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `baseEventsUrl should return base if it is present`() {
|
fun `baseEventsUrl should return events if it is present`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"base/events",
|
"events",
|
||||||
DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA.baseEventsUrl,
|
DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA.baseEventsUrl,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `baseEventsUrl should return events value if base is empty`() {
|
fun `baseEventsUrl should return base value if events is empty`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"events",
|
"base/events",
|
||||||
DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA.copy(base = "").baseEventsUrl,
|
DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA.copy(events = "").baseEventsUrl,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,14 +165,14 @@ class EnvironmentUrlsDataJsonExtensionsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `baseWebSendUrl should return the default when webvault matches default webvault`() {
|
fun `baseWebSendUrl should return the modified webvault when not in the US`() {
|
||||||
val result = DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA
|
val result = DEFAULT_CUSTOM_ENVIRONMENT_URL_DATA
|
||||||
.copy(
|
.copy(
|
||||||
webVault = "https://vault.bitwarden.com",
|
webVault = "https://vault.bitwarden.com",
|
||||||
base = "",
|
base = "",
|
||||||
)
|
)
|
||||||
.baseWebSendUrl
|
.baseWebSendUrl
|
||||||
assertEquals("https://send.bitwarden.com/#", result)
|
assertEquals("https://vault.bitwarden.com/#/send/", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user