lab7: безопасность, mTLS, OpenBao и PKI lifecycle

This commit is contained in:
Vladislav Kunetskiy
2026-11-10 10:58:07 +03:00
parent 3d216fbd50
commit 3441f2269a
183 changed files with 216667 additions and 3165 deletions
+7 -14
View File
@@ -5,17 +5,17 @@ import sys
import urllib.request
from concurrent.futures import ThreadPoolExecutor
from statistics import median
import subprocess
import time
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Собственный тест живёт в student-tests/ (CONTRIBUTING), публичный клиент — в tests/.
sys.path.insert(0, os.path.join(ROOT, 'tests'))
sys.path.insert(0, os.path.join(ROOT, 'scripts'))
from client import Client, check # noqa: E402
COMPOSE = os.environ.get('COMPOSE_BIN', 'docker-compose')
BASE_URL = os.environ.get('BASE_URL', 'http://localhost:8080')
from lab7_http import BASE_URL, CA_FILE, open_url # noqa: E402
from tests_helpers import compose # noqa: E402
USERS = 4
CHATS_PER_USER = 15
REQUESTS_PER_USER = 250
@@ -31,19 +31,12 @@ def restart_api(cache_enabled):
env = dict(os.environ)
env['REDIS_ENABLED'] = 'true'
env['CACHE_ENABLED'] = 'true' if cache_enabled else 'false'
subprocess.run(
[COMPOSE, '-f', 'docker-compose.local.yaml', 'up', '-d', '--force-recreate', 'api'],
cwd=ROOT,
env=env,
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
compose('up', '-d', '--force-recreate', '--no-deps', 'api', env=env)
deadline = time.monotonic() + 90
while time.monotonic() < deadline:
try:
Client(BASE_URL, timeout=2).call('GET', '/health/ready', schema='Health')
Client(BASE_URL, CA_FILE, timeout=2).call('GET', '/health/ready', schema='Health')
return
except Exception:
time.sleep(0.5)
@@ -73,7 +66,7 @@ def benchmark(actors):
},
)
try:
with urllib.request.urlopen(request, timeout=10) as response:
with open_url(request, timeout=10, ca_file=CA_FILE) as response:
data = response.read()
status = response.status
check(status == 200,
@@ -111,7 +104,7 @@ def benchmark(actors):
def main():
client = Client(BASE_URL, timeout=10)
client = Client(BASE_URL, CA_FILE, timeout=10)
actors = [client.user('perf_api_' + str(i)) for i in range(USERS)]
for index, owner in enumerate(actors):