Skip to content

Commit

Permalink
fix: some end points are not routed through the proxy server v4.5 (#2485
Browse files Browse the repository at this point in the history
)

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

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

* fix cli

* fix android sample

* fix test service

* detekt

* fix ios target

* fix tests

* refactor: reimplement update api versions usecase to use proxy (#2414)

* refactor: implement UpdateApiVersionsUseCaseImpl to be proxy safe

* feat: add proxy URL and need auth indication to custom server dialogs

* fix tests

(cherry picked from commit b1f1457)

* fix cherry pick issues

* detekt

* trigger CI

* fix import

* fix test

(cherry picked from commit 5651bb1)
  • Loading branch information
MohamadJaara committed Feb 21, 2024
1 parent 9ec9a54 commit d0d11cc
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,8 @@ class UserSessionScope internal constructor(
messages.sendConfirmation,
renamedConversationHandler,
qualifiedIdMapper,
team.isSelfATeamMember,
authenticationScope.serverConfigRepository,
authenticationScope.serverConfigRepository,
userStorage,
userPropertyRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
@file:Suppress("konsist.useCasesShouldNotAccessNetworkLayerDirectly")
@file:Suppress("konsist.useCasesShouldNotAccessNetworkLayerDirectly", "konsist.useCasesShouldNotAccessDaoLayerDirectly")

package com.wire.kalium.logic.feature.appVersioning

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
@file:Suppress("konsist.useCasesShouldNotAccessDaoLayerDirectly",)

package com.wire.kalium.logic.feature.auth

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
@file:Suppress("konsist.useCasesShouldNotAccessNetworkLayerDirectly")
@file:Suppress("konsist.useCasesShouldNotAccessDaoLayerDirectly", "konsist.useCasesShouldNotAccessNetworkLayerDirectly")

package com.wire.kalium.logic.feature.auth

import co.touchlab.stately.collections.ConcurrentMutableMap
import com.wire.kalium.logic.configuration.appVersioning.AppVersionRepository
import com.wire.kalium.logic.configuration.appVersioning.AppVersionRepositoryImpl
import com.wire.kalium.logic.configuration.server.CustomServerConfigDataSource
import com.wire.kalium.logic.configuration.server.CustomServerConfigRepository
import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.configuration.server.ServerConfigDataSource
import com.wire.kalium.logic.configuration.server.ServerConfigRepository
Expand Down Expand Up @@ -108,6 +110,14 @@ class AuthenticationScope internal constructor(
get() = RegisterAccountDataSource(
unauthenticatedNetworkContainer.registerApi
)

private val customServerConfigRepository: CustomServerConfigRepository
get() = CustomServerConfigDataSource(
unauthenticatedNetworkContainer.serverConfigApi,
kaliumConfigs.developmentApiEnabled,
globalDatabase.serverConfigurationDAO
)

internal val ssoLoginRepository: SSOLoginRepository
get() = SSOLoginRepositoryImpl(unauthenticatedNetworkContainer.sso, unauthenticatedNetworkContainer.domainLookupApi)

Expand Down Expand Up @@ -140,7 +150,7 @@ class AuthenticationScope internal constructor(

val domainLookup: DomainLookupUseCase
get() = DomainLookupUseCase(
serverConfigApi = unauthenticatedNetworkContainer.serverConfigApi,
serverConfigApi = customServerConfigRepository,
ssoLoginRepository = ssoLoginRepository
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.wire.kalium.logic.feature.auth

import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.configuration.server.CustomServerConfigRepository
import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.configuration.server.ServerConfigMapper
import com.wire.kalium.logic.data.auth.login.SSOLoginRepository
Expand All @@ -35,9 +36,8 @@ import com.wire.kalium.network.api.base.unbound.configuration.ServerConfigApi
* @param email the email to lookup
*/
class DomainLookupUseCase internal constructor(
private val serverConfigApi: ServerConfigApi,
private val ssoLoginRepository: SSOLoginRepository,
private val serverConfigMapper: ServerConfigMapper = MapperProvider.serverConfigMapper()
private val customServerConfigRepository: CustomServerConfigRepository,
private val ssoLoginRepository: SSOLoginRepository
) {
suspend operator fun invoke(email: String): Result {
val domain = email.substringAfterLast('@').ifBlank {
Expand All @@ -46,9 +46,7 @@ class DomainLookupUseCase internal constructor(
}

return ssoLoginRepository.domainLookup(domain).flatMap {
wrapApiRequest { serverConfigApi.fetchServerConfig(it.configJsonUrl) }
.map { serverConfigMapper.fromDTO(it) }

customServerConfigRepository.fetchRemoteConfig(it.configJsonUrl)
}.fold(Result::Failure, Result::Success)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
@file:Suppress("konsist.useCasesShouldNotAccessNetworkLayerDirectly")

package com.wire.kalium.logic.feature.auth.autoVersioningAuth

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
@file:Suppress("konsist.useCasesShouldNotAccessDaoLayerDirectly")

package com.wire.kalium.logic.feature.server

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
@file:Suppress("konsist.useCasesShouldNotAccessDaoLayerDirectly")

package com.wire.kalium.logic.feature.server

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package com.wire.kalium.logic.feature.auth

import com.wire.kalium.logic.NetworkFailure
import com.wire.kalium.logic.configuration.server.CustomServerConfigRepository
import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.data.auth.login.DomainLookupResult
import com.wire.kalium.logic.data.auth.login.SSOLoginRepository
import com.wire.kalium.logic.di.MapperProvider
Expand All @@ -41,7 +43,6 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs

@OptIn(ExperimentalCoroutinesApi::class)
class DomainLookupUseCaseTest {

@Test
Expand Down Expand Up @@ -83,8 +84,8 @@ class DomainLookupUseCaseTest {
.arrange()
useCases(userEmail)

verify(arrangement.serverConfigApi)
.suspendFunction(arrangement.serverConfigApi::fetchServerConfig)
verify(arrangement.customServerConfigRepository)
.suspendFunction(arrangement.customServerConfigRepository::fetchRemoteConfig)
.with(eq("https://wire.com"))
.wasInvoked(exactly = once)
}
Expand All @@ -94,9 +95,6 @@ class DomainLookupUseCaseTest {
val userEmail = "[email protected]"
val expectedServerLinks = newServerConfig(1).links

val expextedDTO = expectedServerLinks.let {
MapperProvider.serverConfigMapper().toDTO(it)
}
val (arrangement, useCases) = Arrangement()
.withDomainLookupResult(Either.Right(DomainLookupResult("https://wire.com", "https://wire.com")))
.withFetchServerConfigResult(NetworkResponse.Success(expextedDTO, emptyMap(), 200,))
Expand All @@ -112,8 +110,8 @@ class DomainLookupUseCaseTest {
.with(eq("wire.com"))
.wasInvoked(exactly = once)

verify(arrangement.serverConfigApi)
.suspendFunction(arrangement.serverConfigApi::fetchServerConfig)
verify(arrangement.customServerConfigRepository)
.suspendFunction(arrangement.customServerConfigRepository::fetchRemoteConfig)
.with(eq("https://wire.com"))
.wasInvoked(exactly = once)
}
Expand All @@ -124,10 +122,10 @@ class DomainLookupUseCaseTest {
val ssoLoginRepository: SSOLoginRepository = mock(SSOLoginRepository::class)

@Mock
val serverConfigApi: ServerConfigApi = mock(ServerConfigApi::class)
val customServerConfigRepository: CustomServerConfigRepository = mock(CustomServerConfigRepository::class)

private val useCases = DomainLookupUseCase(
serverConfigApi,
customServerConfigRepository,
ssoLoginRepository
)

Expand All @@ -138,9 +136,10 @@ class DomainLookupUseCaseTest {
.thenReturn(result)
}

fun withFetchServerConfigResult(result: NetworkResponse<ServerConfigDTO.Links>) = apply {
given(serverConfigApi)
.suspendFunction(serverConfigApi::fetchServerConfig)
fun withFetchServerConfigResult(result:
Either<NetworkFailure, ServerConfig.Links>) = apply {
given(customServerConfigRepository)
.suspendFunction(customServerConfigRepository::fetchRemoteConfig)
.whenInvokedWith(any())
.thenReturn(result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ interface UnauthenticatedNetworkContainer {

// this is intentional since we should drop support for api v3
// and we default back to v2
3 -> UnauthenticatedNetworkContainerV2(
developmentApiEnabled,
3 -> UnauthenticatedNetworkContainerV2( developmentApiEnabled,
networkStateObserver,
serverConfigDTO,
proxyCredentials = proxyCredentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ internal class UnboundClearTextTrafficNetworkClientProviderImpl(
class UnboundNetworkContainerCommon(
networkStateObserver: NetworkStateObserver,
userAgent: String,
private val ignoreSSLCertificates: Boolean,
certificatePinning: CertificatePinning,
mockEngine: HttpClientEngine?
) : UnboundNetworkContainer,
UnboundNetworkClientProvider by UnboundNetworkClientProviderImpl(
networkStateObserver = networkStateObserver,
userAgent = userAgent,
networkStateObserver,
userAgent,
engine = mockEngine ?: defaultHttpEngine(
ignoreSSLCertificates = ignoreSSLCertificates,
certificatePinning = certificatePinning,
proxyCredentials = null,
serverConfigDTOApiProxy = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class PocIntegrationTest {
isOnPremises = true,
apiProxy = null
)
).invoke()
).invoke(null)
if (result !is AutoVersionAuthScopeUseCase.Result.Success) {
error("Failed getting AuthScope: $result")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.wire.kalium.logger.KaliumLogger
import com.wire.kalium.logic.CoreLogger
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.data.auth.login.ProxyCredentials
import com.wire.kalium.logic.data.client.ClientType
import com.wire.kalium.logic.data.client.DeleteClientParam
import com.wire.kalium.logic.data.conversation.ClientId
Expand Down Expand Up @@ -172,7 +173,7 @@ class InstanceService(
}
}

val loginResult = provideVersionedAuthenticationScope(coreLogic, serverConfig)
val loginResult = provideVersionedAuthenticationScope(coreLogic, serverConfig, null)
.login(
instanceRequest.email, instanceRequest.password, true,
secondFactorVerificationCode = instanceRequest.verificationCode
Expand Down Expand Up @@ -306,15 +307,21 @@ class InstanceService(
// close the stream
files.close()
} catch (e: IOException) {
log.warn("Instance ${instance.instanceId}: Could not delete directory ${instance.instancePath}: "
+ e.message)
log.warn(
"Instance ${instance.instanceId}: Could not delete directory ${instance.instancePath}: "
+ e.message
)
}
}
}, deleteLocalFilesTimeoutInMinutes.toMinutes(), TimeUnit.MINUTES)
}

private suspend fun provideVersionedAuthenticationScope(coreLogic: CoreLogic, serverLinks: ServerConfig.Links): AuthenticationScope =
when (val result = coreLogic.versionedAuthenticationScope(serverLinks).invoke()) {
private suspend fun provideVersionedAuthenticationScope(
coreLogic: CoreLogic,
serverLinks: ServerConfig.Links,
proxyCredentials: ProxyCredentials?
): AuthenticationScope =
when (val result = coreLogic.versionedAuthenticationScope(serverLinks).invoke(proxyCredentials)) {
is AutoVersionAuthScopeUseCase.Result.Failure.Generic ->
throw WebApplicationException("failed to create authentication scope: ${result.genericFailure}")

Expand Down

0 comments on commit d0d11cc

Please sign in to comment.