mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 00:03:46 +01:00
Pull out encrypted_by_default tests from user_directory tests (#10752)
This commit is contained in:
parent
2ca0d64854
commit
5e9b382505
4 changed files with 111 additions and 95 deletions
1
changelog.d/10752.misc
Normal file
1
changelog.d/10752.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Move tests relating to rooms having encryption out of the user_directory tests.
|
1
mypy.ini
1
mypy.ini
|
@ -90,6 +90,7 @@ files =
|
||||||
tests/test_event_auth.py,
|
tests/test_event_auth.py,
|
||||||
tests/test_utils,
|
tests/test_utils,
|
||||||
tests/handlers/test_password_providers.py,
|
tests/handlers/test_password_providers.py,
|
||||||
|
tests/handlers/test_room.py,
|
||||||
tests/handlers/test_room_summary.py,
|
tests/handlers/test_room_summary.py,
|
||||||
tests/handlers/test_send_email.py,
|
tests/handlers/test_send_email.py,
|
||||||
tests/handlers/test_sync.py,
|
tests/handlers/test_sync.py,
|
||||||
|
|
108
tests/handlers/test_room.py
Normal file
108
tests/handlers/test_room.py
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
import synapse
|
||||||
|
from synapse.api.constants import EventTypes, RoomEncryptionAlgorithms
|
||||||
|
from synapse.rest.client import login, room
|
||||||
|
|
||||||
|
from tests import unittest
|
||||||
|
from tests.unittest import override_config
|
||||||
|
|
||||||
|
|
||||||
|
class EncryptedByDefaultTestCase(unittest.HomeserverTestCase):
|
||||||
|
servlets = [
|
||||||
|
login.register_servlets,
|
||||||
|
synapse.rest.admin.register_servlets_for_client_rest_resource,
|
||||||
|
room.register_servlets,
|
||||||
|
]
|
||||||
|
|
||||||
|
@override_config({"encryption_enabled_by_default_for_room_type": "all"})
|
||||||
|
def test_encrypted_by_default_config_option_all(self):
|
||||||
|
"""Tests that invite-only and non-invite-only rooms have encryption enabled by
|
||||||
|
default when the config option encryption_enabled_by_default_for_room_type is "all".
|
||||||
|
"""
|
||||||
|
# Create a user
|
||||||
|
user = self.register_user("user", "pass")
|
||||||
|
user_token = self.login(user, "pass")
|
||||||
|
|
||||||
|
# Create an invite-only room as that user
|
||||||
|
room_id = self.helper.create_room_as(user, is_public=False, tok=user_token)
|
||||||
|
|
||||||
|
# Check that the room has an encryption state event
|
||||||
|
event_content = self.helper.get_state(
|
||||||
|
room_id=room_id,
|
||||||
|
event_type=EventTypes.RoomEncryption,
|
||||||
|
tok=user_token,
|
||||||
|
)
|
||||||
|
self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT})
|
||||||
|
|
||||||
|
# Create a non invite-only room as that user
|
||||||
|
room_id = self.helper.create_room_as(user, is_public=True, tok=user_token)
|
||||||
|
|
||||||
|
# Check that the room has an encryption state event
|
||||||
|
event_content = self.helper.get_state(
|
||||||
|
room_id=room_id,
|
||||||
|
event_type=EventTypes.RoomEncryption,
|
||||||
|
tok=user_token,
|
||||||
|
)
|
||||||
|
self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT})
|
||||||
|
|
||||||
|
@override_config({"encryption_enabled_by_default_for_room_type": "invite"})
|
||||||
|
def test_encrypted_by_default_config_option_invite(self):
|
||||||
|
"""Tests that only new, invite-only rooms have encryption enabled by default when
|
||||||
|
the config option encryption_enabled_by_default_for_room_type is "invite".
|
||||||
|
"""
|
||||||
|
# Create a user
|
||||||
|
user = self.register_user("user", "pass")
|
||||||
|
user_token = self.login(user, "pass")
|
||||||
|
|
||||||
|
# Create an invite-only room as that user
|
||||||
|
room_id = self.helper.create_room_as(user, is_public=False, tok=user_token)
|
||||||
|
|
||||||
|
# Check that the room has an encryption state event
|
||||||
|
event_content = self.helper.get_state(
|
||||||
|
room_id=room_id,
|
||||||
|
event_type=EventTypes.RoomEncryption,
|
||||||
|
tok=user_token,
|
||||||
|
)
|
||||||
|
self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT})
|
||||||
|
|
||||||
|
# Create a non invite-only room as that user
|
||||||
|
room_id = self.helper.create_room_as(user, is_public=True, tok=user_token)
|
||||||
|
|
||||||
|
# Check that the room does not have an encryption state event
|
||||||
|
self.helper.get_state(
|
||||||
|
room_id=room_id,
|
||||||
|
event_type=EventTypes.RoomEncryption,
|
||||||
|
tok=user_token,
|
||||||
|
expect_code=404,
|
||||||
|
)
|
||||||
|
|
||||||
|
@override_config({"encryption_enabled_by_default_for_room_type": "off"})
|
||||||
|
def test_encrypted_by_default_config_option_off(self):
|
||||||
|
"""Tests that neither new invite-only nor non-invite-only rooms have encryption
|
||||||
|
enabled by default when the config option
|
||||||
|
encryption_enabled_by_default_for_room_type is "off".
|
||||||
|
"""
|
||||||
|
# Create a user
|
||||||
|
user = self.register_user("user", "pass")
|
||||||
|
user_token = self.login(user, "pass")
|
||||||
|
|
||||||
|
# Create an invite-only room as that user
|
||||||
|
room_id = self.helper.create_room_as(user, is_public=False, tok=user_token)
|
||||||
|
|
||||||
|
# Check that the room does not have an encryption state event
|
||||||
|
self.helper.get_state(
|
||||||
|
room_id=room_id,
|
||||||
|
event_type=EventTypes.RoomEncryption,
|
||||||
|
tok=user_token,
|
||||||
|
expect_code=404,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a non invite-only room as that user
|
||||||
|
room_id = self.helper.create_room_as(user, is_public=True, tok=user_token)
|
||||||
|
|
||||||
|
# Check that the room does not have an encryption state event
|
||||||
|
self.helper.get_state(
|
||||||
|
room_id=room_id,
|
||||||
|
event_type=EventTypes.RoomEncryption,
|
||||||
|
tok=user_token,
|
||||||
|
expect_code=404,
|
||||||
|
)
|
|
@ -16,7 +16,7 @@ from unittest.mock import Mock
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
import synapse.rest.admin
|
import synapse.rest.admin
|
||||||
from synapse.api.constants import EventTypes, RoomEncryptionAlgorithms, UserTypes
|
from synapse.api.constants import UserTypes
|
||||||
from synapse.api.room_versions import RoomVersion, RoomVersions
|
from synapse.api.room_versions import RoomVersion, RoomVersions
|
||||||
from synapse.rest.client import login, room, user_directory
|
from synapse.rest.client import login, room, user_directory
|
||||||
from synapse.storage.roommember import ProfileInfo
|
from synapse.storage.roommember import ProfileInfo
|
||||||
|
@ -187,100 +187,6 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
|
||||||
s = self.get_success(self.handler.search_users(u1, "user3", 10))
|
s = self.get_success(self.handler.search_users(u1, "user3", 10))
|
||||||
self.assertEqual(len(s["results"]), 0)
|
self.assertEqual(len(s["results"]), 0)
|
||||||
|
|
||||||
@override_config({"encryption_enabled_by_default_for_room_type": "all"})
|
|
||||||
def test_encrypted_by_default_config_option_all(self):
|
|
||||||
"""Tests that invite-only and non-invite-only rooms have encryption enabled by
|
|
||||||
default when the config option encryption_enabled_by_default_for_room_type is "all".
|
|
||||||
"""
|
|
||||||
# Create a user
|
|
||||||
user = self.register_user("user", "pass")
|
|
||||||
user_token = self.login(user, "pass")
|
|
||||||
|
|
||||||
# Create an invite-only room as that user
|
|
||||||
room_id = self.helper.create_room_as(user, is_public=False, tok=user_token)
|
|
||||||
|
|
||||||
# Check that the room has an encryption state event
|
|
||||||
event_content = self.helper.get_state(
|
|
||||||
room_id=room_id,
|
|
||||||
event_type=EventTypes.RoomEncryption,
|
|
||||||
tok=user_token,
|
|
||||||
)
|
|
||||||
self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT})
|
|
||||||
|
|
||||||
# Create a non invite-only room as that user
|
|
||||||
room_id = self.helper.create_room_as(user, is_public=True, tok=user_token)
|
|
||||||
|
|
||||||
# Check that the room has an encryption state event
|
|
||||||
event_content = self.helper.get_state(
|
|
||||||
room_id=room_id,
|
|
||||||
event_type=EventTypes.RoomEncryption,
|
|
||||||
tok=user_token,
|
|
||||||
)
|
|
||||||
self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT})
|
|
||||||
|
|
||||||
@override_config({"encryption_enabled_by_default_for_room_type": "invite"})
|
|
||||||
def test_encrypted_by_default_config_option_invite(self):
|
|
||||||
"""Tests that only new, invite-only rooms have encryption enabled by default when
|
|
||||||
the config option encryption_enabled_by_default_for_room_type is "invite".
|
|
||||||
"""
|
|
||||||
# Create a user
|
|
||||||
user = self.register_user("user", "pass")
|
|
||||||
user_token = self.login(user, "pass")
|
|
||||||
|
|
||||||
# Create an invite-only room as that user
|
|
||||||
room_id = self.helper.create_room_as(user, is_public=False, tok=user_token)
|
|
||||||
|
|
||||||
# Check that the room has an encryption state event
|
|
||||||
event_content = self.helper.get_state(
|
|
||||||
room_id=room_id,
|
|
||||||
event_type=EventTypes.RoomEncryption,
|
|
||||||
tok=user_token,
|
|
||||||
)
|
|
||||||
self.assertEqual(event_content, {"algorithm": RoomEncryptionAlgorithms.DEFAULT})
|
|
||||||
|
|
||||||
# Create a non invite-only room as that user
|
|
||||||
room_id = self.helper.create_room_as(user, is_public=True, tok=user_token)
|
|
||||||
|
|
||||||
# Check that the room does not have an encryption state event
|
|
||||||
self.helper.get_state(
|
|
||||||
room_id=room_id,
|
|
||||||
event_type=EventTypes.RoomEncryption,
|
|
||||||
tok=user_token,
|
|
||||||
expect_code=404,
|
|
||||||
)
|
|
||||||
|
|
||||||
@override_config({"encryption_enabled_by_default_for_room_type": "off"})
|
|
||||||
def test_encrypted_by_default_config_option_off(self):
|
|
||||||
"""Tests that neither new invite-only nor non-invite-only rooms have encryption
|
|
||||||
enabled by default when the config option
|
|
||||||
encryption_enabled_by_default_for_room_type is "off".
|
|
||||||
"""
|
|
||||||
# Create a user
|
|
||||||
user = self.register_user("user", "pass")
|
|
||||||
user_token = self.login(user, "pass")
|
|
||||||
|
|
||||||
# Create an invite-only room as that user
|
|
||||||
room_id = self.helper.create_room_as(user, is_public=False, tok=user_token)
|
|
||||||
|
|
||||||
# Check that the room does not have an encryption state event
|
|
||||||
self.helper.get_state(
|
|
||||||
room_id=room_id,
|
|
||||||
event_type=EventTypes.RoomEncryption,
|
|
||||||
tok=user_token,
|
|
||||||
expect_code=404,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create a non invite-only room as that user
|
|
||||||
room_id = self.helper.create_room_as(user, is_public=True, tok=user_token)
|
|
||||||
|
|
||||||
# Check that the room does not have an encryption state event
|
|
||||||
self.helper.get_state(
|
|
||||||
room_id=room_id,
|
|
||||||
event_type=EventTypes.RoomEncryption,
|
|
||||||
tok=user_token,
|
|
||||||
expect_code=404,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_spam_checker(self):
|
def test_spam_checker(self):
|
||||||
"""
|
"""
|
||||||
A user which fails the spam checks will not appear in search results.
|
A user which fails the spam checks will not appear in search results.
|
||||||
|
|
Loading…
Reference in a new issue