docs: add evidence for grade 3 requirements

This commit is contained in:
kk10
2026-11-04 17:26:36 +03:00
parent 94afb53e05
commit b266d634c0
6 changed files with 136 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
> make contract-go
go test -tags=contract ./student-tests/... -v -args -base-url=http://localhost:8080
=== RUN TestAttachmentJPEG
--- PASS: TestAttachmentJPEG (0.23s)
=== RUN TestAttachmentTooManyPixels
--- PASS: TestAttachmentTooManyPixels (1.83s)
=== RUN TestAttachmentUnsafeFilename
--- PASS: TestAttachmentUnsafeFilename (0.12s)
=== RUN TestAttachmentTooLarge
--- PASS: TestAttachmentTooLarge (0.22s)
=== RUN TestAttachmentCorruptedImage
--- PASS: TestAttachmentCorruptedImage (0.14s)
=== RUN TestAttachmentMimeSubstitution
--- PASS: TestAttachmentMimeSubstitution (0.12s)
=== RUN TestAttachmentForeignID
--- PASS: TestAttachmentForeignID (0.26s)
=== RUN TestAttachmentFromAnotherChat
--- PASS: TestAttachmentFromAnotherChat (0.41s)
=== RUN TestCreateChatRollback
--- PASS: TestCreateChatRollback (0.16s)
=== RUN TestInvalidJSON
--- PASS: TestInvalidJSON (0.00s)
=== RUN TestForeignChat
--- PASS: TestForeignChat (0.57s)
=== RUN TestEmptyMessage
--- PASS: TestEmptyMessage (0.21s)
=== RUN TestDuplicateUsername
--- PASS: TestDuplicateUsername (0.28s)
=== RUN TestPagination
--- PASS: TestPagination (0.36s)
=== RUN TestLoginWrongPassword
--- PASS: TestLoginWrongPassword (0.34s)
=== RUN TestLogout
--- PASS: TestLogout (0.17s)
PASS
ok mtusi2026-messenger/student-tests 5.442s
+3
View File
@@ -0,0 +1,3 @@
> make test
python3 tests/smoke.py --base-url "http://localhost:8080"
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
+7
View File
@@ -0,0 +1,7 @@
> OBJECT_KEY=$(docker compose exec -T postgres psql -U messenger -d messenger -Atc "SELECT s3_key FROM attachments WHERE status = 'ready' ORDER BY created_at DESC LIMIT 1;")
> echo "$OBJECT_KEY"
chats/01a1a6df-35b7-786f-aa90-f7155218d5b0/attachments/01a1a6df-35ca-7a29-9fa7-fb30a52fbed0
> docker compose exec -T s3 wget -S -O /dev/null "http://127.0.0.1:9000/messenger-attachments/${OBJECT_KEY}"
Connecting to 127.0.0.1:9000 (127.0.0.1:9000)
HTTP/1.1 403 Forbidden
wget: server returned error: HTTP/1.1 403 Forbidden
+5
View File
@@ -0,0 +1,5 @@
> 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": 122, "failed_attempts": 0, "first_recovery_seconds": 2.441}
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
+24
View File
@@ -0,0 +1,24 @@
> docker compose ps -a
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi2026lab4-api-1 mtusi-messenger:lab4 "/app/server" api 2 hours ago Up 2 hours (healthy) 8080/tcp
mtusi2026lab4-api-2 mtusi-messenger:lab4 "/app/server" api 2 hours ago Up 21 seconds (healthy) 8080/tcp
mtusi2026lab4-load_balancer-1 nginx:1.31.7-alpine3.24 "/docker-entrypoint.…" load_balancer 2 hours ago Up 2 hours 127.0.0.1:8080->8080/tcp
mtusi2026lab4-migrate-1 mtusi2026lab4-migrate "sh -c 'goose -dir /…" migrate 26 hours ago Exited (0) 2 hours ago
mtusi2026lab4-postgres-1 postgres:18.6 "docker-entrypoint.s…" postgres 26 hours ago Up 2 hours (healthy) 127.0.0.1:5432->5432/tcp
mtusi2026lab4-redis-1 redis:8.8.3-alpine3.23 "docker-entrypoint.s…" redis 26 hours ago Up 2 hours (healthy) 6379/tcp
mtusi2026lab4-s3-1 chrislusf/seaweedfs:4.51 "/entrypoint.sh serv…" s3 26 hours ago Up 2 hours (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
mtusi2026lab4-s3-config-init-1 mtusi-messenger-s3config:lab4 "/usr/local/bin/s3co…" s3-config-init 2 hours ago Exited (0) 2 hours ago
> 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.
> docker compose ps -a
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi2026lab4-api-1 mtusi-messenger:lab4 "/app/server" api 31 seconds ago Up 9 seconds (healthy) 8080/tcp
mtusi2026lab4-api-2 mtusi-messenger:lab4 "/app/server" api 31 seconds ago Up 9 seconds (healthy) 8080/tcp
mtusi2026lab4-load_balancer-1 nginx:1.31.7-alpine3.24 "/docker-entrypoint.…" load_balancer 31 seconds ago Up 3 seconds 127.0.0.1:8080->8080/tcp
mtusi2026lab4-migrate-1 mtusi2026lab4-migrate "sh -c 'goose -dir /…" migrate 31 seconds ago Exited (0) 24 seconds ago
mtusi2026lab4-postgres-1 postgres:18.6 "docker-entrypoint.s…" postgres 31 seconds ago Up 30 seconds (healthy) 127.0.0.1:5432->5432/tcp
mtusi2026lab4-redis-1 redis:8.8.3-alpine3.23 "docker-entrypoint.s…" redis 31 seconds ago Up 29 seconds (healthy) 6379/tcp
mtusi2026lab4-s3-1 chrislusf/seaweedfs:4.51 "/entrypoint.sh serv…" s3 31 seconds ago Up 29 seconds (healthy) 7333/tcp, 8080/tcp, 8333/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp
mtusi2026lab4-s3-config-init-1 mtusi-messenger-s3config:lab4 "/usr/local/bin/s3co…" s3-config-init 31 seconds ago Exited (0) 30 seconds ago
+61
View File
@@ -5,6 +5,9 @@ package studenttests_test
import (
"bytes"
"encoding/json"
"image/jpeg"
"image/png"
"io"
"net/http"
"net/url"
"testing"
@@ -105,6 +108,64 @@ func requireErrorCode(t *testing.T, resp *http.Response, code dto.ErrorCode) {
}
}
func TestAttachmentJPEG(t *testing.T) {
user := createUser(t)
chat := createChat(t, user, user.ID)
img, err := png.Decode(bytes.NewReader(makePNG(t, 32, 32)))
if err != nil {
t.Fatalf("decode png: %v", err)
}
var body bytes.Buffer
if err := jpeg.Encode(&body, img, nil); err != nil {
t.Fatalf("encode jpeg: %v", err)
}
resp := uploadAttachment(t, user, chat.ID, "sample.jpg", "image/jpeg", body.Bytes())
requireStatus(t, resp, http.StatusCreated)
var att dto.AttachmentResponse
mustDecode(t, resp, &att)
if att.Status != "ready" {
t.Fatalf("expected ready attachment, got %q", att.Status)
}
resp = doRequest(t, http.MethodGet, "/api/v1/attachments/"+att.ID.String()+"/content", user.Token, nil)
requireStatus(t, resp, http.StatusOK)
defer resp.Body.Close()
original, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("read original: %v", err)
}
if !bytes.Equal(original, body.Bytes()) {
t.Error("downloaded JPEG differs from uploaded original")
}
}
func TestAttachmentTooManyPixels(t *testing.T) {
user := createUser(t)
chat := createChat(t, user, user.ID)
body := makePNG(t, 8000, 5001)
if len(body) > maxUploadBytes {
t.Fatal("pixel-limit fixture exceeds upload byte limit")
}
resp := uploadAttachment(t, user, chat.ID, "large.png", "image/png", body)
requireStatus(t, resp, http.StatusRequestEntityTooLarge)
requireErrorCode(t, resp, dto.ErrorCodePayloadTooLarge)
}
func TestAttachmentUnsafeFilename(t *testing.T) {
user := createUser(t)
chat := createChat(t, user, user.ID)
resp := uploadAttachment(t, user, chat.ID, "../image.png", "image/png", makePNG(t, 32, 32))
requireStatus(t, resp, http.StatusBadRequest)
requireErrorCode(t, resp, dto.ErrorCodeInvalidRequest)
}
func TestAttachmentTooLarge(t *testing.T) {
user := createUser(t)
chat := createChat(t, user, user.ID)