Skip to content

Commit 22d9485

Browse files
authored
[Messages] Check the presence of all fields (#270)
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.
1 parent 1b81071 commit 22d9485

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/aleph/network.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ async def check_message(
7777
if not message:
7878
raise InvalidMessageError("Message must not be empty")
7979

80-
if "item_hash" not in message:
81-
raise InvalidMessageError("Missing field 'item_hash' in message")
82-
for field in ("chain", "sender", "signature"):
80+
for field in INCOMING_MESSAGE_AUTHORIZED_FIELDS:
8381
if field not in message:
8482
raise InvalidMessageError(
8583
f"Missing field '{field}' in message {message['item_hash']}"

tests/api/test_messages.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,9 @@ async def fetch_messages_by_channel(channel: str) -> Dict:
9393

9494

9595
@pytest.mark.asyncio
96-
async def test_get_messages_filter_by_chain(fixture_messages, aiohttp_client):
97-
app = create_app()
98-
client = await aiohttp_client(app)
99-
96+
async def test_get_messages_filter_by_chain(fixture_messages, ccn_api_client):
10097
async def fetch_messages_by_chain(chain: str) -> Dict:
101-
response = await client.get(MESSAGES_URI, params={"chains": chain})
98+
response = await ccn_api_client.get(MESSAGES_URI, params={"chains": chain})
10299
assert response.status == 200, await response.text()
103100
return await response.json()
104101

@@ -114,12 +111,9 @@ async def fetch_messages_by_chain(chain: str) -> Dict:
114111

115112

116113
@pytest.mark.asyncio
117-
async def test_get_messages_filter_by_content_hash(fixture_messages, aiohttp_client):
118-
app = create_app()
119-
client = await aiohttp_client(app)
120-
114+
async def test_get_messages_filter_by_content_hash(fixture_messages, ccn_api_client):
121115
async def fetch_messages_by_content_hash(item_hash: str) -> Dict:
122-
response = await client.get(MESSAGES_URI, params={"contentHashes": item_hash})
116+
response = await ccn_api_client.get(MESSAGES_URI, params={"contentHashes": item_hash})
123117
assert response.status == 200, await response.text()
124118
return await response.json()
125119

0 commit comments

Comments
 (0)