Test for Oidc

This commit is contained in:
Benoit Marty 2023-04-20 21:15:46 +02:00
parent 9551a5e6f8
commit f8dbd31c11
9 changed files with 365 additions and 24 deletions

View file

@ -51,25 +51,27 @@ class OidcPresenter @AssistedInject constructor(
fun handleCancel() {
requestState = Async.Loading()
localCoroutineScope.launch {
requestState = try {
authenticationService.cancelOidcLogin()
// Then go back
Async.Success(Unit)
} catch (throwable: Throwable) {
Async.Failure(throwable)
}
authenticationService.cancelOidcLogin()
.fold(
onSuccess = {
// Then go back
requestState = Async.Success(Unit)
},
onFailure = {
requestState = Async.Failure(it)
}
)
}
}
fun handleSuccess(url: String) {
requestState = Async.Loading()
localCoroutineScope.launch {
try {
authenticationService.loginWithOidc(url)
// Then the node tree will be updated, there is nothing to do
} catch (throwable: Throwable) {
requestState = Async.Failure(throwable)
}
authenticationService.loginWithOidc(url)
.onFailure {
requestState = Async.Failure(it)
}
// On success, the node tree will be updated, there is nothing to do
}
}

View file

@ -32,7 +32,7 @@ class OidcUrlParser {
* Return a OidcAction, or null if the url is not a OidcUrl
*/
fun parse(url: String): OidcAction? {
if (!url.startsWith(OidcConfig.redirectUri)) return null
if (url.startsWith(OidcConfig.redirectUri).not()) return null
if (url.contains("error=access_denied")) return OidcAction.GoBack
if (url.contains("code=")) return OidcAction.Success(url)

View file

@ -97,10 +97,12 @@ class LoginRootPresenter @Inject constructor(
homeserver: String,
state: MutableState<Async<MatrixHomeServerDetails>>,
) = launch {
state.value = Async.Loading()
suspend {
authenticationService.setHomeserver(homeserver)
authenticationService.getHomeserverDetails().value!!
.map {
authenticationService.getHomeserverDetails().value!!
}
.getOrThrow()
}.execute(state)
}