Skip to content

Commit 27b1bc9

Browse files
committed
handling msisdn 401 errors as success within the registration wizard delegate
1 parent 7617309 commit 27b1bc9

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ class OnboardingViewModel @AssistedInject constructor(
305305
RegistrationActionHandler.Result.StartRegistration -> _viewEvents.post(OnboardingViewEvents.DisplayStartRegistration)
306306
RegistrationActionHandler.Result.UnsupportedStage -> _viewEvents.post(OnboardingViewEvents.DisplayRegistrationFallback)
307307
is RegistrationActionHandler.Result.SendEmailSuccess -> _viewEvents.post(OnboardingViewEvents.OnSendEmailSuccess(it.email))
308+
is RegistrationActionHandler.Result.SendMsisdnSuccess -> _viewEvents.post(OnboardingViewEvents.OnSendMsisdnSuccess(it.msisdn.msisdn))
308309
is RegistrationActionHandler.Result.Error -> _viewEvents.post(OnboardingViewEvents.Failure(it.cause))
309310
RegistrationActionHandler.Result.MissingNextStage -> {
310311
_viewEvents.post(OnboardingViewEvents.Failure(IllegalStateException("No next registration stage found")))

vector/src/main/java/im/vector/app/features/onboarding/RegistrationActionHandler.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import im.vector.app.features.onboarding.ftueauth.MatrixOrgRegistrationStagesCom
2626
import kotlinx.coroutines.flow.first
2727
import org.matrix.android.sdk.api.auth.AuthenticationService
2828
import org.matrix.android.sdk.api.auth.registration.FlowResult
29+
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
2930
import org.matrix.android.sdk.api.auth.registration.Stage
3031
import org.matrix.android.sdk.api.session.Session
3132
import javax.inject.Inject
@@ -47,7 +48,8 @@ class RegistrationActionHandler @Inject constructor(
4748
else -> when (result) {
4849
is RegistrationResult.Complete -> Result.RegistrationComplete(result.session)
4950
is RegistrationResult.NextStep -> processFlowResult(result, state)
50-
is RegistrationResult.SendEmailSuccess -> Result.SendEmailSuccess(result.email)
51+
is RegistrationResult.SendEmailSuccess -> Result.SendEmailSuccess(result.email.email)
52+
is RegistrationResult.SendMsisdnSuccess -> Result.SendMsisdnSuccess(result.msisdn)
5153
is RegistrationResult.Error -> Result.Error(result.cause)
5254
}
5355
}
@@ -95,6 +97,7 @@ class RegistrationActionHandler @Inject constructor(
9597
data class NextStage(val stage: Stage) : Result
9698
data class Error(val cause: Throwable) : Result
9799
data class SendEmailSuccess(val email: String) : Result
100+
data class SendMsisdnSuccess(val msisdn: RegisterThreePid.Msisdn) : Result
98101
object MissingNextStage : Result
99102
object StartRegistration : Result
100103
object UnsupportedStage : Result

vector/src/main/java/im/vector/app/features/onboarding/RegistrationWizardActionDelegate.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.matrix.android.sdk.api.auth.registration.RegistrationResult.Success
2424
import org.matrix.android.sdk.api.auth.registration.RegistrationWizard
2525
import org.matrix.android.sdk.api.failure.is401
2626
import org.matrix.android.sdk.api.session.Session
27+
import org.matrix.android.sdk.api.session.identity.ThreePid
2728
import javax.inject.Inject
2829
import org.matrix.android.sdk.api.auth.registration.RegistrationResult as MatrixRegistrationResult
2930

@@ -59,7 +60,8 @@ class RegistrationWizardActionDelegate @Inject constructor(
5960
onSuccess = { it.toRegistrationResult() },
6061
onFailure = {
6162
when {
62-
action.threePid is RegisterThreePid.Email && it.is401() -> RegistrationResult.SendEmailSuccess(action.threePid.email)
63+
action.threePid is RegisterThreePid.Email && it.is401() -> RegistrationResult.SendEmailSuccess(action.threePid)
64+
action.threePid is RegisterThreePid.Msisdn && it.is401() -> RegistrationResult.SendMsisdnSuccess(action.threePid)
6365
else -> RegistrationResult.Error(it)
6466
}
6567
}
@@ -95,7 +97,8 @@ sealed interface RegistrationResult {
9597
data class Error(val cause: Throwable) : RegistrationResult
9698
data class Complete(val session: Session) : RegistrationResult
9799
data class NextStep(val flowResult: FlowResult) : RegistrationResult
98-
data class SendEmailSuccess(val email: String) : RegistrationResult
100+
data class SendEmailSuccess(val email: RegisterThreePid.Email) : RegistrationResult
101+
data class SendMsisdnSuccess(val msisdn: RegisterThreePid.Msisdn) : RegistrationResult
99102
}
100103

101104
sealed interface RegisterAction {

vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthGenericTextInputFormFragment.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,8 @@ class FtueAuthGenericTextInputFormFragment @Inject constructor() : AbstractFtueA
225225
TextInputFormFragmentMode.SetEmail -> {
226226
views.loginGenericTextInputFormTil.error = errorFormatter.toHumanReadable(throwable)
227227
}
228-
TextInputFormFragmentMode.SetMsisdn -> {
229-
if (throwable.is401()) {
230-
// This is normal use case, we go to the enter code screen
231-
viewModel.handle(OnboardingAction.PostViewEvent(OnboardingViewEvents.OnSendMsisdnSuccess(viewModel.currentThreePid ?: "")))
232-
} else {
233-
views.loginGenericTextInputFormTil.error = errorFormatter.toHumanReadable(throwable)
234-
}
228+
TextInputFormFragmentMode.SetMsisdn -> {
229+
views.loginGenericTextInputFormTil.error = errorFormatter.toHumanReadable(throwable)
235230
}
236231
TextInputFormFragmentMode.ConfirmMsisdn -> {
237232
when {

vector/src/test/java/im/vector/app/features/onboarding/RegistrationWizardActionDelegateTest.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ private const val AN_INITIAL_DEVICE_NAME = "a device name"
3838
private const val A_CAPTCHA_RESPONSE = "a captcha response"
3939
private const val A_PID_CODE = "a pid code"
4040
private const val EMAIL_VALIDATED_DELAY = 10000L
41-
private val A_PID_TO_REGISTER = RegisterThreePid.Email("an email")
41+
private val AN_EMAIL_PID_TO_REGISTER = RegisterThreePid.Email("an email")
42+
private val A_PHONE_PID_TO_REGISTER = RegisterThreePid.Msisdn("+11111111111", countryCode = "GB")
4243

4344
class RegistrationWizardActionDelegateTest {
4445

@@ -55,7 +56,7 @@ class RegistrationWizardActionDelegateTest {
5556
case(RegisterAction.CaptchaDone(A_CAPTCHA_RESPONSE)) { performReCaptcha(A_CAPTCHA_RESPONSE) },
5657
case(RegisterAction.AcceptTerms) { acceptTerms() },
5758
case(RegisterAction.RegisterDummy) { dummy() },
58-
case(RegisterAction.AddThreePid(A_PID_TO_REGISTER)) { addThreePid(A_PID_TO_REGISTER) },
59+
case(RegisterAction.AddThreePid(AN_EMAIL_PID_TO_REGISTER)) { addThreePid(AN_EMAIL_PID_TO_REGISTER) },
5960
case(RegisterAction.SendAgainThreePid) { sendAgainThreePid() },
6061
case(RegisterAction.ValidateThreePid(A_PID_CODE)) { handleValidateThreePid(A_PID_CODE) },
6162
case(RegisterAction.CheckIfEmailHasBeenValidated(EMAIL_VALIDATED_DELAY)) { checkIfEmailHasBeenValidated(EMAIL_VALIDATED_DELAY) },
@@ -69,14 +70,14 @@ class RegistrationWizardActionDelegateTest {
6970

7071
@Test
7172
fun `given adding an email ThreePid fails with 401, when handling register action, then infer EmailSuccess`() = runTest {
72-
fakeRegistrationWizard.givenAddEmailThreePidErrors(
73+
fakeRegistrationWizard.givenAddThreePidErrors(
7374
cause = a401ServerError(),
74-
email = A_PID_TO_REGISTER.email
75+
threePid = AN_EMAIL_PID_TO_REGISTER
7576
)
7677

77-
val result = registrationActionHandler.executeAction(RegisterAction.AddThreePid(A_PID_TO_REGISTER))
78+
val result = registrationActionHandler.executeAction(RegisterAction.AddThreePid(AN_EMAIL_PID_TO_REGISTER))
7879

79-
result shouldBeEqualTo RegistrationResult.SendEmailSuccess(A_PID_TO_REGISTER.email)
80+
result shouldBeEqualTo RegistrationResult.SendEmailSuccess(AN_EMAIL_PID_TO_REGISTER)
8081
}
8182

8283
@Test
@@ -110,6 +111,18 @@ class RegistrationWizardActionDelegateTest {
110111
result shouldBeEqualTo RegistrationResult.Complete(A_SESSION)
111112
}
112113

114+
@Test
115+
fun `given adding an Msisdn ThreePid fails with 401, when handling register action, then infer EmailSuccess`() = runTest {
116+
fakeRegistrationWizard.givenAddThreePidErrors(
117+
cause = a401ServerError(),
118+
threePid = A_PHONE_PID_TO_REGISTER
119+
)
120+
121+
val result = registrationActionHandler.executeAction(RegisterAction.AddThreePid(A_PHONE_PID_TO_REGISTER))
122+
123+
result shouldBeEqualTo RegistrationResult.SendMsisdnSuccess(A_PHONE_PID_TO_REGISTER)
124+
}
125+
113126
private suspend fun testSuccessfulActionDelegation(case: Case) {
114127
val fakeRegistrationWizard = FakeRegistrationWizard()
115128
val authenticationService = FakeAuthenticationService().also { it.givenRegistrationWizard(fakeRegistrationWizard) }

vector/src/test/java/im/vector/app/test/fakes/FakeRegistrationWizard.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class FakeRegistrationWizard : RegistrationWizard by mockk(relaxed = false) {
3030
coEvery { expect(this@FakeRegistrationWizard) } returns RegistrationResult.Success(result)
3131
}
3232

33-
fun givenAddEmailThreePidErrors(cause: Throwable, email: String) {
34-
coEvery { addThreePid(RegisterThreePid.Email(email)) } throws cause
33+
fun givenAddThreePidErrors(cause: Throwable, threePid: RegisterThreePid) {
34+
coEvery { addThreePid(threePid) } throws cause
3535
}
3636

3737
fun givenCheckIfEmailHasBeenValidatedErrors(errors: List<Throwable>, finally: RegistrationResult? = null) {

0 commit comments

Comments
 (0)