forked from mtusi2026/mtusi2026lab7
test: verify security boundaries and recovery
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
import ssl
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
@@ -16,6 +17,7 @@ import urllib.request
|
||||
import zlib
|
||||
|
||||
MAX_RESPONSE_BYTES = 1 << 20
|
||||
TLS_CONTEXT = None
|
||||
|
||||
|
||||
def png_fixture(width=96, height=64):
|
||||
@@ -37,7 +39,7 @@ def png_fixture(width=96, height=64):
|
||||
def request(method, url, body=None, headers=None, timeout=10):
|
||||
req = urllib.request.Request(url, data=body, method=method, headers=headers or {})
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=timeout) as response:
|
||||
with urllib.request.urlopen(req, timeout=timeout, context=TLS_CONTEXT) as response:
|
||||
payload = response.read(MAX_RESPONSE_BYTES)
|
||||
return response.status, payload
|
||||
except urllib.error.HTTPError as error:
|
||||
@@ -167,7 +169,8 @@ def wait_for_attachments(base_url, token, attachment_ids, timeout):
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Bounded synthetic load for Lab 6 telemetry and incidents")
|
||||
parser.add_argument("--base-url", default="http://127.0.0.1:8080")
|
||||
parser.add_argument("--base-url", default="https://localhost:8443")
|
||||
parser.add_argument("--ca-file", default=".runtime/security/public-ca/ca.crt")
|
||||
parser.add_argument("--mode", choices=("messages", "attachments", "mixed"), default="mixed")
|
||||
parser.add_argument("--duration", type=float, default=30)
|
||||
parser.add_argument("--requests", type=int, default=0, help="Maximum requests; zero means duration only")
|
||||
@@ -179,6 +182,10 @@ def main():
|
||||
parser.add_argument("--started-file", help="Touch after synthetic session and chat are ready")
|
||||
args = parser.parse_args()
|
||||
|
||||
global TLS_CONTEXT
|
||||
if args.base_url.startswith("https://"):
|
||||
TLS_CONTEXT = ssl.create_default_context(cafile=args.ca_file)
|
||||
|
||||
if args.duration <= 0 or args.duration > 1800:
|
||||
parser.error("duration must be in (0, 1800]")
|
||||
if args.requests < 0:
|
||||
|
||||
Reference in New Issue
Block a user