feat: provision private S3 storage and attachment schema
This commit is contained in:
@@ -14,12 +14,13 @@ import urllib.request
|
||||
from uuid import uuid4
|
||||
|
||||
import psycopg
|
||||
from src.db import database_url
|
||||
|
||||
|
||||
URL = os.environ.get("DATABASE_URL")
|
||||
URL = database_url() if os.environ.get("DATABASE_URL") or os.environ.get("DATABASE_URL_FILE") else None
|
||||
|
||||
|
||||
@unittest.skipUnless(URL, "set DATABASE_URL to a disposable PostgreSQL database")
|
||||
@unittest.skipUnless(URL, "set DATABASE_URL or DATABASE_URL_FILE to a disposable PostgreSQL database")
|
||||
class AuthTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
@@ -9,13 +9,14 @@ from uuid import uuid4
|
||||
|
||||
import psycopg
|
||||
|
||||
from src.db import database_url
|
||||
from src.store import Store
|
||||
|
||||
|
||||
URL = os.environ.get("DATABASE_URL")
|
||||
URL = database_url() if os.environ.get("DATABASE_URL") or os.environ.get("DATABASE_URL_FILE") else None
|
||||
|
||||
|
||||
@unittest.skipUnless(URL, "set DATABASE_URL to a disposable PostgreSQL database")
|
||||
@unittest.skipUnless(URL, "set DATABASE_URL or DATABASE_URL_FILE to a disposable PostgreSQL database")
|
||||
class DatabaseTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -30,7 +31,7 @@ class DatabaseTests(unittest.TestCase):
|
||||
def test_migration_and_unique_username_race(self):
|
||||
with psycopg.connect(URL) as conn:
|
||||
versions = conn.execute("SELECT version FROM schema_migrations").fetchall()
|
||||
self.assertEqual(versions, [(1,), (2,), (3,)])
|
||||
self.assertEqual(versions, [(1,), (2,), (3,), (4,)])
|
||||
name = "u_" + uuid4().hex[:16]
|
||||
|
||||
def register(_):
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user