Files
mtusi2026lab4/student-tests/cursor_validation.py
T
zemiles c5a07dc253 ЛР 4 — БПИ2303 — Лазарев — на 4
Перенос lab3 и вложения в приватном S3 (SeaweedFS 4.50).

- POST /chats/{id}/attachments: потоковый приём PNG/JPEG в безымянный
  временный файл, SHA-256 на лету, лимиты 10 MiB / 40 Мпикс до чтения
  и декодирования, проверка MIME по содержимому, валидация filename.
- Порядок записи pending -> S3 PUT -> ready с компенсацией; janitor
  сверяет БД и bucket (dry-run, grace period, advisory lock).
- GET /attachments/{id} и /content только участникам чата, без redirect;
  attachment_ids в сообщениях с проверкой принадлежности чату.
- Отдельные S3-ключи api/janitor/admin с ограниченными правами,
  идемпотентный bootstrap bucket, служебные порты SeaweedFS закрыты.
- Ограничение параллельных S3 PUT и MALLOC_ARENA_MAX: пик RSS API
  178-189 -> 95-102 MiB; лимиты памяти и restart для SeaweedFS после OOM.
- Тесты уровня 4 (негативные, failover вложений, отказы S3/БД, память)
  и доказательства в evidence/, заполнен REPORT.md.
2026-11-07 01:44:58 +03:00

33 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Проверка диапазона дат cursor: некорректная дата должна давать 400, а не 500."""
import base64
import json
import sys
import uuid
from pathlib import Path
from urllib.parse import quote
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
from client import Client, arguments, run
def main():
args = arguments(__doc__)
client = Client(args.base_url, ca_file=args.ca_file)
alice, _bob, _eve, chat = client.bootstrap()
checks = 0
for kind, scope, path in (
("messages", chat["id"], "/api/v1/chats/" + chat["id"] + "/messages"),
("chats", alice["id"], "/api/v1/chats"),
):
for timestamp, expected in ((-10**17, 400), (-62135596800000001, 400), (0, 200)):
payload = {"k": kind, "s": scope, "t": timestamp, "i": str(uuid.uuid4())}
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
client.call("GET", path + "?cursor=" + quote(cursor, safe=""), expected, actor=alice)
checks += 1
print("PASS: %d cursor date boundary checks; invalid dates return 400." % checks)
if __name__ == "__main__":
run(main)