BIT-2305: Update default environment URLs to match legacy data (#1329)

This commit is contained in:
David Perez 2024-05-02 09:26:49 -05:00 committed by Álison Fernandes
parent 862c7f110c
commit 859b4c247d
5 changed files with 53 additions and 5 deletions

View file

@ -25,7 +25,7 @@ data class EnvironmentUrlDataJson(
@SerialName("identity")
val identity: String? = null,
@SerialName("icon")
@SerialName("icons")
val icon: String? = null,
@SerialName("notifications")
@ -44,10 +44,38 @@ data class EnvironmentUrlDataJson(
val DEFAULT_US: EnvironmentUrlDataJson =
EnvironmentUrlDataJson(base = "https://vault.bitwarden.com")
/**
* Default [EnvironmentUrlDataJson] for the US region as written to disk by the legacy
* Xamarin app.
*/
val DEFAULT_LEGACY_US: EnvironmentUrlDataJson = EnvironmentUrlDataJson(
base = "https://vault.bitwarden.com",
api = "https://api.bitwarden.com",
identity = "https://identity.bitwarden.com",
icon = "https://icons.bitwarden.net",
notifications = "https://notifications.bitwarden.com",
webVault = "https://vault.bitwarden.com",
events = "https://events.bitwarden.com",
)
/**
* Default [EnvironmentUrlDataJson] for the EU region.
*/
val DEFAULT_EU: EnvironmentUrlDataJson =
EnvironmentUrlDataJson(base = "https://vault.bitwarden.eu")
/**
* Default [EnvironmentUrlDataJson] for the EU region as written to disk by the legacy
* Xamarin app.
*/
val DEFAULT_LEGACY_EU: EnvironmentUrlDataJson = EnvironmentUrlDataJson(
base = "https://vault.bitwarden.eu",
api = "https://api.bitwarden.eu",
identity = "https://identity.bitwarden.eu",
icon = "https://icons.bitwarden.eu",
notifications = "https://notifications.bitwarden.eu",
webVault = "https://vault.bitwarden.eu",
events = "https://events.bitwarden.eu",
)
}
}

View file

@ -111,8 +111,10 @@ private fun EnvironmentUrlDataJson.getSelfHostedUrlOrNull(): String? =
*/
fun EnvironmentUrlDataJson.toEnvironmentUrls(): Environment =
when (this) {
Environment.Us.environmentUrlData -> Environment.Us
Environment.Eu.environmentUrlData -> Environment.Eu
EnvironmentUrlDataJson.DEFAULT_US -> Environment.Us
EnvironmentUrlDataJson.DEFAULT_LEGACY_US -> Environment.Us
EnvironmentUrlDataJson.DEFAULT_EU -> Environment.Eu
EnvironmentUrlDataJson.DEFAULT_LEGACY_EU -> Environment.Eu
else -> Environment.SelfHosted(environmentUrlData = this)
}

View file

@ -1086,7 +1086,7 @@ private const val USER_STATE_JSON = """
"base": "base",
"api": "api",
"identity": "identity",
"icon": "icon",
"icons": "icon",
"notifications": "notifications",
"webVault": "webVault",
"events": "events"

View file

@ -69,7 +69,7 @@ private const val ENVIRONMENT_URL_DATA_JSON = """
"base": "base",
"api": "api",
"identity": "identity",
"icon": "icon",
"icons": "icon",
"notifications": "notifications",
"webVault": "webVault",
"events": "events"

View file

@ -178,6 +178,15 @@ class EnvironmentUrlsDataJsonExtensionsTest {
)
}
@Suppress("MaxLineLength")
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert legacy US urls to the expected type`() {
assertEquals(
Environment.Us,
EnvironmentUrlDataJson.DEFAULT_LEGACY_US.toEnvironmentUrlsOrDefault(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert EU urls to the expected type`() {
assertEquals(
@ -186,6 +195,15 @@ class EnvironmentUrlsDataJsonExtensionsTest {
)
}
@Suppress("MaxLineLength")
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert legacy EU urls to the expected type`() {
assertEquals(
Environment.Eu,
EnvironmentUrlDataJson.DEFAULT_LEGACY_EU.toEnvironmentUrlsOrDefault(),
)
}
@Test
fun `toEnvironmentUrlsOrDefault should correctly convert custom urls to the expected type`() {
assertEquals(