@@ -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,
@@ -499,6 +508,9 @@ async fn migrate_unrefreshable_access_tokens(
499
508
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
500
509
. to_owned ( ) ;
501
510
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
511
+ if is_likely_appservice ( & username) {
512
+ continue ;
513
+ }
502
514
return Err ( Error :: MissingUserFromDependentTable {
503
515
table : "access_tokens" . to_owned ( ) ,
504
516
user : synapse_user_id,
@@ -606,6 +618,9 @@ async fn migrate_refreshable_token_pairs(
606
618
. into_extract_localpart ( synapse_user_id. clone ( ) ) ?
607
619
. to_owned ( ) ;
608
620
let Some ( user_id) = user_localparts_to_uuid. get ( username. as_str ( ) ) . copied ( ) else {
621
+ if is_likely_appservice ( & username) {
622
+ continue ;
623
+ }
609
624
return Err ( Error :: MissingUserFromDependentTable {
610
625
table : "refresh_tokens" . to_owned ( ) ,
611
626
user : synapse_user_id,
@@ -705,3 +720,15 @@ fn transform_user(
705
720
706
721
Ok ( ( new_user, mas_password) )
707
722
}
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