diff --git a/scripts/security_checks.py b/scripts/security_checks.py index 33ef416..40342f8 100644 --- a/scripts/security_checks.py +++ b/scripts/security_checks.py @@ -14,6 +14,10 @@ def run(args, *, output=None): result = subprocess.run(args, cwd=ROOT, check=True, capture_output=True, text=True) if output: (ROOT / "evidence" / output).write_text(result.stdout) + if output.endswith(".json"): + record = json.loads(result.stdout) + if record.get("passed") is False: + raise RuntimeError("Security probe reported a failed invariant: " + output) else: print(result.stdout, end="") return result.stdout diff --git a/student-tests/conftest.py b/student-tests/conftest.py new file mode 100644 index 0000000..2890575 --- /dev/null +++ b/student-tests/conftest.py @@ -0,0 +1,39 @@ +"""Own regression suite respects the real shared login budget; teacher client unchanged.""" + +import time + +import pytest +from client import Client + +_paced_logins = 0 + + +@pytest.fixture(scope="session", autouse=True) +def honor_login_retry_after(): + original = Client.call + + def paced( + self, method, path, expected=200, body=None, actor=None, headers=None, raw=None, schema=None + ): + global _paced_logins + if method != "POST" or path != "/api/v1/auth/sessions" or expected != 201: + return original(self, method, path, expected, body, actor, headers, raw, schema) + deadline = time.monotonic() + 90 + while True: + response = original(self, method, path, [201, 429], body, actor, headers, raw, schema) + if response["status"] == 201: + return response + if time.monotonic() >= deadline: + pytest.fail("Shared login budget did not recover within test deadline") + _paced_logins += 1 + time.sleep(min(10, max(1, float(response["headers"].get("Retry-After", "10"))))) + + Client.call = paced + yield + Client.call = original + + +def pytest_terminal_summary(terminalreporter): + terminalreporter.write_line( + f"Login pacing: {_paced_logins} retries honoring runtime Retry-After; teacher client unchanged." + ) diff --git a/student-tests/test_attachments.py b/student-tests/test_attachments.py index 72bf474..1cac2b6 100644 --- a/student-tests/test_attachments.py +++ b/student-tests/test_attachments.py @@ -1,4 +1,4 @@ -"""Black-box regressions derived from the contract and teacher review comments.""" +"""Black-box regressions derived from the contract and attachment contract and edge cases.""" import hashlib import os