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 redirection #2836

Merged
merged 9 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ Bugfix 🐛:
- VoIP : fix audio devices output
- Fix crash after initial sync on Dendrite
- Fix crash reported by PlayStore (#2707)
- Ignore url override from credential if it is not valid (#2822)

Translations 🗣:
-

SDK API changes ⚠️:
-
- Migrate AuthenticationService API to coroutines (#2449)

Build 🧱:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.auth.UIABaseAuth
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
import org.matrix.android.sdk.api.auth.UserPasswordAuth
import org.matrix.android.sdk.api.auth.data.LoginFlowResult
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
import org.matrix.android.sdk.api.auth.registration.RegistrationResult
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.MatrixError
import org.matrix.android.sdk.common.CommonTestHelper
import org.matrix.android.sdk.common.SessionTestParams
import org.matrix.android.sdk.common.TestConstants
import org.matrix.android.sdk.common.TestMatrixCallback
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume

Expand Down Expand Up @@ -75,23 +72,23 @@ class DeactivateAccountTest : InstrumentedTest {
// Try to create an account with the deactivate account user id, it will fail (M_USER_IN_USE)
val hs = commonTestHelper.createHomeServerConfig()

commonTestHelper.doSync<LoginFlowResult> {
commonTestHelper.matrix.authenticationService.getLoginFlow(hs, it)
commonTestHelper.runBlockingTest {
commonTestHelper.matrix.authenticationService.getLoginFlow(hs)
}

var accountCreationError: Throwable? = null
commonTestHelper.waitWithLatch {
commonTestHelper.matrix.authenticationService
.getRegistrationWizard()
.createAccount(session.myUserId.substringAfter("@").substringBefore(":"),
TestConstants.PASSWORD,
null,
object : TestMatrixCallback<RegistrationResult>(it, false) {
override fun onFailure(failure: Throwable) {
accountCreationError = failure
super.onFailure(failure)
}
})
commonTestHelper.runBlockingTest {
try {
commonTestHelper.matrix.authenticationService
.getRegistrationWizard()
.createAccount(
session.myUserId.substringAfter("@").substringBefore(":"),
TestConstants.PASSWORD,
null
)
} catch (failure: Throwable) {
accountCreationError = failure
}
}

// Test the error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.matrix.android.sdk.api.Matrix
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.MatrixConfiguration
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.data.LoginFlowResult
import org.matrix.android.sdk.api.auth.registration.RegistrationResult
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType
Expand Down Expand Up @@ -210,22 +209,21 @@ class CommonTestHelper(context: Context) {
sessionTestParams: SessionTestParams): Session {
val hs = createHomeServerConfig()

doSync<LoginFlowResult> {
matrix.authenticationService
.getLoginFlow(hs, it)
runBlockingTest {
matrix.authenticationService.getLoginFlow(hs)
}

doSync<RegistrationResult>(timeout = 60_000) {
runBlockingTest(timeout = 60_000) {
matrix.authenticationService
.getRegistrationWizard()
.createAccount(userName, password, null, it)
.createAccount(userName, password, null)
}

// Perform dummy step
val registrationResult = doSync<RegistrationResult>(timeout = 60_000) {
val registrationResult = runBlockingTest(timeout = 60_000) {
matrix.authenticationService
.getRegistrationWizard()
.dummy(it)
.dummy()
}

assertTrue(registrationResult is RegistrationResult.Success)
Expand All @@ -249,15 +247,14 @@ class CommonTestHelper(context: Context) {
sessionTestParams: SessionTestParams): Session {
val hs = createHomeServerConfig()

doSync<LoginFlowResult> {
matrix.authenticationService
.getLoginFlow(hs, it)
runBlockingTest {
matrix.authenticationService.getLoginFlow(hs)
}

val session = doSync<Session> {
val session = runBlockingTest {
matrix.authenticationService
.getLoginWizard()
.login(userName, password, "myDevice", it)
.login(userName, password, "myDevice")
}

if (sessionTestParams.withInitialSync) {
Expand All @@ -277,21 +274,19 @@ class CommonTestHelper(context: Context) {
password: String): Throwable {
val hs = createHomeServerConfig()

doSync<LoginFlowResult> {
matrix.authenticationService
.getLoginFlow(hs, it)
runBlockingTest {
matrix.authenticationService.getLoginFlow(hs)
}

var requestFailure: Throwable? = null
waitWithLatch { latch ->
matrix.authenticationService
.getLoginWizard()
.login(userName, password, "myDevice", object : TestMatrixCallback<Session>(latch, onlySuccessful = false) {
override fun onFailure(failure: Throwable) {
requestFailure = failure
super.onFailure(failure)
}
})
runBlockingTest {
try {
matrix.authenticationService
.getLoginWizard()
.login(userName, password, "myDevice")
} catch (failure: Throwable) {
requestFailure = failure
}
}

assertNotNull(requestFailure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SearchMessagesTest : InstrumentedTest {
2)

run {
var lock = CountDownLatch(1)
val lock = CountDownLatch(1)

val eventListener = commonTestHelper.createEventListener(lock) { snapshot ->
snapshot.count { it.root.content.toModel<MessageContent>()?.body?.startsWith(MESSAGE).orFalse() } == 2
Expand All @@ -70,7 +70,6 @@ class SearchMessagesTest : InstrumentedTest {
aliceTimeline.addListener(eventListener)
commonTestHelper.await(lock)

lock = CountDownLatch(1)
val data = commonTestHelper.runBlockingTest {
aliceSession
.searchService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,28 @@

package org.matrix.android.sdk.api.auth

import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.data.LoginFlowResult
import org.matrix.android.sdk.api.auth.login.LoginWizard
import org.matrix.android.sdk.api.auth.registration.RegistrationWizard
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Cancelable

/**
* This interface defines methods to authenticate or to create an account to a matrix server.
*/
interface AuthenticationService {
/**
* Request the supported login flows for this homeserver.
* This is the first method to call to be able to get a wizard to login or the create an account
* This is the first method to call to be able to get a wizard to login or to create an account
*/
fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback<LoginFlowResult>): Cancelable
suspend fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig): LoginFlowResult

/**
* Request the supported login flows for the corresponding sessionId.
*/
fun getLoginFlowOfSession(sessionId: String, callback: MatrixCallback<LoginFlowResult>): Cancelable
suspend fun getLoginFlowOfSession(sessionId: String): LoginFlowResult

/**
* Get a SSO url
Expand Down Expand Up @@ -69,12 +67,12 @@ interface AuthenticationService {
/**
* Cancel pending login or pending registration
*/
fun cancelPendingLoginOrRegistration()
suspend fun cancelPendingLoginOrRegistration()

/**
* Reset all pending settings, including current HomeServerConnectionConfig
*/
fun reset()
suspend fun reset()

/**
* Check if there is an authenticated [Session].
Expand All @@ -91,24 +89,21 @@ interface AuthenticationService {
/**
* Create a session after a SSO successful login
*/
fun createSessionFromSso(homeServerConnectionConfig: HomeServerConnectionConfig,
credentials: Credentials,
callback: MatrixCallback<Session>): Cancelable
suspend fun createSessionFromSso(homeServerConnectionConfig: HomeServerConnectionConfig,
credentials: Credentials): Session

/**
* Perform a wellknown request, using the domain from the matrixId
*/
fun getWellKnownData(matrixId: String,
homeServerConnectionConfig: HomeServerConnectionConfig?,
callback: MatrixCallback<WellknownResult>): Cancelable
suspend fun getWellKnownData(matrixId: String,
homeServerConnectionConfig: HomeServerConnectionConfig?): WellknownResult

/**
* Authenticate with a matrixId and a password
* Usually call this after a successful call to getWellKnownData()
*/
fun directAuthentication(homeServerConnectionConfig: HomeServerConnectionConfig,
matrixId: String,
password: String,
initialDeviceName: String,
callback: MatrixCallback<Session>): Cancelable
suspend fun directAuthentication(homeServerConnectionConfig: HomeServerConnectionConfig,
matrixId: String,
password: String,
initialDeviceName: String): Session
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.matrix.android.sdk.api.auth.login

import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Cancelable

Expand All @@ -29,26 +28,23 @@ interface LoginWizard {
* @param callback the matrix callback on which you'll receive the result of authentication.
* @return a [Cancelable]
*/
fun login(login: String,
password: String,
deviceName: String,
callback: MatrixCallback<Session>): Cancelable
suspend fun login(login: String,
password: String,
deviceName: String): Session

/**
* Exchange a login token to an access token
*/
fun loginWithToken(loginToken: String,
callback: MatrixCallback<Session>): Cancelable
suspend fun loginWithToken(loginToken: String): Session

/**
* Reset user password
*/
fun resetPassword(email: String,
newPassword: String,
callback: MatrixCallback<Unit>): Cancelable
suspend fun resetPassword(email: String,
newPassword: String)

/**
* Confirm the new password, once the user has checked his email
* Confirm the new password, once the user has checked their email
*/
fun resetPasswordMailConfirmed(callback: MatrixCallback<Unit>): Cancelable
suspend fun resetPasswordMailConfirmed()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@

package org.matrix.android.sdk.api.auth.registration

import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.util.Cancelable

interface RegistrationWizard {

fun getRegistrationFlow(callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun getRegistrationFlow(): RegistrationResult

fun createAccount(userName: String, password: String, initialDeviceDisplayName: String?, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun createAccount(userName: String, password: String, initialDeviceDisplayName: String?): RegistrationResult

fun performReCaptcha(response: String, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun performReCaptcha(response: String): RegistrationResult

fun acceptTerms(callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun acceptTerms(): RegistrationResult

fun dummy(callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun dummy(): RegistrationResult

fun addThreePid(threePid: RegisterThreePid, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun addThreePid(threePid: RegisterThreePid): RegistrationResult

fun sendAgainThreePid(callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun sendAgainThreePid(): RegistrationResult

fun handleValidateThreePid(code: String, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun handleValidateThreePid(code: String): RegistrationResult

fun checkIfEmailHasBeenValidated(delayMillis: Long, callback: MatrixCallback<RegistrationResult>): Cancelable
suspend fun checkIfEmailHasBeenValidated(delayMillis: Long): RegistrationResult

val currentThreePid: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import android.content.Context
import dagger.Binds
import dagger.Module
import dagger.Provides
import io.realm.RealmConfiguration
import org.matrix.android.sdk.api.auth.AuthenticationService
import org.matrix.android.sdk.api.auth.HomeServerHistoryService
import org.matrix.android.sdk.api.legacy.LegacySessionImporter
import org.matrix.android.sdk.internal.auth.db.AuthRealmMigration
import org.matrix.android.sdk.internal.auth.db.AuthRealmModule
Expand All @@ -32,8 +34,6 @@ import org.matrix.android.sdk.internal.database.RealmKeysUtils
import org.matrix.android.sdk.internal.di.AuthDatabase
import org.matrix.android.sdk.internal.legacy.DefaultLegacySessionImporter
import org.matrix.android.sdk.internal.wellknown.WellknownModule
import io.realm.RealmConfiguration
import org.matrix.android.sdk.api.auth.HomeServerHistoryService
import java.io.File

@Module(includes = [WellknownModule::class])
Expand Down Expand Up @@ -82,6 +82,9 @@ internal abstract class AuthModule {
@Binds
abstract fun bindDirectLoginTask(task: DefaultDirectLoginTask): DirectLoginTask

@Binds
abstract fun bindGetVersionTask(task: DefaultIsValidClientServerApiTask): IsValidClientServerApiTask

@Binds
abstract fun bindHomeServerHistoryService(service: DefaultHomeServerHistoryService): HomeServerHistoryService
}
Loading