Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
WIP: Oops, that test shouldn't have been changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoric committed May 25, 2022
1 parent 4d4783e commit 8e91608
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions tests/handlers/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Tuple, Union
from typing import Tuple
from unittest.mock import Mock, patch
from urllib.parse import quote

from twisted.test.proto_helpers import MemoryReactor

import synapse.rest.admin
from synapse.api.constants import UserTypes
from synapse.api.errors import Codes
from synapse.api.room_versions import RoomVersion, RoomVersions
from synapse.appservice import ApplicationService
from synapse.rest.client import login, register, room, user_directory
from synapse.server import HomeServer
from synapse.spam_checker_api import Allow
from synapse.storage.roommember import ProfileInfo
from synapse.types import create_requester
from synapse.util import Clock
Expand Down Expand Up @@ -775,24 +773,11 @@ def test_spam_checker(self) -> None:
s = self.get_success(self.handler.search_users(u1, "user2", 10))
self.assertEqual(len(s["results"]), 1)

async def allow_all_deprecated(user_profile: ProfileInfo) -> bool:
# Allow all users, deprecated API.
return False

# Configure a spam checker that does not filter any users (deprecated API).
spam_checker = self.hs.get_spam_checker()
spam_checker._check_username_for_spam_callbacks = [allow_all_deprecated]

async def allow_all(user_profile: ProfileInfo) -> Union[Allow, Codes]:
async def allow_all(user_profile: ProfileInfo) -> bool:
# Allow all users.
return Allow.ALLOW

# The results do not change:
# We get one search result when searching for user2 by user1.
s = self.get_success(self.handler.search_users(u1, "user2", 10))
self.assertEqual(len(s["results"]), 1)
return False

# Configure a spam checker that does not filter any users (deprecated API).
# Configure a spam checker that does not filter any users.
spam_checker = self.hs.get_spam_checker()
spam_checker._check_username_for_spam_callbacks = [allow_all]

Expand All @@ -802,21 +787,10 @@ async def allow_all(user_profile: ProfileInfo) -> Union[Allow, Codes]:
self.assertEqual(len(s["results"]), 1)

# Configure a spam checker that filters all users.
async def block_all_deprecated(user_profile: ProfileInfo) -> bool:
async def block_all(user_profile: ProfileInfo) -> bool:
# All users are spammy.
return True

spam_checker._check_username_for_spam_callbacks = [block_all_deprecated]

# User1 now gets no search results for any of the other users.
s = self.get_success(self.handler.search_users(u1, "user2", 10))
self.assertEqual(len(s["results"]), 0)

# Configure a spam checker that filters all users.
async def block_all(user_profile: ProfileInfo) -> Union[Allow, Codes]:
# All users are spammy.
return Codes.CONSENT_NOT_GIVEN

spam_checker._check_username_for_spam_callbacks = [block_all]

# User1 now gets no search results for any of the other users.
Expand Down

0 comments on commit 8e91608

Please sign in to comment.