Skip to content

Commit fd73360

Browse files
authored
[PM-21405] Delete account error message (#5237)
1 parent 1786252 commit fd73360

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

app/src/test/java/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,37 @@ class AuthRepositoryTest {
794794
}
795795
}
796796

797+
@Test
798+
fun `delete account fails if deleteAccount fails with message`() = runTest {
799+
val masterPassword = "hello world"
800+
val hashedMasterPassword = "dlrow olleh"
801+
fakeAuthDiskSource.userState = SINGLE_USER_STATE_1
802+
val kdf = SINGLE_USER_STATE_1.activeAccount.profile.toSdkParams()
803+
coEvery {
804+
authSdkSource.hashPassword(EMAIL, masterPassword, kdf, HashPurpose.SERVER_AUTHORIZATION)
805+
} returns hashedMasterPassword.asSuccess()
806+
coEvery {
807+
accountsService.deleteAccount(
808+
masterPasswordHash = hashedMasterPassword,
809+
oneTimePassword = null,
810+
)
811+
} returns DeleteAccountResponseJson.Invalid(
812+
errorMessage = "Fail",
813+
validationErrors = null,
814+
).asSuccess()
815+
816+
val result = repository.deleteAccountWithMasterPassword(masterPassword = masterPassword)
817+
818+
assertEquals(DeleteAccountResult.Error(message = "Fail", error = null), result)
819+
coVerify {
820+
authSdkSource.hashPassword(EMAIL, masterPassword, kdf, HashPurpose.SERVER_AUTHORIZATION)
821+
accountsService.deleteAccount(
822+
masterPasswordHash = hashedMasterPassword,
823+
oneTimePassword = null,
824+
)
825+
}
826+
}
827+
797828
@Test
798829
fun `deleteAccountWithMasterPassword succeeds`() = runTest {
799830
val masterPassword = "hello world"

network/src/main/kotlin/com/bitwarden/network/model/DeleteAccountResponseJson.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ sealed class DeleteAccountResponseJson {
1616
/**
1717
* Models the json body of a deletion error.
1818
*
19+
* @param errorMessage a human readable error message.
1920
* @param validationErrors a map where each value is a list of error messages for each key.
2021
* The values in the array should be used for display to the user, since the keys tend to come
2122
* back as nonsense. (eg: empty string key)
2223
*/
2324
@Serializable
2425
data class Invalid(
26+
@SerialName("message")
27+
private val errorMessage: String?,
28+
2529
@SerialName("validationErrors")
2630
private val validationErrors: Map<String, List<String?>>?,
2731
) : DeleteAccountResponseJson() {
@@ -33,5 +37,6 @@ sealed class DeleteAccountResponseJson {
3337
?.values
3438
?.firstOrNull()
3539
?.firstOrNull()
40+
?: errorMessage
3641
}
3742
}

0 commit comments

Comments
 (0)