Skip to content

Commit

Permalink
Merge branch 'develop' into feat/e2ei/separate-e2ei-enrollment-steps
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani authored Nov 17, 2023
2 parents 6493796 + 78a0841 commit 22ac20b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ internal class LogoutUseCaseImpl @Suppress("LongParameterList") constructor(
endCallUseCase(it.conversationId)
}

logoutRepository.logout()
if (reason != LogoutReason.SESSION_EXPIRED) {
logoutRepository.logout()
}

sessionRepository.logout(userId = userId, reason)
logoutRepository.onLogout(reason)
userSessionWorkScheduler.cancelScheduledSendingOfPendingMessages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.wire.kalium.logic.data.featureConfig.AppLockModel
import com.wire.kalium.logic.data.featureConfig.Status
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.nullableFold
import kotlin.time.Duration.Companion.seconds

class AppLockConfigHandler(
private val userConfigRepository: UserConfigRepository
Expand All @@ -37,8 +36,8 @@ class AppLockConfigHandler(
},
{
val newStatus = appLockConfig.status == Status.ENABLED
((it.isEnabled != newStatus) ||
(newStatus && it.timeout != appLockConfig.inactivityTimeoutSecs.seconds))
if (it.isEnabled != newStatus) true
else it.isStatusChanged
}
)
return userConfigRepository.setAppLockStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,14 @@ class SessionManagerImpl internal constructor(

private var serverConfig: ServerConfigDTO? = null

override suspend fun session(): SessionDTO = withContext(coroutineContext) {
override suspend fun session(): SessionDTO? = withContext(coroutineContext) {
wrapStorageRequest { tokenStorage.getToken(userId.toDao()) }
.map { sessionMapper.fromEntityToSessionDTO(it) }
.fold(
.nullableFold(
{
error(
"""SESSION MANAGER:
|"error": "missing user session",
|"cause": "$it" """.trimMargin()
)
logout(LogoutReason.SESSION_EXPIRED)
null
}, { session ->
kaliumLogger.i("_TOKEN_ FOUND SESSION = $session")
session
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class LogoutUseCaseTest {
verify(arrangement.deregisterTokenUseCase)
.suspendFunction(arrangement.deregisterTokenUseCase::invoke)
.wasInvoked(exactly = once)
verify(arrangement.logoutRepository)
.suspendFunction(arrangement.logoutRepository::logout)
.wasInvoked(exactly = once)

verify(arrangement.sessionRepository)
.suspendFunction(arrangement.sessionRepository::logout)
.with(any(), eq(reason))
Expand Down Expand Up @@ -211,6 +209,10 @@ class LogoutUseCaseTest {
logoutUseCase.invoke(reason)
arrangement.globalTestScope.advanceUntilIdle()

verify(arrangement.logoutRepository)
.suspendFunction(arrangement.logoutRepository::logout)
.wasNotInvoked()

verify(arrangement.clearClientDataUseCase)
.suspendFunction(arrangement.clearClientDataUseCase::invoke)
.wasInvoked(exactly = once)
Expand Down Expand Up @@ -238,9 +240,14 @@ class LogoutUseCaseTest {
logoutUseCase.invoke(reason)
arrangement.globalTestScope.advanceUntilIdle()

verify(arrangement.logoutRepository)
.suspendFunction(arrangement.logoutRepository::logout)
.wasInvoked(exactly = once)

verify(arrangement.clearClientDataUseCase)
.suspendFunction(arrangement.clearClientDataUseCase::invoke)
.wasInvoked(exactly = once)

verify(arrangement.clearUserDataUseCase)
.suspendFunction(arrangement.clearUserDataUseCase::invoke)
.wasNotInvoked()
Expand Down Expand Up @@ -271,6 +278,10 @@ class LogoutUseCaseTest {
logoutUseCase.invoke(reason)
arrangement.globalTestScope.advanceUntilIdle()

verify(arrangement.logoutRepository)
.suspendFunction(arrangement.logoutRepository::logout)
.wasInvoked(exactly = once)

verify(arrangement.clearClientDataUseCase)
.suspendFunction(arrangement.clearClientDataUseCase::invoke)
.wasNotInvoked()
Expand Down Expand Up @@ -307,6 +318,10 @@ class LogoutUseCaseTest {
logoutUseCase.invoke(reason)
arrangement.globalTestScope.advanceUntilIdle()

verify(arrangement.logoutRepository)
.suspendFunction(arrangement.logoutRepository::logout)
.wasInvoked(exactly = once)

verify(arrangement.observeEstablishedCallsUseCase)
.suspendFunction(arrangement.observeEstablishedCallsUseCase::invoke)
.wasInvoked(exactly = once)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AppLockConfigHandlerTest {
}

@Test
fun givenNewStatusSameAsCurrent_whenHandlingTheEvent_ThenSetAppLockWithStatusChangedFalse() {
fun givenNewStatusSameAsCurrent_whenHandlingTheEvent_ThenSetAppLockWithOldStatusChangedValue() {
val appLockModel = AppLockModel(Status.ENABLED, 44)
val (arrangement, appLockConfigHandler) = Arrangement()
.withAppLocked()
Expand All @@ -99,30 +99,7 @@ class AppLockConfigHandlerTest {
.with(
eq(appLockModel.status.toBoolean()),
eq(appLockModel.inactivityTimeoutSecs),
eq(false)
)
.wasInvoked(exactly = once)
}

@Test
fun givenStatusEnabledAndTimeoutDifferentFromCurrent_whenHandlingTheEvent_ThenSetAppLockWithStatusChangedTrue() {
val appLockModel = AppLockModel(Status.ENABLED, 20)
val (arrangement, appLockConfigHandler) = Arrangement()
.withAppLocked()
.arrange()

appLockConfigHandler.handle(appLockModel)

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::isTeamAppLockEnabled)
.wasInvoked(exactly = once)

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::setAppLockStatus)
.with(
eq(appLockModel.status.toBoolean()),
eq(appLockModel.inactivityTimeoutSecs),
eq(true)
eq(appLockTeamConfigEnabled.isStatusChanged)
)
.wasInvoked(exactly = once)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import com.wire.kalium.network.api.v2.authenticated.networkContainer.Authenticat
import com.wire.kalium.network.api.v3.authenticated.networkContainer.AuthenticatedNetworkContainerV3
import com.wire.kalium.network.api.v4.authenticated.networkContainer.AuthenticatedNetworkContainerV4
import com.wire.kalium.network.api.v5.authenticated.networkContainer.AuthenticatedNetworkContainerV5
import com.wire.kalium.network.kaliumLogger
import com.wire.kalium.network.session.CertificatePinning
import com.wire.kalium.network.session.SessionManager
import com.wire.kalium.network.tools.ServerConfigDTO
Expand Down Expand Up @@ -202,8 +201,9 @@ internal class AuthenticatedHttpClientProviderImpl(
}

private val loadToken: suspend () -> BearerTokens? = {
val session = sessionManager.session() ?: error("missing user session")
BearerTokens(accessToken = session.accessToken, refreshToken = session.refreshToken)
sessionManager.session()?.let { session ->
BearerTokens(accessToken = session.accessToken, refreshToken = session.refreshToken)
}
}

private val refreshToken: suspend RefreshTokensParams.() -> BearerTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ import com.wire.kalium.network.exceptions.KaliumException
import com.wire.kalium.network.exceptions.NetworkErrorLabel

object CustomErrors {

private const val MISSING_REFRESH_TOKEN_CODE = -1
private const val MISSING_NONCE_CODE = -2

val MISSING_REFRESH_TOKEN =
NetworkResponse.Error(
KaliumException.ServerError(
ErrorResponse(
500,
MISSING_REFRESH_TOKEN_CODE,
"no cookie was found",
NetworkErrorLabel.KaliumCustom.MISSING_REFRESH_TOKEN
)
Expand All @@ -38,10 +42,11 @@ object CustomErrors {
NetworkResponse.Error(
KaliumException.ServerError(
ErrorResponse(
500,
MISSING_NONCE_CODE,
"no nonce found",
NetworkErrorLabel.KaliumCustom.MISSING_NONCE
)
)
)

}

0 comments on commit 22ac20b

Please sign in to comment.