Добавил TLS и защиту мессенджера для лабораторной 7
Skeleton contracts / contracts (pull_request) Blocked by required conditions

This commit is contained in:
2026-11-29 13:06:06 +03:00
parent 20afc2c790
commit d15d78efdf
100 changed files with 4067 additions and 62 deletions
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
"""Проверяет, что действующий Bearer-токен перестаёт работать по истечении TTL."""
import base64
from datetime import datetime, timezone
import sys
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
from client import Client, arguments, check, run, timestamp
def main():
args = arguments("Check session expiry with SESSION_TTL_SECONDS=5")
client = Client(args.base_url, args.ca_file)
registration = client.user("expiry")["registration"]
credentials = f"{registration['username']}:{registration['password']}"
authorization = "Basic " + base64.b64encode(credentials.encode()).decode()
session = client.call("POST", "/api/v1/auth/sessions", 201,
headers={"Authorization": authorization}, schema="Session")["json"]
actor = {"token": session["token"]}
client.call("GET", "/api/v1/users/me", actor=actor, schema="User")
remaining = (timestamp(session["expires_at"]) - datetime.now(timezone.utc)).total_seconds()
check(0 < remaining <= 10, "set SESSION_TTL_SECONDS=5 on both API replicas")
time.sleep(remaining + 1)
client.call("GET", "/api/v1/users/me", 401, actor=actor)
print("PASS: an active Bearer session returned 401 after its declared expiry")
if __name__ == "__main__":
run(main)