Add an assertion on prev_events in create_new_client_event (#8041)

I think this would have caught all the cases in
https://github.com/matrix-org/synapse/issues/7642 - and I think a 500 makes
more sense here than a 403
This commit is contained in:
Richard van der Hoff 2020-08-10 12:29:47 +01:00 committed by GitHub
parent cdbb8e6d6e
commit fcbab08cbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

1
changelog.d/8041.misc Normal file
View File

@ -0,0 +1 @@
Add an assertion on prev_events in create_new_client_event.

View File

@ -768,6 +768,15 @@ class EventCreationHandler(object):
else: else:
prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id) prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
# we now ought to have some prev_events (unless it's a create event).
#
# do a quick sanity check here, rather than waiting until we've created the
# event and then try to auth it (which fails with a somewhat confusing "No
# create event in auth events")
assert (
builder.type == EventTypes.Create or len(prev_event_ids) > 0
), "Attempting to create an event with no prev_events"
event = await builder.build(prev_event_ids=prev_event_ids) event = await builder.build(prev_event_ids=prev_event_ids)
context = await self.state.compute_event_context(event) context = await self.state.compute_event_context(event)
if requester: if requester:

View File

@ -251,6 +251,10 @@ class RedactionTestCase(unittest.HomeserverTestCase):
def room_id(self): def room_id(self):
return self._base_builder.room_id return self._base_builder.room_id
@property
def type(self):
return self._base_builder.type
event_1, context_1 = self.get_success( event_1, context_1 = self.get_success(
self.event_creation_handler.create_new_client_event( self.event_creation_handler.create_new_client_event(
EventIdManglingBuilder( EventIdManglingBuilder(