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: handle legal hold failure result when sending connection [WPB-4395] #2419

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -26,6 +26,8 @@ import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.functional.flatMap
import com.wire.kalium.logic.functional.fold
import com.wire.kalium.logic.kaliumLogger
import com.wire.kalium.network.exceptions.KaliumException
import com.wire.kalium.network.exceptions.isMissingLegalHoldConsent

/**
* Use Case that allows a user send a connection request to connect with another User
Expand Down Expand Up @@ -53,13 +55,26 @@ internal class SendConnectionRequestUseCaseImpl(
when (coreFailure) {
is NetworkFailure.FederatedBackendFailure.FederationDenied ->
SendConnectionRequestResult.Failure.FederationDenied

is NetworkFailure.ServerMiscommunication -> handleServerMissCommunicationError(coreFailure)
else -> SendConnectionRequestResult.Failure.GenericFailure(coreFailure)
}
}, {
SendConnectionRequestResult.Success
})
}

private fun handleServerMissCommunicationError(failure: NetworkFailure.ServerMiscommunication): SendConnectionRequestResult.Failure =
when (failure.kaliumException) {
is KaliumException.InvalidRequestError -> {
with(failure.kaliumException) {
when {
isMissingLegalHoldConsent() -> SendConnectionRequestResult.Failure.MissingLegalHoldConsent
else -> SendConnectionRequestResult.Failure.GenericFailure(failure)
}
}
}
else -> SendConnectionRequestResult.Failure.GenericFailure(failure)
}
}

sealed class SendConnectionRequestResult {
Expand All @@ -68,6 +83,7 @@ sealed class SendConnectionRequestResult {
sealed class Failure : SendConnectionRequestResult() {
class GenericFailure(val coreFailure: CoreFailure) : Failure()
data object FederationDenied : Failure()
data object MissingLegalHoldConsent : Failure()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import com.wire.kalium.logic.data.connection.ConnectionRepository
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.network.api.base.model.ErrorResponse
import com.wire.kalium.network.exceptions.KaliumException
import io.mockative.Mock
import io.mockative.any
import io.mockative.classOf
Expand Down Expand Up @@ -123,6 +125,30 @@ class SendConnectionRequestUseCaseTest {
.wasInvoked(once)
}

@Test
fun givenAConnectionRequest_whenInvokingAndFailsByMissingLegalHoldConsent_thenShouldReturnsAMissingLegalHoldConsent() = runTest {
// given
val (arrangement, sendConnectionRequestUseCase) = Arrangement()
.withFetchUserInfoResult(Either.Right(Unit))
.withCreateConnectionResult(
Either.Left(
NetworkFailure.ServerMiscommunication(
KaliumException.InvalidRequestError(ErrorResponse(403, "", "missing-legalhold-consent"))
)
)
)
.arrange()
// when
val resultFailure = sendConnectionRequestUseCase(userId)

// then
assertEquals(SendConnectionRequestResult.Failure.MissingLegalHoldConsent::class, resultFailure::class)
verify(arrangement.connectionRepository)
.suspendFunction(arrangement.connectionRepository::sendUserConnection)
.with(eq(userId))
.wasInvoked(once)
}

private class Arrangement {
@Mock
val connectionRepository = mock(classOf<ConnectionRepository>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.wire.kalium.network.exceptions.NetworkErrorLabel.INVALID_EMAIL
import com.wire.kalium.network.exceptions.NetworkErrorLabel.INVALID_HANDLE
import com.wire.kalium.network.exceptions.NetworkErrorLabel.KEY_EXISTS
import com.wire.kalium.network.exceptions.NetworkErrorLabel.MISSING_AUTH
import com.wire.kalium.network.exceptions.NetworkErrorLabel.MISSING_LEGALHOLD_CONSENT
import com.wire.kalium.network.exceptions.NetworkErrorLabel.MLS_CLIENT_MISMATCH
import com.wire.kalium.network.exceptions.NetworkErrorLabel.MLS_COMMIT_MISSING_REFERENCES
import com.wire.kalium.network.exceptions.NetworkErrorLabel.MLS_MISSING_GROUP_INFO
Expand Down Expand Up @@ -231,3 +232,4 @@ val KaliumException.InvalidRequestError.authenticationCodeFailure: Authenticatio

fun KaliumException.FederationError.isFederationDenied() = errorResponse.label == FEDERATION_DENIED
fun KaliumException.FederationError.isFederationNotEnabled() = errorResponse.label == FEDERATION_NOT_ENABLED
fun KaliumException.InvalidRequestError.isMissingLegalHoldConsent(): Boolean = errorResponse.label == MISSING_LEGALHOLD_CONSENT
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal object NetworkErrorLabel {
const val ACCESS_DENIED = "access-denied"
const val WRONG_CONVERSATION_PASSWORD = "invalid-conversation-password"
const val NOT_FOUND = "not-found"
const val MISSING_LEGALHOLD_CONSENT = "missing-legalhold-consent"

// Federation
const val FEDERATION_FAILURE = "federation-remote-error"
Expand Down
Loading