From 587298f7e607bad323cf6bd93d1a064370f6dfb3 Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Sun, 15 May 2022 23:26:49 +0200 Subject: [PATCH 1/3] [Messages] Check the presence of all fields Broadened the check of fields in new messages. We now check for the presence of all the authorized fields, as parts of the code expect them later anyway. This fixes an issue detected on Sentry where the missing "time" field on some messages triggered an exception. --- src/aleph/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aleph/network.py b/src/aleph/network.py index fce2b79a9..13a9e0b24 100644 --- a/src/aleph/network.py +++ b/src/aleph/network.py @@ -79,7 +79,7 @@ async def check_message( if "item_hash" not in message: raise InvalidMessageError("Missing field 'item_hash' in message") - for field in ("chain", "sender", "signature"): + for field in INCOMING_MESSAGE_AUTHORIZED_FIELDS: if field not in message: raise InvalidMessageError( f"Missing field '{field}' in message {message['item_hash']}" From efc57794569331bfb9b6bcdca72dcc203c050752 Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Tue, 24 May 2022 11:17:37 +0200 Subject: [PATCH 2/3] fix for review --- src/aleph/network.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/aleph/network.py b/src/aleph/network.py index 13a9e0b24..5f0a55b62 100644 --- a/src/aleph/network.py +++ b/src/aleph/network.py @@ -77,8 +77,6 @@ async def check_message( if not message: raise InvalidMessageError("Message must not be empty") - if "item_hash" not in message: - raise InvalidMessageError("Missing field 'item_hash' in message") for field in INCOMING_MESSAGE_AUTHORIZED_FIELDS: if field not in message: raise InvalidMessageError( From 9fedf2417249d1b12ce658e9c01724d57cfdd470 Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Tue, 24 May 2022 11:42:04 +0200 Subject: [PATCH 3/3] rebase fixes --- tests/api/test_messages.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/api/test_messages.py b/tests/api/test_messages.py index 8ce5f722b..ad9a07f7a 100644 --- a/tests/api/test_messages.py +++ b/tests/api/test_messages.py @@ -93,12 +93,9 @@ async def fetch_messages_by_channel(channel: str) -> Dict: @pytest.mark.asyncio -async def test_get_messages_filter_by_chain(fixture_messages, aiohttp_client): - app = create_app() - client = await aiohttp_client(app) - +async def test_get_messages_filter_by_chain(fixture_messages, ccn_api_client): async def fetch_messages_by_chain(chain: str) -> Dict: - response = await client.get(MESSAGES_URI, params={"chains": chain}) + response = await ccn_api_client.get(MESSAGES_URI, params={"chains": chain}) assert response.status == 200, await response.text() return await response.json() @@ -114,12 +111,9 @@ async def fetch_messages_by_chain(chain: str) -> Dict: @pytest.mark.asyncio -async def test_get_messages_filter_by_content_hash(fixture_messages, aiohttp_client): - app = create_app() - client = await aiohttp_client(app) - +async def test_get_messages_filter_by_content_hash(fixture_messages, ccn_api_client): async def fetch_messages_by_content_hash(item_hash: str) -> Dict: - response = await client.get(MESSAGES_URI, params={"contentHashes": item_hash}) + response = await ccn_api_client.get(MESSAGES_URI, params={"contentHashes": item_hash}) assert response.status == 200, await response.text() return await response.json()