-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Invalid ItemHash did not raise a ValidationError
Problem: Posting invalid item hashes to the `update_allocations` API failed far after the initial validation, with: ``` File "/opt/aleph-vm/aleph_message/models/item_hash.py", line 25, in from_hash raise UnknownHashError(f"Could not determine hash type: '{item_hash}'") aleph_message.exceptions.UnknownHashError: Could not determine hash type: '${{ matrix.check_vm.item_hash }}' ``` Solution: Require ItemHash as part of the `Allocation` schema, in order to fail validation earlier, in the section dedicated to the validation of the uploaded data.
- Loading branch information
Showing
3 changed files
with
31 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
from aiohttp import web | ||
|
||
from aleph.vm.conf import settings | ||
from aleph.vm.orchestrator.supervisor import app | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_allocation_fails_on_invalid_item_hash(aiohttp_client): | ||
"""Test that the allocation endpoint fails when an invalid item_hash is provided.""" | ||
client = await aiohttp_client(app) | ||
settings.ALLOCATION_TOKEN_HASH = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" # = "test" | ||
response: web.Response = await client.post( | ||
"/control/allocations", json={"persistent_vms": ["not-an-ItemHash"]}, headers={"X-Auth-Signature": "test"} | ||
) | ||
assert response.status == 400 | ||
assert await response.json() == [ | ||
{ | ||
"loc": [ | ||
"persistent_vms", | ||
0, | ||
], | ||
"msg": "Could not determine hash type: 'not-an-ItemHash'", | ||
"type": "value_error.unknownhash", | ||
}, | ||
] |