From e6185b3827727e7e715f489e44c501dbdf4db2a8 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 4 Jun 2024 14:04:33 +0200 Subject: [PATCH] authentication service(ffi): don't set the base_path for the temporary discovery client Following https://github.com/matrix-org/matrix-rust-sdk/pull/3473, we made it so that if there's a base-path but no username, then we'll create a sqlite database. Unfortunately, this introduced a bad side-effect: for the temporary client used during homeserver resolution, this would create a temporary sqlite database. The "fix" is to not set the base path for the temporary client, and only for the other caller of `new_client_builder()`, manually. The long term fix is to get rid of the `AuthenticationService` so we can test it properly. --- .../src/authentication_service.rs | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/authentication_service.rs b/bindings/matrix-sdk-ffi/src/authentication_service.rs index 62e8daf06..fd4591671 100644 --- a/bindings/matrix-sdk-ffi/src/authentication_service.rs +++ b/bindings/matrix-sdk-ffi/src/authentication_service.rs @@ -264,7 +264,7 @@ impl AuthenticationService { builder = builder.server_name_or_homeserver_url(server_name_or_homeserver_url); let client = builder.build_inner().await?; - let details = self.details_from_client(&client).await?; + let details = self.details_from_client(&client).await; // Make sure there's a sliding sync proxy available. if self.custom_sliding_sync_proxy.read().unwrap().is_none() @@ -403,10 +403,12 @@ impl AuthenticationService { } impl AuthenticationService { - /// A new client builder pre-configured with the service's base path and - /// user agent if specified + /// Create a new client builder pre-configured with the service's HTTP + /// configuration if needed. + /// + /// Note: this client doesn't set the base path by default. fn new_client_builder(&self) -> Arc { - let mut builder = ClientBuilder::new().base_path(self.base_path.clone()); + let mut builder = ClientBuilder::new(); if let Some(user_agent) = self.user_agent.clone() { builder = builder.user_agent(user_agent); @@ -422,21 +424,18 @@ impl AuthenticationService { } /// Get the homeserver login details from a client. - async fn details_from_client( - &self, - client: &Client, - ) -> Result { + async fn details_from_client(&self, client: &Client) -> HomeserverLoginDetails { let supports_oidc_login = client.inner.oidc().fetch_authentication_issuer().await.is_ok(); let supports_password_login = client.supports_password_login().await.ok().unwrap_or(false); let sliding_sync_proxy = client.sliding_sync_proxy().map(|proxy_url| proxy_url.to_string()); let url = client.homeserver(); - Ok(HomeserverLoginDetails { + HomeserverLoginDetails { url, sliding_sync_proxy, supports_oidc_login, supports_password_login, - }) + } } /// Handle any necessary configuration in order for login via OIDC to @@ -590,6 +589,7 @@ impl AuthenticationService { // Construct the final client. let mut client = self .new_client_builder() + .base_path(self.base_path.clone()) .passphrase(self.passphrase.clone()) .homeserver_url(homeserver_url) .sliding_sync_proxy(sliding_sync_proxy) @@ -598,10 +598,6 @@ impl AuthenticationService { .auto_enable_backups(true) .username(user_id.to_string()); - if let Some(proxy) = &self.proxy { - client = client.proxy(proxy.to_owned()) - } - if let Some(id) = &self.cross_process_refresh_lock_id { let Some(ref session_delegate) = self.session_delegate else { return Err(AuthenticationError::OidcError {