Реализовать ЛР4: S3-хранилище и вложения на оценку 3

Стенд: PostgreSQL 16 + две API-реплики за HAProxy + SeaweedFS S3 в приватном bucket. Метаданные вложений в PostgreSQL, байты в S3, object key назначает сервер. Лимиты 10 MiB и 40 млн пикселей, MIME по магическим байтам, проверка filename. Добавлены smoke/негативные тесты, хуки restart/stop-one, сценарий отказа S3 и отчёт с доказательствами.
This commit is contained in:
drunkdiente
2026-11-08 14:29:02 +03:00
parent ec540a1a72
commit 935307d412
38 changed files with 2641 additions and 26 deletions
+1
View File
@@ -0,0 +1 @@
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
+31
View File
@@ -0,0 +1,31 @@
Table "public.attachments"
Column | Type | Collation | Nullable | Default
--------------+--------------------------+-----------+----------+-------------
id | uuid | | not null |
chat_id | uuid | | not null |
owner_id | uuid | | not null |
filename | text | | not null |
content_type | text | | not null |
size_bytes | bigint | | not null |
sha256 | text | | not null |
object_key | text | | not null |
status | text | | not null |
variants | jsonb | | not null | '[]'::jsonb
error_code | text | | |
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
Indexes:
"attachments_pkey" PRIMARY KEY, btree (id)
"attachments_chat_idx" btree (chat_id)
"attachments_object_key_key" UNIQUE CONSTRAINT, btree (object_key)
Foreign-key constraints:
"attachments_chat_id_fkey" FOREIGN KEY (chat_id) REFERENCES chats(id) ON DELETE CASCADE
"attachments_owner_id_fkey" FOREIGN KEY (owner_id) REFERENCES users(id)
Referenced by:
TABLE "message_attachments" CONSTRAINT "message_attachments_attachment_id_fkey" FOREIGN KEY (attachment_id) REFERENCES attachments(id)
attachments | object_keys
-------------+-------------
7 | 7
(1 row)
+6
View File
@@ -0,0 +1,6 @@
SERVICE NAME STATUS PORTS
api1 lab4-api1 Up About a minute (healthy) 8080/tcp
api2 lab4-api2 Up About a minute (healthy) 8080/tcp
haproxy lab4-haproxy Up About a minute 127.0.0.1:8081->8080/tcp
postgres lab4-postgres Up About a minute (healthy) 5432/tcp
seaweedfs lab4-seaweedfs Up 45 seconds 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
+3
View File
@@ -0,0 +1,3 @@
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
{"observed_instances_before": 2, "successful_writes": 112, "failed_attempts": 0, "first_recovery_seconds": 2.328}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+14
View File
@@ -0,0 +1,14 @@
PASS: oversized upload returns 413 before decoding
PASS: corrupt image returns 415
PASS: MIME mismatch returns 415
PASS: unsupported declared type returns 415
PASS: path-like and control-character filenames return 400
PASS: pixel limit returns 413
PASS: attachment from another chat cannot be attached
PASS: unknown attachment id returns 404
PASS: outsider cannot read metadata or bytes
PASS: chat member downloads identical bytes
PASS: real JPEG upload roundtrip
PASS: attachment_ids survive message history
PASS: all negative attachment scenarios
+2
View File
@@ -0,0 +1,2 @@
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
+6
View File
@@ -0,0 +1,6 @@
{
"objects_in_bucket": 7,
"first_key": "chats/188fd76c-74c0-4861-a521-8b020b1430e8/95a16c4a-e8c0-4da6-9b7e-581f96762c27/original",
"anonymous_object_get_status": 403,
"anonymous_bucket_list_status": 403
}
+7
View File
@@ -0,0 +1,7 @@
stage=baseline attachment=9aabb7d3-764a-4d15-b769-21ea2810beb3 sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
stage=s3_down lb_readiness_status=503
stage=s3_down lb_upload_status=503
stage=s3_down lb_download_status=503
stage=s3_down api_replica_probe={"metadata": {"status": 200}, "content": {"status": 503, "error_code": "unavailable", "has_request_id": true}}
stage=s3_restored readiness=200 download=identical
PASS: S3 outage surfaced as 503 and the original survived the restart
+1
View File
@@ -0,0 +1 @@
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
+17
View File
@@ -0,0 +1,17 @@
.venv\Scripts\python : test_signed_cursor_roundtrip_and_tampering (test_core.CursorTests) ... ok
строка:1 знак:382
+ ... ntract.txt; .venv\Scripts\python -m unittest discover -s student-test ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (test_signed_cur...orTests) ... ok:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
test_corrupt_and_oversized (test_core.ImageTests) ... ok
test_filename_rules (test_core.ImageTests) ... ok
test_fixture_png (test_core.ImageTests) ... ok
test_jpeg_and_mime_mismatch (test_core.ImageTests) ... ok
test_password_roundtrip (test_core.PasswordTests) ... ok
----------------------------------------------------------------------
Ran 6 tests in 0.099s
OK
+1
View File
@@ -0,0 +1 @@
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.