Skip to content

Commit

Permalink
Merge branch 'develop' into fix/passingState-when-getting-team-member…
Browse files Browse the repository at this point in the history
…s-cherry-pick
  • Loading branch information
vitorhugods authored Mar 5, 2024
2 parents d0be2c6 + 00706fc commit f07b7c2
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,14 @@ class CallManagerImpl internal constructor(
conversationId: ConversationId,
clients: String
) {
withCalling {
wcall_set_clients_for_conv(
it,
federatedIdMapper.parseToFederatedId(conversationId),
clients
)
if (callRepository.getCallMetadataProfile()[conversationId]?.protocol is Conversation.ProtocolInfo.Proteus) {
withCalling {
wcall_set_clients_for_conv(
it,
federatedIdMapper.parseToFederatedId(conversationId),
clients
)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions monkeys/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@
"type": "integer",
"default": 10
},
"disable2FA": {
"description": "Force disable 2FA",
"type": "boolean",
"default": false
},
"2FAEnabled": {
"description": "Does this server require 2FA authentication?",
"type": "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fun CoroutineScope.stopIM() {
class MonkeyApplication : CliktCommand(allowMultipleSubcommands = true) {
private val dataFilePath by argument(help = "path to the test data file")
private val skipWarmup by option("-s", "--skip-warmup", help = "Should the warmup be skipped?").flag()
private val sequentialWarmup by option("-w", "--sequential-warmup", help = "Should the warmup happen sequentially?").flag()
private val logLevel by option("-l", "--log-level", help = "log level").enum<KaliumLogLevel>().default(KaliumLogLevel.INFO)
private val logOutputFile by option("-f", "--log-file", help = "output file for logs")
private val monkeysLogOutputFile by option("-m", "--monkeys-log-file", help = "output file for monkey logs")
Expand Down Expand Up @@ -156,7 +157,7 @@ class MonkeyApplication : CliktCommand(allowMultipleSubcommands = true) {
if (index == 0) {
if (!this.skipWarmup) {
logger.i("Creating initial key packages for clients (logging everyone in and out). This can take a while...")
monkeyPool.warmUp(coreLogic)
monkeyPool.warmUp(coreLogic, sequentialWarmup)
}
logger.i("Creating prefixed groups")
testData.conversationDistribution.forEach { (prefix, config) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ data class BackendConfig(
@SerialName("authPassword") val authPassword: String,
@SerialName("userCount") val userCount: ULong = 10u,
@SerialName("2FAEnabled") val secondFactorAuth: Boolean = false,
@SerialName("disable2FA") val forceDisable2fa: Boolean = false,
@SerialName("dumpUsers") val dumpUsers: Boolean = false,
@SerialName("presetTeam") val presetTeam: TeamConfig? = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ object TestDataImporter {
)
backendConfig.presetTeam.users.map { user ->
UserData(
user.email,
backendConfig.passwordForUsers,
UserId(user.unqualifiedId, backendConfig.domain),
team,
null
user.email, backendConfig.passwordForUsers, UserId(user.unqualifiedId, backendConfig.domain), team, null
)
}
} else {
Expand Down Expand Up @@ -155,6 +151,16 @@ private suspend fun HttpClient.createTeam(backendConfig: BackendConfig): Team {
).toJsonObject()
)
}
if (backendConfig.forceDisable2fa) {
put("i/teams/$teamId/features/sndFactorPasswordChallenge/unlocked")
put("i/teams/$teamId/features/sndFactorPasswordChallenge") {
setBody(
mapOf(
"status" to "disabled", "ttl" to "unlimited"
).toJsonObject()
)
}
}

val backend = Backend.fromConfig(backendConfig)
val userId = user["id"]?.jsonPrimitive?.content ?: error("Could not register user")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,19 @@ data class Backend(
) {
companion object {
fun fromConfig(config: BackendConfig): Backend = with(config) {
Backend(api, accounts, webSocket, blackList, teams, website, title, domain, secondFactorAuth, authUser, authPassword)
Backend(
api,
accounts,
webSocket,
blackList,
teams,
website,
title,
domain,
!forceDisable2fa && secondFactorAuth,
authUser,
authPassword
)
}
}
}
21 changes: 16 additions & 5 deletions monkeys/src/main/kotlin/com/wire/kalium/monkeys/pool/MonkeyPool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,24 @@ class MonkeyPool(users: List<UserData>, testCase: String, config: MonkeyConfig)
}.awaitAll()
}

suspend fun warmUp(core: CoreLogic) = coroutineScope {
@Suppress("TooGenericExceptionCaught")
suspend fun warmUp(core: CoreLogic, sequentialWarmup: Boolean) = coroutineScope {
// this is needed to create key packages for clients at least once
poolById.values.map {
async {
it.warmUp(core)
if (sequentialWarmup) {
poolById.values.forEach {
try {
it.warmUp(core)
} catch (e: Exception) {
logger.w("Error warming up monkey ${it.monkeyType.userId()}", e)
}
}
}.awaitAll()
} else {
poolById.values.map {
async {
it.warmUp(core)
}
}.awaitAll()
}
}

fun randomMonkeysFromTeam(team: String, userCount: UserCount): List<Monkey> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.wire.kalium.network.api.base.model.ConversationId
import com.wire.kalium.network.api.base.model.GenerateGuestLinkRequest
import com.wire.kalium.network.api.base.model.JoinConversationRequestV4
import com.wire.kalium.network.api.v3.authenticated.ConversationApiV3
import com.wire.kalium.network.exceptions.KaliumException
import com.wire.kalium.network.utils.NetworkResponse
import com.wire.kalium.network.utils.handleUnsuccessfulResponse
import com.wire.kalium.network.utils.mapSuccess
Expand All @@ -43,7 +42,6 @@ import io.ktor.client.request.parameter
import io.ktor.client.request.post
import io.ktor.client.request.preparePost
import io.ktor.client.request.setBody
import io.ktor.utils.io.errors.IOException

internal open class ConversationApiV4 internal constructor(
authenticatedNetworkClient: AuthenticatedNetworkClient,
Expand Down Expand Up @@ -88,15 +86,16 @@ internal open class ConversationApiV4 internal constructor(
override suspend fun addMember(
addParticipantRequest: AddConversationMembersRequest,
conversationId: ConversationId
): NetworkResponse<ConversationMemberAddedResponse> = try {
httpClient.post("$PATH_CONVERSATIONS/${conversationId.domain}/${conversationId.value}/$PATH_MEMBERS") {
setBody(addParticipantRequest)
}.let { response ->
wrapFederationResponse(response) { handleConversationMemberAddedResponse(response) }
): NetworkResponse<ConversationMemberAddedResponse> = wrapKaliumResponse(
performRequest = {
httpClient.post("$PATH_CONVERSATIONS/${conversationId.domain}/${conversationId.value}/$PATH_MEMBERS") {
setBody(addParticipantRequest)
}
},
unsuccessfulResponseOverride = {
wrapFederationResponse(it) { handleConversationMemberAddedResponse(it) }
}
} catch (e: IOException) {
NetworkResponse.Error(KaliumException.GenericError(e))
}
)

override suspend fun generateGuestRoomLink(
conversationId: ConversationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ import com.wire.kalium.network.api.base.model.FederationConflictResponse
import com.wire.kalium.network.api.base.model.FederationUnreachableResponse
import com.wire.kalium.network.exceptions.KaliumException
import com.wire.kalium.network.kaliumLogger
import com.wire.kalium.network.tools.KtxSerializer
import io.ktor.client.call.NoTransformationFoundException
import io.ktor.client.call.body
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpStatusCode
import io.ktor.http.URLProtocol
import io.ktor.http.Url
import io.ktor.http.isSuccess
import io.ktor.serialization.JsonConvertException
import kotlinx.serialization.SerializationException

internal fun HttpRequestBuilder.setWSSUrl(baseUrl: Url, vararg path: String) {
url {
Expand Down Expand Up @@ -282,17 +284,21 @@ suspend fun <T : Any> wrapFederationResponse(
* i.e.: '/commit-bundles' 409 for "mls-stale-message" and 409 for "federation-conflict"
*/
private suspend fun resolveStatusCodeBasedFirstOrFederated(response: HttpResponse): NetworkResponse.Error {
val responseString = response.bodyAsText()

val kaliumException = try {
val errorResponse = response.body<ErrorResponse>()
val errorResponse = KtxSerializer.json.decodeFromString<ErrorResponse>(responseString)

toStatusCodeBasedKaliumException(
response.status,
response,
errorResponse
)
} catch (exception: JsonConvertException) {
} catch (exception: SerializationException) {
try {
KaliumException.FederationConflictException(response.body<FederationConflictResponse>())
} catch (_: NoTransformationFoundException) {
val federationConflictResponse = KtxSerializer.json.decodeFromString<FederationConflictResponse>(responseString)
KaliumException.FederationConflictException(federationConflictResponse)
} catch (_: SerializationException) {
KaliumException.FederationConflictException(FederationConflictResponse(emptyList()))
}
}
Expand Down

0 comments on commit f07b7c2

Please sign in to comment.