fix: keep a non-default port in the account name (#105)
This commit is contained in:
@@ -1386,10 +1386,14 @@ class AddAccountViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// The port is part of the name: two servers on one host are two accounts (#105).
|
||||
private fun accountName(): String =
|
||||
username.takeIf { it.isNotBlank() }?.let { "$it@${serverRoot?.host.orEmpty()}" }
|
||||
username.takeIf { it.isNotBlank() }?.let { "$it@${serverRoot?.authority().orEmpty()}" }
|
||||
?: typedInput
|
||||
|
||||
private fun HttpUrl.authority(): String =
|
||||
if (port == HttpUrl.defaultPort(scheme)) host else "$host:$port"
|
||||
|
||||
internal companion object {
|
||||
const val POLL_INTERVAL_MILLIS = 2_000L
|
||||
|
||||
|
||||
+13
-2
@@ -1307,6 +1307,15 @@ class AddAccountViewModelTest {
|
||||
assertThat(vm.state.value.fatal).isEqualTo(AddAccountMessage.ExternalStorage)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a server on its own port is named with it`() = runTest(dispatcher) {
|
||||
val vm = signedIn("https://cloud.example.com:5233/")
|
||||
vm.onSave()
|
||||
advanceUntilIdle()
|
||||
|
||||
assertThat(creator.created).containsExactly("me@cloud.example.com:5233")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a completed add reports the account it created`() = runTest(dispatcher) {
|
||||
val vm = signedIn()
|
||||
@@ -1406,12 +1415,14 @@ class AddAccountViewModelTest {
|
||||
* submit, so going straight from the address to a `Found` leaves the
|
||||
* username and password empty.
|
||||
*/
|
||||
private fun kotlinx.coroutines.test.TestScope.signedIn(): AddAccountViewModel {
|
||||
private fun kotlinx.coroutines.test.TestScope.signedIn(
|
||||
address: String = "https://cloud.example.com/",
|
||||
): AddAccountViewModel {
|
||||
gateway.discoveryOutcomes += CalDavDiscovery.Outcome.NeedsAuthentication(emptyList())
|
||||
gateway.loginFlow = null
|
||||
|
||||
val vm = viewModel()
|
||||
vm.enterAddress("https://cloud.example.com/")
|
||||
vm.enterAddress(address)
|
||||
vm.onAddressSubmitted()
|
||||
advanceUntilIdle()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user