diff --git a/tests/handlers/test_e2e_keys.py b/tests/handlers/test_e2e_keys.py
index f0723892e4..ddcf3ee348 100644
--- a/tests/handlers/test_e2e_keys.py
+++ b/tests/handlers/test_e2e_keys.py
@@ -161,8 +161,9 @@ class E2eKeysHandlerTestCase(unittest.HomeserverTestCase):
def test_fallback_key(self):
local_user = "@boris:" + self.hs.hostname
device_id = "xyz"
- fallback_key = {"alg1:k1": "key1"}
- fallback_key2 = {"alg1:k2": "key2"}
+ fallback_key = {"alg1:k1": "fallback_key1"}
+ fallback_key2 = {"alg1:k2": "fallback_key2"}
+ fallback_key3 = {"alg1:k2": "fallback_key3"}
otk = {"alg1:k2": "key2"}
# we shouldn't have any unused fallback keys yet
@@ -175,7 +176,7 @@ class E2eKeysHandlerTestCase(unittest.HomeserverTestCase):
self.handler.upload_keys_for_user(
local_user,
device_id,
- {"org.matrix.msc2732.fallback_keys": fallback_key},
+ {"fallback_keys": fallback_key},
)
)
@@ -220,7 +221,7 @@ class E2eKeysHandlerTestCase(unittest.HomeserverTestCase):
self.handler.upload_keys_for_user(
local_user,
device_id,
- {"org.matrix.msc2732.fallback_keys": fallback_key},
+ {"fallback_keys": fallback_key},
)
)
@@ -234,7 +235,7 @@ class E2eKeysHandlerTestCase(unittest.HomeserverTestCase):
self.handler.upload_keys_for_user(
local_user,
device_id,
- {"org.matrix.msc2732.fallback_keys": fallback_key2},
+ {"fallback_keys": fallback_key2},
)
)
@@ -271,6 +272,25 @@ class E2eKeysHandlerTestCase(unittest.HomeserverTestCase):
{"failures": {}, "one_time_keys": {local_user: {device_id: fallback_key2}}},
)
+ # using the unstable prefix should also set the fallback key
+ self.get_success(
+ self.handler.upload_keys_for_user(
+ local_user,
+ device_id,
+ {"org.matrix.msc2732.fallback_keys": fallback_key3},
+ )
+ )
+
+ res = self.get_success(
+ self.handler.claim_one_time_keys(
+ {"one_time_keys": {local_user: {device_id: "alg1"}}}, timeout=None
+ )
+ )
+ self.assertEqual(
+ res,
+ {"failures": {}, "one_time_keys": {local_user: {device_id: fallback_key3}}},
+ )
+
def test_replace_master_key(self):
"""uploading a new signing key should make the old signing key unavailable"""
local_user = "@boris:" + self.hs.hostname
diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py
index e1557566e4..496b581726 100644
--- a/tests/handlers/test_federation.py
+++ b/tests/handlers/test_federation.py
@@ -373,9 +373,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
destination: str, room_id: str, event_id: str
) -> List[EventBase]:
return [
- event_from_pdu_json(
- ae.get_pdu_json(), room_version=room_version, outlier=True
- )
+ event_from_pdu_json(ae.get_pdu_json(), room_version=room_version)
for ae in auth_events
]
diff --git a/tests/handlers/test_message.py b/tests/handlers/test_message.py
index 8a8d369fac..5816295d8b 100644
--- a/tests/handlers/test_message.py
+++ b/tests/handlers/test_message.py
@@ -23,6 +23,7 @@ from synapse.types import create_requester
from synapse.util.stringutils import random_string
from tests import unittest
+from tests.test_utils.event_injection import create_event
logger = logging.getLogger(__name__)
@@ -51,6 +52,24 @@ class EventCreationTestCase(unittest.HomeserverTestCase):
self.requester = create_requester(self.user_id, access_token_id=self.token_id)
+ def _create_and_persist_member_event(self) -> Tuple[EventBase, EventContext]:
+ # Create a member event we can use as an auth_event
+ memberEvent, memberEventContext = self.get_success(
+ create_event(
+ self.hs,
+ room_id=self.room_id,
+ type="m.room.member",
+ sender=self.requester.user.to_string(),
+ state_key=self.requester.user.to_string(),
+ content={"membership": "join"},
+ )
+ )
+ self.get_success(
+ self.persist_event_storage.persist_event(memberEvent, memberEventContext)
+ )
+
+ return memberEvent, memberEventContext
+
def _create_duplicate_event(self, txn_id: str) -> Tuple[EventBase, EventContext]:
"""Create a new event with the given transaction ID. All events produced
by this method will be considered duplicates.
@@ -156,6 +175,90 @@ class EventCreationTestCase(unittest.HomeserverTestCase):
self.assertEqual(len(events), 2)
self.assertEqual(events[0].event_id, events[1].event_id)
+ def test_when_empty_prev_events_allowed_create_event_with_empty_prev_events(self):
+ """When we set allow_no_prev_events=True, should be able to create a
+ event without any prev_events (only auth_events).
+ """
+ # Create a member event we can use as an auth_event
+ memberEvent, _ = self._create_and_persist_member_event()
+
+ # Try to create the event with empty prev_events bit with some auth_events
+ event, _ = self.get_success(
+ self.handler.create_event(
+ self.requester,
+ {
+ "type": EventTypes.Message,
+ "room_id": self.room_id,
+ "sender": self.requester.user.to_string(),
+ "content": {"msgtype": "m.text", "body": random_string(5)},
+ },
+ # Empty prev_events is the key thing we're testing here
+ prev_event_ids=[],
+ # But with some auth_events
+ auth_event_ids=[memberEvent.event_id],
+ # Allow no prev_events!
+ allow_no_prev_events=True,
+ )
+ )
+ self.assertIsNotNone(event)
+
+ def test_when_empty_prev_events_not_allowed_reject_event_with_empty_prev_events(
+ self,
+ ):
+ """When we set allow_no_prev_events=False, shouldn't be able to create a
+ event without any prev_events even if it has auth_events. Expect an
+ exception to be raised.
+ """
+ # Create a member event we can use as an auth_event
+ memberEvent, _ = self._create_and_persist_member_event()
+
+ # Try to create the event with empty prev_events but with some auth_events
+ self.get_failure(
+ self.handler.create_event(
+ self.requester,
+ {
+ "type": EventTypes.Message,
+ "room_id": self.room_id,
+ "sender": self.requester.user.to_string(),
+ "content": {"msgtype": "m.text", "body": random_string(5)},
+ },
+ # Empty prev_events is the key thing we're testing here
+ prev_event_ids=[],
+ # But with some auth_events
+ auth_event_ids=[memberEvent.event_id],
+ # We expect the test to fail because empty prev_events are not
+ # allowed here!
+ allow_no_prev_events=False,
+ ),
+ AssertionError,
+ )
+
+ def test_when_empty_prev_events_allowed_reject_event_with_empty_prev_events_and_auth_events(
+ self,
+ ):
+ """When we set allow_no_prev_events=True, should be able to create a
+ event without any prev_events or auth_events. Expect an exception to be
+ raised.
+ """
+ # Try to create the event with empty prev_events and empty auth_events
+ self.get_failure(
+ self.handler.create_event(
+ self.requester,
+ {
+ "type": EventTypes.Message,
+ "room_id": self.room_id,
+ "sender": self.requester.user.to_string(),
+ "content": {"msgtype": "m.text", "body": random_string(5)},
+ },
+ prev_event_ids=[],
+ # The event should be rejected when there are no auth_events
+ auth_event_ids=[],
+ # Allow no prev_events!
+ allow_no_prev_events=True,
+ ),
+ AssertionError,
+ )
+
class ServerAclValidationTestCase(unittest.HomeserverTestCase):
servlets = [
|