Skip to content

Commit 4db2158

Browse files
committed
Don't return errors when finding rows dependent upon appservice users
1 parent c468250 commit 4db2158

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,
@@ -409,6 +415,9 @@ async fn migrate_devices(
409415
.into_extract_localpart(synapse_user_id.clone())?
410416
.to_owned();
411417
let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else {
418+
if is_likely_appservice(&username) {
419+
continue;
420+
}
412421
return Err(Error::MissingUserFromDependentTable {
413422
table: "devices".to_owned(),
414423
user: synapse_user_id,
@@ -481,6 +490,9 @@ async fn migrate_unrefreshable_access_tokens(
481490
.into_extract_localpart(synapse_user_id.clone())?
482491
.to_owned();
483492
let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else {
493+
if is_likely_appservice(&username) {
494+
continue;
495+
}
484496
return Err(Error::MissingUserFromDependentTable {
485497
table: "access_tokens".to_owned(),
486498
user: synapse_user_id,
@@ -587,6 +599,9 @@ async fn migrate_refreshable_token_pairs(
587599
.into_extract_localpart(synapse_user_id.clone())?
588600
.to_owned();
589601
let Some(user_id) = user_localparts_to_uuid.get(username.as_str()).copied() else {
602+
if is_likely_appservice(&username) {
603+
continue;
604+
}
590605
return Err(Error::MissingUserFromDependentTable {
591606
table: "refresh_tokens".to_owned(),
592607
user: synapse_user_id,
@@ -685,3 +700,15 @@ fn transform_user(
685700

686701
Ok((new_user, mas_password))
687702
}
703+
704+
/// Returns true if and only if the given localpart looks like it would belong
705+
/// to an application service user.
706+
/// The rule here is that it must start with an underscore.
707+
/// Synapse reserves these by default, but there is no hard rule prohibiting other namespaces
708+
/// from being reserved, so this is not a robust check.
709+
// TODO replace with a more robust mechanism, if we even care about this sanity check
710+
// e.g. read application service registration files.
711+
#[inline]
712+
fn is_likely_appservice(localpart: &str) -> bool {
713+
localpart.starts_with('_')
714+
}

0 commit comments

Comments
 (0)