forked from mtusi2026/mtusi2026lab7
lab7: безопасность, mTLS, OpenBao и PKI lifecycle
This commit is contained in:
+14
-8
@@ -4,7 +4,7 @@
|
||||
Measures client-facing LB traffic, API traffic, API anon memory and latency for
|
||||
two file sizes. Run against a live stand from the repository root.
|
||||
|
||||
python3 scripts/lab4_track1.py --base-url http://localhost:8080
|
||||
python3 scripts/lab4_track1.py --base-url https://localhost:8443
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -24,12 +24,14 @@ sys.path.insert(0, str(ROOT / 'student-tests'))
|
||||
from client import Client # noqa: E402
|
||||
from presign_flow import complete, presign, put # noqa: E402
|
||||
from lab4_memory_experiment import png_of_size # noqa: E402
|
||||
from lab7_http import BASE_URL, CA_FILE # noqa: E402
|
||||
from tests_helpers import compose # noqa: E402
|
||||
|
||||
OUTPUT = ROOT / 'evidence/lab4/track1'
|
||||
|
||||
|
||||
def containers(service: str) -> list[str]:
|
||||
ids = os.popen(f'docker compose ps -q {service}').read().split()
|
||||
ids = compose('ps', '-q', service).stdout.split()
|
||||
if not ids:
|
||||
raise SystemExit(f'no running containers for service {service}')
|
||||
return ids
|
||||
@@ -83,14 +85,14 @@ class Sampler:
|
||||
def proxy_upload(client: Client, actor: dict, chat: dict, content: bytes) -> None:
|
||||
path = '/api/v1/chats/' + chat['id'] + '/attachments?filename=track1.png'
|
||||
client.call(
|
||||
'POST', path, 201, actor=actor, raw=content,
|
||||
'POST', path, 202, actor=actor, raw=content,
|
||||
headers={'Content-Type': 'image/png'}, schema='Attachment',
|
||||
)
|
||||
|
||||
|
||||
def presign_upload(client: Client, actor: dict, chat: dict, content: bytes) -> None:
|
||||
def presign_upload(client: Client, actor: dict, chat: dict, content: bytes, ca_file=CA_FILE) -> None:
|
||||
prepared = presign(client, actor, chat, content)
|
||||
status = put(prepared['upload_url'], content)
|
||||
status = put(prepared['upload_url'], content, ca_file=ca_file)
|
||||
if status != 200:
|
||||
raise SystemExit(f'presigned PUT failed with {status}')
|
||||
complete(client, actor, prepared['attachment_id'], prepared['sha256'])
|
||||
@@ -98,11 +100,12 @@ def presign_upload(client: Client, actor: dict, chat: dict, content: bytes) -> N
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--base-url', default='http://localhost:8080')
|
||||
parser.add_argument('--base-url', default=BASE_URL)
|
||||
parser.add_argument('--ca-file', default=CA_FILE)
|
||||
parser.add_argument('--iterations', type=int, default=5)
|
||||
args = parser.parse_args()
|
||||
|
||||
client = Client(args.base_url, timeout=180)
|
||||
client = Client(args.base_url, args.ca_file or CA_FILE, timeout=180)
|
||||
alice, _, _, chat = client.bootstrap()
|
||||
|
||||
files = {
|
||||
@@ -121,7 +124,10 @@ def main() -> None:
|
||||
started = time.monotonic()
|
||||
|
||||
with Sampler() as sampler:
|
||||
operation(client, alice, chat, content)
|
||||
if flow == 'presign':
|
||||
operation(client, alice, chat, content, ca_file=args.ca_file or CA_FILE)
|
||||
else:
|
||||
operation(client, alice, chat, content)
|
||||
|
||||
latency = time.monotonic() - started
|
||||
lb_after, lb_tx_after = read_net('lb')
|
||||
|
||||
Reference in New Issue
Block a user