@@ -796,6 +796,7 @@ def test_spam_checker(self) -> None:
796796 s = self .get_success (self .handler .search_users (u1 , "user2" , 10 ))
797797 self .assertEqual (len (s ["results" ]), 1 )
798798
799+ # Kept old spam checker without `requester_id` tests for backwards compatibility.
799800 async def allow_all (user_profile : UserProfile ) -> bool :
800801 # Allow all users.
801802 return False
@@ -809,6 +810,7 @@ async def allow_all(user_profile: UserProfile) -> bool:
809810 s = self .get_success (self .handler .search_users (u1 , "user2" , 10 ))
810811 self .assertEqual (len (s ["results" ]), 1 )
811812
813+ # Kept old spam checker without `requester_id` tests for backwards compatibility.
812814 # Configure a spam checker that filters all users.
813815 async def block_all (user_profile : UserProfile ) -> bool :
814816 # All users are spammy.
@@ -820,6 +822,40 @@ async def block_all(user_profile: UserProfile) -> bool:
820822 s = self .get_success (self .handler .search_users (u1 , "user2" , 10 ))
821823 self .assertEqual (len (s ["results" ]), 0 )
822824
825+ async def allow_all_expects_requester_id (
826+ user_profile : UserProfile , requester_id : str
827+ ) -> bool :
828+ self .assertEqual (requester_id , u1 )
829+ # Allow all users.
830+ return False
831+
832+ # Configure a spam checker that does not filter any users.
833+ spam_checker = self .hs .get_module_api_callbacks ().spam_checker
834+ spam_checker ._check_username_for_spam_callbacks = [
835+ allow_all_expects_requester_id
836+ ]
837+
838+ # The results do not change:
839+ # We get one search result when searching for user2 by user1.
840+ s = self .get_success (self .handler .search_users (u1 , "user2" , 10 ))
841+ self .assertEqual (len (s ["results" ]), 1 )
842+
843+ # Configure a spam checker that filters all users.
844+ async def block_all_expects_requester_id (
845+ user_profile : UserProfile , requester_id : str
846+ ) -> bool :
847+ self .assertEqual (requester_id , u1 )
848+ # All users are spammy.
849+ return True
850+
851+ spam_checker ._check_username_for_spam_callbacks = [
852+ block_all_expects_requester_id
853+ ]
854+
855+ # User1 now gets no search results for any of the other users.
856+ s = self .get_success (self .handler .search_users (u1 , "user2" , 10 ))
857+ self .assertEqual (len (s ["results" ]), 0 )
858+
823859 @override_config (
824860 {
825861 "spam_checker" : {
0 commit comments