forked from mtusi2026/mtusi2026lab4
feat: attachments over S3 (grade 3)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
2026-11-20T03:51:30+03:00
|
||||
make test-attachments
|
||||
|
||||
BASE_URL="http://localhost:8080" python3 scripts/attachments-check.py
|
||||
ok: upload 201 ready, sha256=99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75, size=111817
|
||||
ok: jpeg upload/download byte-identical; jpeg declared as png -> 415
|
||||
ok: png with 40,000,000 pixels accepted and downloaded byte-identical
|
||||
ok: filename with slash -> 400
|
||||
ok: filename with NUL -> 400
|
||||
ok: empty filename -> 400
|
||||
ok: declared jpeg with png body -> 415
|
||||
ok: truncated png -> 415
|
||||
ok: 10485761 bytes -> 413
|
||||
ok: text/plain -> 415
|
||||
ok: unknown variant -> 400
|
||||
ok: variant=original -> 200
|
||||
ok: unknown attachment id -> 404
|
||||
ok: upload by outsider -> 404
|
||||
ok: attachment from another chat -> 404
|
||||
ok: unknown attachment id in message -> 404
|
||||
ok: duplicate attachment_ids -> 400
|
||||
ok: eleven attachment_ids -> 400
|
||||
ok: empty text without attachments -> 400
|
||||
ok: idempotent replay with same attachment set -> same message
|
||||
ok: absent attachment_ids equals [] for idempotency
|
||||
ok: same key with a different attachment set -> 409
|
||||
ok: history exposes attachment_ids on every message
|
||||
PASS: 23 attachment contract checks
|
||||
@@ -0,0 +1,5 @@
|
||||
2026-11-20T03:51:29+03:00
|
||||
make check
|
||||
|
||||
python3 scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
@@ -0,0 +1,7 @@
|
||||
2026-11-20T03:53:34+03:00
|
||||
|
||||
users | chats | messages | attachments | links | db_size
|
||||
-------+-------+----------+-------------+-------+---------
|
||||
40 | 11 | 289 | 8 | 2 | 8542 kB
|
||||
(1 row)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
2026-11-20T03:53:33+03:00
|
||||
|
||||
Linux archlinux 7.3.5-arch1-1 #1 SMP PREEMPT_DYNAMIC Tue, 17 Nov 2026 22:28:33 +0000 x86_64 GNU/Linux
|
||||
12
|
||||
total used free shared buff/cache available
|
||||
Mem: 15Gi 5.0Gi 1.3Gi 385Mi 9.6Gi 10Gi
|
||||
Swap: 8.0Gi 58Mi 7.9Gi
|
||||
podman version 6.2.0
|
||||
podman version 6.2.0
|
||||
podman-compose version 1.6.0
|
||||
go version go1.27.4-X:nodwarf5 linux/amd64
|
||||
|
||||
images
|
||||
docker.io/library/haproxy:3.4.7-alpine 49c6afb26f02
|
||||
docker.io/library/postgres:18.6-alpine3.24 57b23a0326ee
|
||||
docker.io/library/redis:8.10.3-alpine3.23 9722accf3e8e
|
||||
docker.io/migrate/migrate:v4.20.1 719a6f5d0ade
|
||||
docker.io/rustfs/rustfs:1.0.6 7cd1c573d76d
|
||||
localhost/messenger-api:lab4 ff3adbffb20b
|
||||
@@ -0,0 +1,7 @@
|
||||
2026-11-20T03:52:00+03:00
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 86, "failed_attempts": 0, "first_recovery_seconds": 3.239}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,7 @@
|
||||
2026-11-20T03:52:32+03:00
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 87, "failed_attempts": 0, "first_recovery_seconds": 3.236}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,11 @@
|
||||
2026-11-20T03:51:42+03:00
|
||||
make test-idempotency
|
||||
|
||||
BASE_URL="http://localhost:8080" python3 scripts/idempotency-race.py
|
||||
parallel requests with one key: 20
|
||||
successful responses (201): 20
|
||||
failed requests: 0 []
|
||||
distinct message ids in responses: 1
|
||||
messages stored in history: 1
|
||||
instances that served requests: ['939e096de71a', 'dbc0d13c9b45']
|
||||
OK: exactly one message created
|
||||
@@ -0,0 +1,23 @@
|
||||
2026-11-20T03:53:27+03:00
|
||||
API replicas and single entrypoint
|
||||
|
||||
messenger-lab4_api_1 Up About a minute (healthy)
|
||||
messenger-lab4_api_2 Up 35 seconds (healthy)
|
||||
messenger-lab4_lb_1 Up About a minute
|
||||
messenger-lab4_postgres_1 Up About a minute (healthy)
|
||||
messenger-lab4_redis_1 Up About a minute (healthy)
|
||||
messenger-lab4_s3_1 Up About a minute (healthy)
|
||||
|
||||
published ports (only lb must publish 8080)
|
||||
|
||||
messenger-lab4_api_1 8080/tcp
|
||||
messenger-lab4_api_2 8080/tcp
|
||||
messenger-lab4_lb_1 0.0.0.0:8080->8080/tcp
|
||||
messenger-lab4_postgres_1 127.0.0.1:55432->5432/tcp
|
||||
messenger-lab4_redis_1 127.0.0.1:56379->6379/tcp
|
||||
messenger-lab4_s3_1 9000-9001/tcp
|
||||
|
||||
X-Instance-Id distribution over 20 requests through LB
|
||||
|
||||
10 x-instance-id: 939e096de71a
|
||||
10 x-instance-id: dbc0d13c9b45
|
||||
@@ -0,0 +1,19 @@
|
||||
2026-11-20T03:53:28+03:00
|
||||
per-container limits, networks, secrets
|
||||
|
||||
messenger-lab4_api_1 nano_cpus=1000000000 memory=536870912 networks=messenger-lab4_backend messenger-lab4_edge
|
||||
messenger-lab4_api_2 nano_cpus=1000000000 memory=536870912 networks=messenger-lab4_backend messenger-lab4_edge
|
||||
messenger-lab4_lb_1 nano_cpus=500000000 memory=67108864 networks=messenger-lab4_edge
|
||||
messenger-lab4_postgres_1 nano_cpus=1000000000 memory=536870912 networks=messenger-lab4_backend
|
||||
messenger-lab4_redis_1 nano_cpus=500000000 memory=134217728 networks=messenger-lab4_backend
|
||||
messenger-lab4_s3_1 nano_cpus=1000000000 memory=536870912 networks=messenger-lab4_backend
|
||||
messenger-lab4_migrate_1 nano_cpus=500000000 memory=67108864 networks=messenger-lab4_backend
|
||||
|
||||
ls /run/secrets per container
|
||||
|
||||
messenger-lab4_api_1: cache_url database_url s3_access_key_id s3_secret_access_key
|
||||
messenger-lab4_api_2: cache_url database_url s3_access_key_id s3_secret_access_key
|
||||
messenger-lab4_lb_1:
|
||||
messenger-lab4_postgres_1: postgres_password
|
||||
messenger-lab4_redis_1:
|
||||
messenger-lab4_s3_1: s3_access_key_id s3_secret_access_key
|
||||
@@ -0,0 +1,20 @@
|
||||
2026-11-20T03:53:34+03:00
|
||||
migrate container logs and schema version
|
||||
|
||||
1/u init (12.217985ms)
|
||||
2/u message_idempotency (17.93178ms)
|
||||
3/u attachments (25.639306ms)
|
||||
no change
|
||||
no change
|
||||
no change
|
||||
no change
|
||||
no change
|
||||
no change
|
||||
|
||||
schema_migrations
|
||||
|
||||
version | dirty
|
||||
---------+-------
|
||||
3 | f
|
||||
(1 row)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
2026-11-20T03:51:42+03:00
|
||||
make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
||||
|
||||
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080"
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
|
||||
--- hook scope: containers and volumes before/after scripts/restart.sh ---
|
||||
|
||||
messenger-lab4_api_1 dbc0d13c9b45 Up About a minute (healthy)
|
||||
messenger-lab4_api_2 939e096de71a Up 42 seconds (healthy)
|
||||
messenger-lab4_lb_1 c2c6a2077627 Up About a minute
|
||||
messenger-lab4_postgres_1 a0b192c17952 Up About a minute (healthy)
|
||||
messenger-lab4_redis_1 f787abf8c4bf Up About a minute (healthy)
|
||||
messenger-lab4_s3_1 49ff0b0c9d92 Up About a minute (healthy)
|
||||
messenger-lab4_pgdata
|
||||
messenger-lab4_redisdata
|
||||
messenger-lab4_s3data
|
||||
|
||||
$ scripts/restart.sh
|
||||
|
||||
|
||||
messenger-lab4_api_1 dbc0d13c9b45 Up 15 seconds (healthy)
|
||||
messenger-lab4_api_2 939e096de71a Up 15 seconds (healthy)
|
||||
messenger-lab4_lb_1 c2c6a2077627 Up 15 seconds
|
||||
messenger-lab4_postgres_1 a0b192c17952 Up 16 seconds (healthy)
|
||||
messenger-lab4_redis_1 f787abf8c4bf Up 16 seconds (healthy)
|
||||
messenger-lab4_s3_1 49ff0b0c9d92 Up 16 seconds (healthy)
|
||||
messenger-lab4_pgdata
|
||||
messenger-lab4_redisdata
|
||||
messenger-lab4_s3data
|
||||
ready: 200
|
||||
@@ -0,0 +1,5 @@
|
||||
2026-11-20T03:51:29+03:00
|
||||
make test
|
||||
|
||||
python3 tests/smoke.py --base-url "http://localhost:8080"
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,44 @@
|
||||
2026-11-20T03:53:23+03:00
|
||||
object bytes live in the RustFS volume, metadata in PostgreSQL
|
||||
|
||||
id | object_key | size_bytes | sha256
|
||||
--------------------------------------+---------------------------------------------------------------------------------+------------+------------------------------------------------------------------
|
||||
0df7c6fd-6ac6-488b-9803-73fee496586f | chats/70682cfc-bf33-4f15-8de6-e85972fc95e0/0df7c6fd-6ac6-488b-9803-73fee496586f | 111817 | 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
|
||||
(1 row)
|
||||
|
||||
|
||||
S3 volume listing for that object
|
||||
|
||||
/data/messenger-attachments/chats/70682cfc-bf33-4f15-8de6-e85972fc95e0/0df7c6fd-6ac6-488b-9803-73fee496586f:
|
||||
total 112
|
||||
-rw-r--r-- 1 rustfs rustfs 112398 Nov 20 00:52 xl.meta
|
||||
|
||||
attachments table columns (no binary content)
|
||||
|
||||
column_name | data_type
|
||||
--------------+--------------------------
|
||||
id | uuid
|
||||
chat_id | uuid
|
||||
owner_id | uuid
|
||||
filename | text
|
||||
content_type | text
|
||||
size_bytes | bigint
|
||||
sha256 | text
|
||||
object_key | text
|
||||
status | text
|
||||
error_code | text
|
||||
created_at | timestamp with time zone
|
||||
updated_at | timestamp with time zone
|
||||
(12 rows)
|
||||
|
||||
|
||||
anonymous S3 GET without credentials
|
||||
|
||||
Connecting to s3:9000 (10.89.5.10:9000)
|
||||
HTTP/1.1 403 Forbidden
|
||||
wget: server returned error: HTTP/1.1 403 Forbidden
|
||||
|
||||
admin console port (must be closed)
|
||||
|
||||
000
|
||||
console-closed
|
||||
@@ -0,0 +1,64 @@
|
||||
2026-11-20T03:54:42+03:00
|
||||
make test-go
|
||||
|
||||
? messenger/cmd/server [no test files]
|
||||
? messenger/internal/config [no test files]
|
||||
? messenger/internal/domain [no test files]
|
||||
=== RUN TestSessionExpiry
|
||||
--- PASS: TestSessionExpiry (3.09s)
|
||||
=== RUN TestLogout
|
||||
--- PASS: TestLogout (0.11s)
|
||||
=== RUN TestWrongPassword
|
||||
--- PASS: TestWrongPassword (0.10s)
|
||||
=== RUN TestRedisUnavailable
|
||||
redis: 2026/11/20 03:54:46 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
|
||||
redis: 2026/11/20 03:54:46 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
|
||||
redis: 2026/11/20 03:54:47 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
|
||||
redis: 2026/11/20 03:54:47 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
|
||||
redis: 2026/11/20 03:54:47 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
|
||||
redis: 2026/11/20 03:54:48 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
|
||||
--- PASS: TestRedisUnavailable (2.81s)
|
||||
=== RUN TestDatabaseUnavailable
|
||||
--- PASS: TestDatabaseUnavailable (0.17s)
|
||||
=== RUN TestInvalidJSON
|
||||
--- PASS: TestInvalidJSON (0.01s)
|
||||
=== RUN TestForeignChat
|
||||
--- PASS: TestForeignChat (0.18s)
|
||||
=== RUN TestEmptyMessage
|
||||
redis: 2026/11/20 03:54:48 pool.go:770: redis: connection pool: failed to dial after 5 attempts: dial tcp 127.0.0.1:1: connect: connection refused
|
||||
--- PASS: TestEmptyMessage (0.08s)
|
||||
=== RUN TestDuplicateUsername
|
||||
--- PASS: TestDuplicateUsername (0.09s)
|
||||
=== RUN TestPaginationMultiplePages
|
||||
--- PASS: TestPaginationMultiplePages (0.09s)
|
||||
=== RUN TestConcurrentMessages
|
||||
--- PASS: TestConcurrentMessages (0.57s)
|
||||
PASS
|
||||
ok messenger/internal/handler 7.289s
|
||||
=== RUN TestRegisterUsernameRace
|
||||
--- PASS: TestRegisterUsernameRace (0.05s)
|
||||
=== RUN TestCreateChatRollback
|
||||
--- PASS: TestCreateChatRollback (0.01s)
|
||||
PASS
|
||||
ok messenger/internal/repository/postgres 0.072s
|
||||
? messenger/internal/repository/redis [no test files]
|
||||
? messenger/internal/repository/s3 [no test files]
|
||||
? messenger/internal/router [no test files]
|
||||
=== RUN TestCheckFilename
|
||||
--- PASS: TestCheckFilename (0.00s)
|
||||
=== RUN TestDetectImageType
|
||||
--- PASS: TestDetectImageType (0.00s)
|
||||
=== RUN TestCheckPixels
|
||||
--- PASS: TestCheckPixels (0.00s)
|
||||
=== RUN TestCheckIntegrity
|
||||
--- PASS: TestCheckIntegrity (0.00s)
|
||||
=== RUN TestCheckMessageText
|
||||
--- PASS: TestCheckMessageText (0.00s)
|
||||
=== RUN TestCheckAttachmentIDs
|
||||
--- PASS: TestCheckAttachmentIDs (0.00s)
|
||||
=== RUN TestMessageHash
|
||||
--- PASS: TestMessageHash (0.00s)
|
||||
=== RUN TestReadLimited
|
||||
--- PASS: TestReadLimited (0.00s)
|
||||
PASS
|
||||
ok messenger/internal/service 0.004s
|
||||
Reference in New Issue
Block a user