Skip to content

Commit 7181cc8

Browse files
reivilibresandhose
authored andcommitted
Don't return errors when finding rows dependent upon appservice users
1 parent b7bb27b commit 7181cc8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

crates/syn2mas/src/migration.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ async fn migrate_threepids(
255255
.into_extract_localpart(synapse_user_id.clone())?
256256
.to_owned();
257257
let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else {
258+
if is_likely_appservice(&username) {
259+
continue;
260+
}
258261
return Err(Error::MissingUserFromDependentTable {
259262
table: "user_threepids".to_owned(),
260263
user: synapse_user_id,
@@ -332,6 +335,9 @@ async fn migrate_external_ids(
332335
.into_extract_localpart(synapse_user_id.clone())?
333336
.to_owned();
334337
let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else {
338+
if is_likely_appservice(&username) {
339+
continue;
340+
}
335341
return Err(Error::MissingUserFromDependentTable {
336342
table: "user_external_ids".to_owned(),
337343
user: synapse_user_id,
@@ -410,6 +416,9 @@ async fn migrate_devices(
410416
.into_extract_localpart(synapse_user_id.clone())?
411417
.to_owned();
412418
let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else {
419+
if is_likely_appservice(&username) {
420+
continue;
421+
}
413422
return Err(Error::MissingUserFromDependentTable {
414423
table: "devices".to_owned(),
415424
user: synapse_user_id,
@@ -499,6 +508,9 @@ async fn migrate_unrefreshable_access_tokens(
499508
.into_extract_localpart(synapse_user_id.clone())?
500509
.to_owned();
501510
let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else {
511+
if is_likely_appservice(&username) {
512+
continue;
513+
}
502514
return Err(Error::MissingUserFromDependentTable {
503515
table: "access_tokens".to_owned(),
504516
user: synapse_user_id,
@@ -606,6 +618,9 @@ async fn migrate_refreshable_token_pairs(
606618
.into_extract_localpart(synapse_user_id.clone())?
607619
.to_owned();
608620
let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else {
621+
if is_likely_appservice(&username) {
622+
continue;
623+
}
609624
return Err(Error::MissingUserFromDependentTable {
610625
table: "refresh_tokens".to_owned(),
611626
user: synapse_user_id,
@@ -705,3 +720,15 @@ fn transform_user(
705720

706721
Ok((new_user, mas_password))
707722
}
723+
724+
/// Returns true if and only if the given localpart looks like it would belong
725+
/// to an application service user.
726+
/// The rule here is that it must start with an underscore.
727+
/// Synapse reserves these by default, but there is no hard rule prohibiting
728+
/// other namespaces from being reserved, so this is not a robust check.
729+
// TODO replace with a more robust mechanism, if we even care about this sanity check
730+
// e.g. read application service registration files.
731+
#[inline]
732+
fn is_likely_appservice(localpart: &str) -> bool {
733+
localpart.starts_with('_')
734+
}

0 commit comments

Comments
 (0)