Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: harden ClientCapabilityDTO for api v7 [WPB-14882] #3151

Merged
merged 24 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e0e3430
feat: harden ClientCapabilityDTO for api v7
MohamadJaara Dec 6, 2024
177939c
add tests
MohamadJaara Dec 6, 2024
dde0b1e
detekt
MohamadJaara Dec 6, 2024
f1ca8e1
detekt
MohamadJaara Dec 6, 2024
5b8fd62
chore: disable folders update handler (#3161)
Garzas Dec 10, 2024
6a93e45
Merge branch 'release/candidate' into feat/harden-ClientCapabilityDTO…
yamilmedina Dec 11, 2024
1fd8732
fix: Login to second device does not have MLS capabilities RC (#3165)
borichellow Dec 11, 2024
7fd041a
feat: add usecase to get team url (WPB-14872) (#3157) (#3168)
ohassine Dec 11, 2024
c9f091b
chore: upgrade to cc3, fixes new_transaction in paralell (#3170)
yamilmedina Dec 12, 2024
d5d2f0a
Merge branch 'release/candidate' into feat/harden-ClientCapabilityDTO…
yamilmedina Dec 12, 2024
6518915
test: add tests for old format parser in capabilities (#3173)
yamilmedina Dec 13, 2024
33669ca
Merge branch 'release/candidate' into feat/harden-ClientCapabilityDTO…
yamilmedina Dec 13, 2024
11966c7
Update libs.versions.toml
MohamadJaara Dec 16, 2024
f6dfc75
Update UserPropertiesEventReceiver.kt
MohamadJaara Dec 16, 2024
deb21ba
Update UserPropertiesEventReceiver.kt
MohamadJaara Dec 16, 2024
f56f1ce
Update UserPropertiesEventReceiverTest.kt
MohamadJaara Dec 16, 2024
a084dbb
Merge remote-tracking branch 'origin/develop' into feat/harden-Client…
MohamadJaara Jan 7, 2025
40c11bf
fix
MohamadJaara Jan 7, 2025
f53ca10
fix tests
MohamadJaara Jan 7, 2025
6648bdd
missing imports
MohamadJaara Jan 8, 2025
0eae6c3
Merge remote-tracking branch 'origin/develop' into feat/harden-Client…
MohamadJaara Jan 8, 2025
248db9c
fix circular dependency
MohamadJaara Jan 8, 2025
049bbc9
Trigger CI
MohamadJaara Jan 9, 2025
0470f0d
remove not needed dependency
MohamadJaara Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ enum class DeviceType {
Unknown;
}

enum class ClientCapability {
LegalHoldImplicitConsent;
sealed class ClientCapability {
data object LegalHoldImplicitConsent : ClientCapability()
data class Unknown(val name: String) : ClientCapability()
}

data class OtherUserClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ class ClientMapper(

private fun toClientCapabilityDTO(clientCapability: ClientCapability): ClientCapabilityDTO = when (clientCapability) {
ClientCapability.LegalHoldImplicitConsent -> ClientCapabilityDTO.LegalHoldImplicitConsent
is ClientCapability.Unknown -> ClientCapabilityDTO.Unknown(clientCapability.name)
}

private fun fromClientCapabilityDTO(clientCapabilityDTO: ClientCapabilityDTO): ClientCapability = when (clientCapabilityDTO) {
ClientCapabilityDTO.LegalHoldImplicitConsent -> ClientCapability.LegalHoldImplicitConsent
is ClientCapabilityDTO.Unknown -> ClientCapability.Unknown(clientCapabilityDTO.name)
}

fun fromOtherUsersClientsDTO(otherUsersClients: List<ClientEntity>): List<OtherUserClient> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2164,14 +2164,15 @@ class UserSessionScope internal constructor(
kaliumLogger = userScopedLogger,
)

val getTeamUrlUseCase: GetTeamUrlUseCase by lazy {
GetTeamUrlUseCase(
val getTeamUrlUseCase: GetTeamUrlUseCase
get() = GetTeamUrlUseCase(
userId,
authenticationScope.serverConfigRepository,
)
}

private val inCallReactionsRepository: InCallReactionsRepository = InCallReactionsDataSource()
private val inCallReactionsRepository: InCallReactionsRepository by lazy {
InCallReactionsDataSource()
}

/**
* This will start subscribers of observable work per user session, as long as the user is logged in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class UserPropertiesEventReceiverTest {
suspend fun withUpdateConversationFolders() = apply {
coEvery {
conversationFolderRepository.updateConversationFolders(any())
}.returns(Either.Right(Unit))
}.returns(Either.Right(Unit))
}

fun arrange() = this to userPropertiesEventReceiver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.wire.kalium.network.api.authenticated.client.ClientCapabilityDTO
import com.wire.kalium.network.api.authenticated.client.ClientDTO
import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO
import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

object ClientResponseJson {
private val jsonProvider = { serializable: ClientDTO ->
Expand All @@ -36,7 +38,7 @@ object ClientResponseJson {
| "cookie": "${serializable.cookie}",
| "model": "${serializable.model}",
| "capabilities": [
| "${serializable.capabilities[0]}"
| ${Json.encodeToString(serializable.capabilities[0])}
| ],
| "mls_public_keys": ${serializable.mlsPublicKeys}
|}
Expand All @@ -57,9 +59,9 @@ object ClientResponseJson {
| "model": "${serializable.model}",
| "capabilities": {
| "capabilities": [
| "${serializable.capabilities[0]}"
| ${Json.encodeToString(serializable.capabilities[0])}
| ]
| }
| },
| "mls_public_keys": ${serializable.mlsPublicKeys}
|}
""".trimMargin()
Expand Down
1 change: 0 additions & 1 deletion network-model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ kotlin {

// KTX
implementation(libs.ktxDateTime)

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO.Unknown
import com.wire.kalium.network.api.authenticated.prekey.PreKeyDTO
import com.wire.kalium.network.api.model.MLSPublicKey
import com.wire.kalium.network.api.model.UserId
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializable
data class RegisterClientRequest(
Expand Down Expand Up @@ -86,12 +92,33 @@ enum class DeviceTypeDTO {
}
}

@Serializable
enum class ClientCapabilityDTO {
@Serializable(with = ClientCapabilityDTOSerializer::class)
sealed class ClientCapabilityDTO {
@SerialName("legalhold-implicit-consent")
LegalHoldImplicitConsent {
override fun toString(): String {
return "legalhold-implicit-consent"
data object LegalHoldImplicitConsent : ClientCapabilityDTO()
data class Unknown(val name: String) : ClientCapabilityDTO()
}

object ClientCapabilityDTOSerializer : KSerializer<ClientCapabilityDTO> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(
serialName = "ClientCapabilityDTO",
kind = PrimitiveKind.STRING
)

override fun serialize(encoder: Encoder, value: ClientCapabilityDTO) {
when (value) {
is ClientCapabilityDTO.LegalHoldImplicitConsent ->
encoder.encodeString("legalhold-implicit-consent")

is ClientCapabilityDTO.Unknown ->
encoder.encodeString(value.name)
}
}

override fun deserialize(decoder: Decoder): ClientCapabilityDTO {
return when (val value = decoder.decodeString()) {
"legalhold-implicit-consent" -> ClientCapabilityDTO.LegalHoldImplicitConsent
else -> ClientCapabilityDTO.Unknown(value)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.network.api.authenticated.client

import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith


class ClientCapabilityDTOSerializerTest {

private val json = Json { ignoreUnknownKeys = true }

@Test
fun serialize_legal_hold_implicit_consent() {
val capability = ClientCapabilityDTO.LegalHoldImplicitConsent
val result = json.encodeToString(ClientCapabilityDTO.serializer(), capability)
assertEquals("\"legalhold-implicit-consent\"", result)
}

@Test
fun serialize_unknown_capability() {
val capability = ClientCapabilityDTO.Unknown("custom-capability")
val result = json.encodeToString(ClientCapabilityDTO.serializer(), capability)
assertEquals("\"custom-capability\"", result)
}

@Test
fun deserialize_legal_hold_implicit_consent() {
val jsonString = "\"legalhold-implicit-consent\""
val result = json.decodeFromString(ClientCapabilityDTO.serializer(), jsonString)
assertEquals(ClientCapabilityDTO.LegalHoldImplicitConsent, result)
}

@Test
fun deserialize_unknown_capability() {
val jsonString = "\"unknown-capability\""
val result = json.decodeFromString(ClientCapabilityDTO.serializer(), jsonString)
assertEquals(ClientCapabilityDTO.Unknown("unknown-capability"), result)
}

@Test
fun deserialization_fails_on_invalid_json_format() {
val invalidJson = "12345" // Invalid format for a string
assertFailsWith<SerializationException> {
json.decodeFromString(ClientCapabilityDTO.serializer(), invalidJson)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ internal class ClientApiV0Test : ApiTest() {
@Test
fun givenAValidRegisterClientRequest_whenCallingTheRegisterClientEndpointWithOldFormat_theRequestShouldBeConfiguredCorrectly() =
runTest {

val rowJson = VALID_REGISTER_CLIENT_OLD_RESPONSE.rawJson
val data = VALID_REGISTER_CLIENT_OLD_RESPONSE.serializableData

val networkClient = mockAuthenticatedNetworkClient(
VALID_REGISTER_CLIENT_OLD_RESPONSE.rawJson,
rowJson,
statusCode = HttpStatusCode.Created,
assertion = {
assertPost()
Expand All @@ -77,7 +81,7 @@ internal class ClientApiV0Test : ApiTest() {
val clientApi: ClientApi = ClientApiV0(networkClient)
val response = clientApi.registerClient(REGISTER_CLIENT_REQUEST.serializableData)
assertTrue(response.isSuccessful())
assertEquals(VALID_REGISTER_CLIENT_OLD_RESPONSE.serializableData, response.value)
assertEquals(data, response.value)
}

@Test
Expand Down
Loading