Files
mtusi2026lab7/student-tests/cursor_validation.py
T
zemiles 9cc80d2529 ЛР 7 — БПИ2303 — Лазарев — на 3
Перенесена реализация lab6; бизнес-API без изменений, транспорт — HTTPS.

- Внешний HTTPS (public-ca) на 127.0.0.1:8443; HSTS, TLS >= 1.2.
- Обязательное mTLS LB -> каждая API-реплика: API проверяет цепочку
  internal-ca и SAN клиента (allowlist: lb); health только на 127.0.0.1.
- TLS с проверкой сервера ко всем зависимостям: PostgreSQL verify-full
  (pg_hba только hostssl), HTTPS S3, AMQPS, OTLP/HTTPS с client cert,
  mTLS Collector -> Prometheus/Loki/Tempo, Grafana -> datasources, scrape.
- OpenBao 2.7.2 не в dev-mode: Raft на volume, init/unseal оператором,
  auth/cert с ролью и policy на сервис, TTL 15 мин + renew/re-login.
- Отдельные роли PostgreSQL с грантами по таблицам; разные ключи S3 и
  пользователи брокера выдаются из OpenBao.
- Argon2id (m=19 MiB, t=2, p=1, замер на стенде) и rehash при входе.
- Случайный X-Instance-Id; hardening контейнеров (non-root, cap_drop ALL,
  no-new-privileges, read-only, лимиты); TCP_NODELAY на сокете API.
- Модель угроз, trust matrix, отрицательные тесты TLS/mTLS, API, OpenBao,
  hardening; evidence, в т.ч. прогон из чистого clone.
2026-11-18 23:59:35 +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)