feat: provision private S3 storage and attachment schema

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 13:01:50 +03:00
parent bd41f2d93d
commit 22f7bcddf5
14 changed files with 309 additions and 25 deletions
+38
View File
@@ -0,0 +1,38 @@
"""Run inside an API container after S3 bootstrap."""
import io
import unittest
from uuid import uuid4
from urllib.error import HTTPError
from urllib.request import urlopen
from minio.error import S3Error
from src.attachments import BUCKET, storage
class StorageBootstrapTests(unittest.TestCase):
def test_private_bucket_and_scoped_api_credentials(self):
client = storage()
key = "test-bootstrap/" + uuid4().hex
data = b"private attachment fixture"
client.put_object(BUCKET, key, io.BytesIO(data), len(data), content_type="application/octet-stream")
try:
response = client.get_object(BUCKET, key)
try:
self.assertEqual(response.read(), data)
finally:
response.close()
response.release_conn()
with self.assertRaises(HTTPError) as denied:
urlopen(f"http://s3:9000/{BUCKET}/{key}", timeout=3)
self.assertEqual(denied.exception.code, 403)
with self.assertRaises(S3Error) as forbidden:
client.make_bucket("forbidden-" + uuid4().hex)
self.assertEqual(forbidden.exception.code, "AccessDenied")
finally:
client.remove_object(BUCKET, key)
if __name__ == "__main__":
unittest.main()