@@ -255,6 +255,9 @@ async fn migrate_threepids(
255
255
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
256
256
. to_owned ( ) ;
257
257
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
258
+ if is_likely_appservice ( & username) {
259
+ continue ;
260
+ }
258
261
return Err ( Error :: MissingUserFromDependentTable {
259
262
table : "user_threepids" . to_owned ( ) ,
260
263
user : synapse_user_id,
@@ -332,6 +335,9 @@ async fn migrate_external_ids(
332
335
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
333
336
. to_owned ( ) ;
334
337
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
338
+ if is_likely_appservice ( & username) {
339
+ continue ;
340
+ }
335
341
return Err ( Error :: MissingUserFromDependentTable {
336
342
table : "user_external_ids" . to_owned ( ) ,
337
343
user : synapse_user_id,
@@ -410,6 +416,9 @@ async fn migrate_devices(
410
416
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
411
417
. to_owned ( ) ;
412
418
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
419
+ if is_likely_appservice ( & username) {
420
+ continue ;
421
+ }
413
422
return Err ( Error :: MissingUserFromDependentTable {
414
423
table : "devices" . to_owned ( ) ,
415
424
user : synapse_user_id,
@@ -482,6 +491,9 @@ async fn migrate_unrefreshable_access_tokens(
482
491
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
483
492
. to_owned ( ) ;
484
493
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
494
+ if is_likely_appservice ( & username) {
495
+ continue ;
496
+ }
485
497
return Err ( Error :: MissingUserFromDependentTable {
486
498
table : "access_tokens" . to_owned ( ) ,
487
499
user : synapse_user_id,
@@ -589,6 +601,9 @@ async fn migrate_refreshable_token_pairs(
589
601
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
590
602
. to_owned ( ) ;
591
603
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
604
+ if is_likely_appservice ( & username) {
605
+ continue ;
606
+ }
592
607
return Err ( Error :: MissingUserFromDependentTable {
593
608
table : "refresh_tokens" . to_owned ( ) ,
594
609
user : synapse_user_id,
@@ -688,3 +703,15 @@ fn transform_user(
688
703
689
704
Ok ( ( new_user, mas_password) )
690
705
}
706
+
707
+ /// Returns true if and only if the given localpart looks like it would belong
708
+ /// to an application service user.
709
+ /// The rule here is that it must start with an underscore.
710
+ /// Synapse reserves these by default, but there is no hard rule prohibiting
711
+ /// other namespaces from being reserved, so this is not a robust check.
712
+ // TODO replace with a more robust mechanism, if we even care about this sanity check
713
+ // e.g. read application service registration files.
714
+ #[ inline]
715
+ fn is_likely_appservice ( localpart : & str ) -> bool {
716
+ localpart. starts_with ( '_' )
717
+ }
0 commit comments