From 7181cc82d5d0f31b35b2a55963fad3e4733ff9e8 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Thu, 30 Jan 2025 17:42:22 +0000 Subject: [PATCH] Don't return errors when finding rows dependent upon appservice users --- crates/syn2mas/src/migration.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/syn2mas/src/migration.rs b/crates/syn2mas/src/migration.rs index dff034ca9..f46586c03 100644 --- a/crates/syn2mas/src/migration.rs +++ b/crates/syn2mas/src/migration.rs @@ -255,6 +255,9 @@ async fn migrate_threepids( .into_extract_localpart(synapse_user_id.clone())? .to_owned(); let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else { + if is_likely_appservice(&username) { + continue; + } return Err(Error::MissingUserFromDependentTable { table: "user_threepids".to_owned(), user: synapse_user_id, @@ -332,6 +335,9 @@ async fn migrate_external_ids( .into_extract_localpart(synapse_user_id.clone())? .to_owned(); let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else { + if is_likely_appservice(&username) { + continue; + } return Err(Error::MissingUserFromDependentTable { table: "user_external_ids".to_owned(), user: synapse_user_id, @@ -410,6 +416,9 @@ async fn migrate_devices( .into_extract_localpart(synapse_user_id.clone())? .to_owned(); let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else { + if is_likely_appservice(&username) { + continue; + } return Err(Error::MissingUserFromDependentTable { table: "devices".to_owned(), user: synapse_user_id, @@ -499,6 +508,9 @@ async fn migrate_unrefreshable_access_tokens( .into_extract_localpart(synapse_user_id.clone())? .to_owned(); let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else { + if is_likely_appservice(&username) { + continue; + } return Err(Error::MissingUserFromDependentTable { table: "access_tokens".to_owned(), user: synapse_user_id, @@ -606,6 +618,9 @@ async fn migrate_refreshable_token_pairs( .into_extract_localpart(synapse_user_id.clone())? .to_owned(); let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else { + if is_likely_appservice(&username) { + continue; + } return Err(Error::MissingUserFromDependentTable { table: "refresh_tokens".to_owned(), user: synapse_user_id, @@ -705,3 +720,15 @@ fn transform_user( Ok((new_user, mas_password)) } + +/// Returns true if and only if the given localpart looks like it would belong +/// to an application service user. +/// The rule here is that it must start with an underscore. +/// Synapse reserves these by default, but there is no hard rule prohibiting +/// other namespaces from being reserved, so this is not a robust check. +// TODO replace with a more robust mechanism, if we even care about this sanity check +// e.g. read application service registration files. +#[inline] +fn is_likely_appservice(localpart: &str) -> bool { + localpart.starts_with('_') +}