Merge pull request 'Only presign and accept images in the caller's own conversations' (#81) from fix/image-ownership into main
CI / backend (push) Successful in 42s
CI / frontend (push) Failing after 7s

This commit was merged in pull request #81.
This commit is contained in:
2026-10-13 07:53:05 -04:00
2 changed files with 61 additions and 0 deletions
+42
View File
@@ -301,3 +301,45 @@ class TestStreamQueryFileKey:
f"conversations/{CONV_ID}/files/u.txt"
)
assert name == "u.txt"
class TestImageOwnership:
async def test_presigns_only_keys_in_owned_conversations(self, app, headers, s3):
presign = AsyncMock(return_value="https://s3.example/signed")
with patch.object(conv, "s3_presigned_url", presign):
client = app.test_client()
own = await client.get(
f"/api/conversation/image/conversations/{CONV_ID}/a.jpg",
headers=headers,
)
assert own.status_code == 200
for key in (
f"conversations/{OTHER_ID}/a.jpg",
f"conversations/{CONV_ID}/../{OTHER_ID}/a.jpg",
"conversations/not-a-uuid/a.jpg",
"beli/profile.jpg",
):
resp = await client.get(
f"/api/conversation/image/{key}", headers=headers
)
assert resp.status_code == 404, key
presign.assert_awaited_once_with(f"conversations/{CONV_ID}/a.jpg")
async def test_image_upload_requires_owned_conversation(self, app, headers, s3):
with patch.object(conv.blueprints.users.models.User, "get", AsyncMock()):
resp = await self._upload_image(app, headers)
assert resp.status_code == 404
s3.upload_image.assert_not_awaited()
@staticmethod
async def _upload_image(app, headers):
return await app.test_client().post(
"/api/conversation/upload-image",
headers=headers,
form={"conversation_id": OTHER_ID},
files={
"file": FileStorage(
io.BytesIO(_png_bytes()), filename="a.png", content_type="image/png"
)
},
)