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

fix: some end points are not routed through the proxy server #2400

Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -100,7 +100,7 @@ class MainActivity : ComponentActivity() {
}

private suspend fun provideAuthScope(coreLogic: CoreLogic, backendLinks: ServerConfig.Links): AuthenticationScope =
when (val result = coreLogic.versionedAuthenticationScope(backendLinks).invoke()) {
when (val result = coreLogic.versionedAuthenticationScope(backendLinks).invoke(null)) {
is AutoVersionAuthScopeUseCase.Result.Failure.Generic -> error("Generic failure")
AutoVersionAuthScopeUseCase.Result.Failure.TooNewVersion -> error("Too new version")
AutoVersionAuthScopeUseCase.Result.Failure.UnknownServerVersion -> error("Unknown server version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class LoginCommand : CliktCommand(name = "login") {
}

private suspend fun provideVersionedAuthenticationScope(serverLinks: ServerConfig.Links): AuthenticationScope =
when (val result = coreLogic.versionedAuthenticationScope(serverLinks).invoke()) {
// CLI does not support proxy mode so we can pass null here
when (val result = coreLogic.versionedAuthenticationScope(serverLinks).invoke(null)) {
is AutoVersionAuthScopeUseCase.Result.Failure.Generic ->
throw PrintMessage("failed to create authentication scope: ${result.genericFailure}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import com.wire.kalium.logic.feature.UserSessionScopeProvider
import com.wire.kalium.logic.feature.UserSessionScopeProviderImpl
import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.network.NetworkStateObserverImpl
import com.wire.kalium.logic.sync.GlobalWorkScheduler
import com.wire.kalium.logic.sync.GlobalWorkSchedulerImpl
import com.wire.kalium.logic.util.PlatformContext
import com.wire.kalium.logic.util.SecurityHelperImpl
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider
import kotlinx.coroutines.cancel
Expand Down Expand Up @@ -83,6 +83,7 @@ actual class CoreLogic(
rootPathsProvider,
appContext,
getGlobalScope(),
globalDatabase,
kaliumConfigs,
globalPreferences,
globalCallManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import com.wire.kalium.logic.di.UserStorageProvider
import com.wire.kalium.logic.feature.auth.AuthenticationScopeProvider
import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.UserSessionWorkScheduler
import com.wire.kalium.logic.util.SecurityHelperImpl
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider

@Suppress("LongParameterList")
Expand All @@ -41,6 +42,7 @@ internal fun UserSessionScope(
userAgent: String,
userId: UserId,
globalScope: GlobalKaliumScope,
globalDatabaseProvider: GlobalDatabaseProvider,
globalCallManager: GlobalCallManager,
globalPreferences: GlobalPrefProvider,
authenticationScopeProvider: AuthenticationScopeProvider,
Expand All @@ -62,6 +64,7 @@ internal fun UserSessionScope(
userId,
globalScope,
globalCallManager,
globalDatabaseProvider,
globalPreferences,
authenticationScopeProvider,
userSessionWorkScheduler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import com.wire.kalium.logic.di.UserStorageProvider
import com.wire.kalium.logic.feature.auth.AuthenticationScopeProvider
import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.UserSessionWorkSchedulerImpl
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider
import com.wire.kalium.persistence.util.FileNameUtil

Expand All @@ -42,6 +43,7 @@ internal actual class UserSessionScopeProviderImpl(
private val rootPathsProvider: RootPathsProvider,
private val appContext: Context,
private val globalScope: GlobalKaliumScope,
private val globalDatabaseProvider: GlobalDatabaseProvider,
private val kaliumConfigs: KaliumConfigs,
private val globalPreferences: GlobalPrefProvider,
private val globalCallManager: GlobalCallManager,
Expand All @@ -64,6 +66,7 @@ internal actual class UserSessionScopeProviderImpl(
globalScope = globalScope,
globalCallManager = globalCallManager,
globalPreferences = globalPreferences,
globalDatabaseProvider = globalDatabaseProvider,
authenticationScopeProvider = authenticationScopeProvider,
userSessionWorkScheduler = userSessionWorkScheduler,
rootPathsProvider = rootPathsProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ actual class CoreLogic(
kaliumConfigs,
globalPreferences,
globalCallManager,
globalDatabase,
userStorageProvider,
networkStateObserver,
userAgent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.UserSessionWorkScheduler
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider

@Suppress("LongParameterList")
Expand All @@ -40,6 +41,7 @@ internal fun UserSessionScope(
globalScope: GlobalKaliumScope,
globalCallManager: GlobalCallManager,
globalPreferences: GlobalPrefProvider,
globalDatabaseProvider: GlobalDatabaseProvider,
authenticationScopeProvider: AuthenticationScopeProvider,
userSessionWorkScheduler: UserSessionWorkScheduler,
rootPathsProvider: RootPathsProvider,
Expand All @@ -58,6 +60,7 @@ internal fun UserSessionScope(
userId,
globalScope,
globalCallManager,
globalDatabaseProvider,
globalPreferences,
authenticationScopeProvider,
userSessionWorkScheduler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.UserSessionWorkSchedulerImpl
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider

@Suppress("LongParameterList")
Expand All @@ -42,6 +43,7 @@ internal actual class UserSessionScopeProviderImpl(
private val kaliumConfigs: KaliumConfigs,
private val globalPreferences: GlobalPrefProvider,
private val globalCallManager: GlobalCallManager,
private val globalDatabaseProvider: GlobalDatabaseProvider,
private val userStorageProvider: UserStorageProvider,
private val networkStateObserver: NetworkStateObserver,
userAgent: String
Expand All @@ -60,6 +62,7 @@ internal actual class UserSessionScopeProviderImpl(
globalScope,
globalCallManager,
globalPreferences,
globalDatabaseProvider,
authenticationScopeProvider,
userSessionWorkScheduler,
rootPathsProvider,
Expand Down
16 changes: 10 additions & 6 deletions logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import com.wire.kalium.logic.feature.auth.AuthenticationScopeProvider
import com.wire.kalium.logic.feature.auth.autoVersioningAuth.AutoVersionAuthScopeUseCase
import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.logic.sync.GlobalWorkScheduler
import com.wire.kalium.logic.sync.periodic.UpdateApiVersionsScheduler
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.persistence.db.GlobalDatabaseProvider
import com.wire.kalium.persistence.kmmSettings.GlobalPrefProvider

Expand All @@ -49,7 +49,7 @@ abstract class CoreLogicCommon internal constructor(
protected val idMapper: IdMapper = MapperProvider.idMapper()
) {
protected abstract val globalPreferences: GlobalPrefProvider
protected abstract val globalDatabase: GlobalDatabaseProvider
internal abstract val globalDatabase: GlobalDatabaseProvider
protected abstract val userSessionScopeProvider: Lazy<UserSessionScopeProvider>
protected val userStorageProvider: UserStorageProvider = PlatformUserStorageProvider()

Expand All @@ -71,9 +71,9 @@ abstract class CoreLogicCommon internal constructor(
@Suppress("MemberVisibilityCanBePrivate") // Can be used by other targets like iOS and JS
fun getAuthenticationScope(
serverConfig: ServerConfig,
proxyCredentials: ProxyCredentials? = null
proxyCredentials: ProxyCredentials?
): AuthenticationScope =
authenticationScopeProvider.provide(serverConfig, proxyCredentials, getGlobalScope().serverConfigRepository, networkStateObserver)
authenticationScopeProvider.provide(serverConfig, proxyCredentials, networkStateObserver, globalDatabase, kaliumConfigs)

@Suppress("MemberVisibilityCanBePrivate") // Can be used by other targets like iOS and JS
abstract fun getSessionScope(userId: UserId): UserSessionScope
Expand All @@ -83,8 +83,12 @@ abstract class CoreLogicCommon internal constructor(
// TODO: make globalScope a singleton
inline fun <T> globalScope(action: GlobalKaliumScope.() -> T): T = getGlobalScope().action()

inline fun <T> authenticationScope(serverConfig: ServerConfig, action: AuthenticationScope.() -> T): T =
getAuthenticationScope(serverConfig).action()
inline fun <T> authenticationScope(
serverConfig: ServerConfig,
proxyCredentials: ProxyCredentials?,
action: AuthenticationScope.() -> T
): T =
getAuthenticationScope(serverConfig, proxyCredentials).action()

inline fun <T> sessionScope(
userId: UserId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package com.wire.kalium.logic

import com.wire.kalium.logic.configuration.notification.NotificationTokenDataSource
import com.wire.kalium.logic.configuration.notification.NotificationTokenRepository
import com.wire.kalium.logic.configuration.server.ServerConfigDataSource
import com.wire.kalium.logic.configuration.server.ServerConfigRepository
import com.wire.kalium.logic.configuration.server.CustomServerConfigDataSource
import com.wire.kalium.logic.configuration.server.CustomServerConfigRepository
import com.wire.kalium.logic.data.client.UserClientRepositoryProvider
import com.wire.kalium.logic.data.client.UserClientRepositoryProviderImpl
import com.wire.kalium.logic.data.session.SessionDataSource
Expand All @@ -46,10 +46,7 @@ import com.wire.kalium.logic.feature.notificationToken.SaveNotificationTokenUseC
import com.wire.kalium.logic.feature.rootDetection.CheckSystemIntegrityUseCase
import com.wire.kalium.logic.feature.rootDetection.CheckSystemIntegrityUseCaseImpl
import com.wire.kalium.logic.feature.rootDetection.RootDetectorImpl
import com.wire.kalium.logic.feature.server.FetchApiVersionUseCase
import com.wire.kalium.logic.feature.server.FetchApiVersionUseCaseImpl
import com.wire.kalium.logic.feature.server.GetServerConfigUseCase
import com.wire.kalium.logic.feature.server.ObserveServerConfigUseCase
import com.wire.kalium.logic.feature.server.ServerConfigForAccountUseCase
import com.wire.kalium.logic.feature.server.StoreServerConfigUseCase
import com.wire.kalium.logic.feature.server.StoreServerConfigUseCaseImpl
Expand Down Expand Up @@ -98,25 +95,16 @@ class GlobalKaliumScope internal constructor(
val unboundNetworkContainer: UnboundNetworkContainer by lazy {
UnboundNetworkContainerCommon(
networkStateObserver,
kaliumConfigs.developmentApiEnabled,
userAgent,
kaliumConfigs.ignoreSSLCertificatesForUnboundCalls
)
}

internal val serverConfigRepository: ServerConfigRepository
get() = ServerConfigDataSource(
unboundNetworkContainer.serverConfigApi,
globalDatabase.serverConfigurationDAO,
unboundNetworkContainer.remoteVersion,
kaliumConfigs.developmentApiEnabled
)

val sessionRepository: SessionRepository
get() = SessionDataSource(
globalDatabase.accountsDAO,
globalPreferences.authTokenStorage,
serverConfigRepository,
globalDatabase.serverConfigurationDAO,
kaliumConfigs
)

Expand All @@ -127,24 +115,28 @@ class GlobalKaliumScope internal constructor(
get() =
NotificationTokenDataSource(globalPreferences.tokenStorage)

private val customServerConfigRepository: CustomServerConfigRepository
get() = CustomServerConfigDataSource(
unboundNetworkContainer.serverConfigApi,
developmentApiEnabled = kaliumConfigs.developmentApiEnabled,
globalDatabase.serverConfigurationDAO
)
val validateEmailUseCase: ValidateEmailUseCase get() = ValidateEmailUseCaseImpl()
val validateUserHandleUseCase: ValidateUserHandleUseCase get() = ValidateUserHandleUseCaseImpl()
val validatePasswordUseCase: ValidatePasswordUseCase get() = ValidatePasswordUseCaseImpl()

val addAuthenticatedAccount: AddAuthenticatedUserUseCase
get() =
AddAuthenticatedUserUseCase(sessionRepository, serverConfigRepository)
AddAuthenticatedUserUseCase(sessionRepository, globalDatabase.serverConfigurationDAO)
val getSessions: GetSessionsUseCase get() = GetSessionsUseCase(sessionRepository)
val doesValidSessionExist: DoesValidSessionExistUseCase get() = DoesValidSessionExistUseCase(sessionRepository)
val observeValidAccounts: ObserveValidAccountsUseCase
get() = ObserveValidAccountsUseCaseImpl(sessionRepository, userSessionScopeProvider.value)

val session: SessionScope get() = SessionScope(sessionRepository)
val fetchServerConfigFromDeepLink: GetServerConfigUseCase get() = GetServerConfigUseCase(serverConfigRepository)
val fetchApiVersion: FetchApiVersionUseCase get() = FetchApiVersionUseCaseImpl(serverConfigRepository)
val observeServerConfig: ObserveServerConfigUseCase get() = ObserveServerConfigUseCase(serverConfigRepository)
val updateApiVersions: UpdateApiVersionsUseCase get() = UpdateApiVersionsUseCaseImpl(serverConfigRepository)
val storeServerConfig: StoreServerConfigUseCase get() = StoreServerConfigUseCaseImpl(serverConfigRepository)
val fetchServerConfigFromDeepLink: GetServerConfigUseCase get() = GetServerConfigUseCase(customServerConfigRepository)
val updateApiVersions: UpdateApiVersionsUseCase get() = UpdateApiVersionsUseCaseImpl()
val storeServerConfig: StoreServerConfigUseCase get() = StoreServerConfigUseCaseImpl(customServerConfigRepository)

val saveNotificationToken: SaveNotificationTokenUseCase
get() = SaveNotificationTokenUseCaseImpl(
Expand All @@ -157,15 +149,16 @@ class GlobalKaliumScope internal constructor(
get() = DeleteSessionUseCase(sessionRepository, userSessionScopeProvider.value)

val serverConfigForAccounts: ServerConfigForAccountUseCase
get() =
ServerConfigForAccountUseCase(serverConfigRepository)
get() = ServerConfigForAccountUseCase(globalDatabase.serverConfigurationDAO)

val observeIfAppUpdateRequired: ObserveIfAppUpdateRequiredUseCase
get() = ObserveIfAppUpdateRequiredUseCaseImpl(
serverConfigRepository,
customServerConfigRepository,
authenticationScopeProvider,
userSessionScopeProvider.value,
networkStateObserver
networkStateObserver,
globalDatabase,
kaliumConfigs
)

val checkSystemIntegrity: CheckSystemIntegrityUseCase
Expand Down
Loading
Loading