Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into PM-18067/view-item-fa…
Browse files Browse the repository at this point in the history
…vicon
  • Loading branch information
SaintPatrck committed Feb 24, 2025
2 parents 9496bc2 + 00eb78f commit e44738f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.x8bit.bitwarden.data.auth.datasource.network.model

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonNames
import kotlinx.serialization.json.JsonObject

/**
Expand Down Expand Up @@ -92,20 +94,21 @@ sealed class GetTokenResponseJson {

/**
* Models json body of an invalid request.
*
* This model supports older versions of the error response model that used lower-case keys.
*/
@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class Invalid(
@JsonNames("errorModel")
@SerialName("ErrorModel")
val errorModel: ErrorModel?,
@SerialName("errorModel")
val legacyErrorModel: LegacyErrorModel?,
private val errorModel: ErrorModel?,
) : GetTokenResponseJson() {

/**
* The error message returned from the server, or null.
*/
val errorMessage: String?
get() = errorModel?.errorMessage ?: legacyErrorModel?.errorMessage
val errorMessage: String? get() = errorModel?.errorMessage

/**
* The type of invalid responses that can be received.
Expand All @@ -131,24 +134,16 @@ sealed class GetTokenResponseJson {

/**
* The error body of an invalid request containing a message.
*
* This model supports older versions of the error response model that used lower-case
* keys.
*/
@Serializable
data class ErrorModel(
@JsonNames("message")
@SerialName("Message")
val errorMessage: String,
)

/**
* The legacy error body of an invalid request containing a message.
*
* This model is used to support older versions of the error response model that used
* lower-case keys.
*/
@Serializable
data class LegacyErrorModel(
@SerialName("message")
val errorMessage: String,
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.x8bit.bitwarden.data.auth.datasource.network.model

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonNames

/**
* Models response bodies for the register request.
Expand Down Expand Up @@ -50,20 +52,24 @@ sealed class RegisterResponseJson {
* The values in the array should be used for display to the user, since the keys tend to come
* back as nonsense. (eg: empty string key)
*/
@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class Invalid(
@SerialName("message")
private val invalidMessage: String? = null,

@JsonNames("message")
@SerialName("Message")
private val errorMessage: String? = null,
private val invalidMessage: String? = null,

@SerialName("validationErrors")
val validationErrors: Map<String, List<String>>?,
private val validationErrors: Map<String, List<String>>?,
) : RegisterResponseJson() {
/**
* A generic error message.
*/
val message: String? get() = invalidMessage ?: errorMessage
val message: String?
get() = validationErrors
?.values
?.firstOrNull()
?.firstOrNull()
?: invalidMessage
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -910,14 +910,7 @@ class AuthRepositoryImpl(
}

is RegisterResponseJson.Invalid -> {
RegisterResult.Error(
errorMessage = it
.validationErrors
?.values
?.firstOrNull()
?.firstOrNull()
?: it.message,
)
RegisterResult.Error(errorMessage = it.message)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class IdentityServiceTest : BaseServiceTest() {
val result = identityService.register(registerRequestBody)
assertEquals(
RegisterResponseJson.Invalid(
errorMessage = "Slow down! Too many requests. Try again soon.",
invalidMessage = "Slow down! Too many requests. Try again soon.",
validationErrors = null,
),
result.getOrThrow(),
Expand Down Expand Up @@ -287,7 +287,7 @@ class IdentityServiceTest : BaseServiceTest() {
captchaToken = null,
uniqueAppId = UNIQUE_APP_ID,
)
assertEquals(LEGACY_INVALID_LOGIN.asSuccess(), result)
assertEquals(INVALID_LOGIN.asSuccess(), result)
}

@Suppress("MaxLineLength")
Expand Down Expand Up @@ -363,7 +363,7 @@ class IdentityServiceTest : BaseServiceTest() {
val result = identityService.registerFinish(registerFinishRequestBody)
assertEquals(
RegisterResponseJson.Invalid(
errorMessage = "Slow down! Too many requests. Try again soon.",
invalidMessage = "Slow down! Too many requests. Try again soon.",
validationErrors = null,
),
result.getOrThrow(),
Expand Down Expand Up @@ -651,7 +651,7 @@ private const val INVALID_LOGIN_JSON = """
private const val LEGACY_INVALID_LOGIN_JSON = """
{
"errorModel": {
"message": "Legacy-123"
"message": "123"
}
}
"""
Expand Down Expand Up @@ -688,14 +688,6 @@ private val INVALID_LOGIN = GetTokenResponseJson.Invalid(
errorModel = GetTokenResponseJson.Invalid.ErrorModel(
errorMessage = "123",
),
legacyErrorModel = null,
)

private val LEGACY_INVALID_LOGIN = GetTokenResponseJson.Invalid(
errorModel = null,
legacyErrorModel = GetTokenResponseJson.Invalid.LegacyErrorModel(
errorMessage = "Legacy-123",
),
)

private val SEND_VERIFICATION_EMAIL_REQUEST = SendVerificationEmailRequestJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,6 @@ class AuthRepositoryTest {
errorModel = GetTokenResponseJson.Invalid.ErrorModel(
errorMessage = "mock_error_message",
),
legacyErrorModel = null,
)
.asSuccess()

Expand Down Expand Up @@ -1617,7 +1616,6 @@ class AuthRepositoryTest {
errorModel = GetTokenResponseJson.Invalid.ErrorModel(
errorMessage = "new device verification required",
),
legacyErrorModel = null,
)
.asSuccess()

Expand Down Expand Up @@ -2401,7 +2399,6 @@ class AuthRepositoryTest {
errorModel = GetTokenResponseJson.Invalid.ErrorModel(
errorMessage = "mock_error_message",
),
legacyErrorModel = null,
)
.asSuccess()

Expand Down Expand Up @@ -2870,7 +2867,6 @@ class AuthRepositoryTest {
errorModel = GetTokenResponseJson.Invalid.ErrorModel(
errorMessage = "mock_error_message",
),
legacyErrorModel = null,
)
.asSuccess()

Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ hilt = "2.55"
junit5 = "5.11.3"
jvmTarget = "17"
# kotlin and ksp **must** use compatible versions, do not update either without the other.
kotlin = "2.1.0"
kotlin = "2.1.10"
kotlinxCollectionsImmutable = "0.3.8"
kotlinxCoroutines = "1.10.1"
kotlinxSerialization = "1.8.0"
kotlinxKover = "0.9.1"
ksp = "2.1.0-1.0.29"
ksp = "2.1.10-1.0.30"
mockk = "1.13.13"
okhttp = "4.12.0"
retrofitBom = "2.11.0"
Expand Down Expand Up @@ -97,7 +97,7 @@ google-firebase-crashlytics = { module = "com.google.firebase:firebase-crashlyti
google-hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
google-hilt-android-testing = { module = "com.google.dagger:hilt-android-testing", version.ref = "hilt" }
google-hilt-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
google-play-review = { module = "com.google.android.play:review", version.ref = "googleReview"}
google-play-review = { module = "com.google.android.play:review", version.ref = "googleReview" }
junit-junit5 = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit5" }
junit-vintage = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit5" }
kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlinxCollectionsImmutable" }
Expand Down

0 comments on commit e44738f

Please sign in to comment.