Merge pull request #3965 from ostcar/fix_change_id_on_connection

Fix error on to big change id on websocket connection
This commit is contained in:
Finn Stutzenstein 2018-11-02 07:48:24 +01:00 committed by GitHub
commit 0b1d11f03f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -41,9 +41,15 @@ class SiteConsumer(ProtocollAsyncJsonWebsocketConsumer):
await self.channel_layer.group_add('autoupdate', self.channel_name)
await self.accept()
if change_id is not None:
data = await get_element_data(self.scope['user'], change_id)
await self.send_json(type='autoupdate', content=data)
try:
data = await get_element_data(self.scope['user'], change_id)
except ValueError:
# When the change_id is to big, do nothing
pass
else:
await self.send_json(type='autoupdate', content=data)
async def disconnect(self, close_code: int) -> None:
"""

View File

@ -101,6 +101,17 @@ async def test_connection_with_invalid_change_id(get_communicator):
assert connected is False
@pytest.mark.asyncio
async def test_connection_with_to_big_change_id(get_communicator):
await set_config('general_system_enable_anonymous', True)
communicator = get_communicator('change_id=1000000000000')
connected, __ = await communicator.connect()
assert connected is True
assert await communicator.receive_nothing()
@pytest.mark.asyncio
async def test_changed_data_autoupdate_off(communicator):
await set_config('general_system_enable_anonymous', True)