forked from mtusi2026/mtusi2026lab7
fix(auth): reject excess login concurrency before Argon2 work
This commit is contained in:
@@ -139,6 +139,8 @@ def main():
|
||||
observer.start()
|
||||
started = time.monotonic()
|
||||
|
||||
measurement_lock = threading.Lock()
|
||||
|
||||
def login(i):
|
||||
name = (
|
||||
"absent_"
|
||||
@@ -157,6 +159,15 @@ def main():
|
||||
"instance": r.headers.get("x-instance-id"),
|
||||
"retry_after": r.headers.get("retry-after"),
|
||||
}
|
||||
if r.status_code != 401:
|
||||
try:
|
||||
result["error_message"] = (
|
||||
r.json().get("error", {}).get("message")
|
||||
)
|
||||
except ValueError:
|
||||
result["error_message"] = "Non-JSON response"
|
||||
with measurement_lock:
|
||||
report["measurements"].append(result)
|
||||
assert r.status_code in {401, 429}
|
||||
if r.status_code == 429:
|
||||
assert int(r.headers["retry-after"]) >= 1
|
||||
@@ -164,7 +175,7 @@ def main():
|
||||
|
||||
try:
|
||||
with ThreadPoolExecutor(max_workers=12) as pool:
|
||||
report["measurements"] = list(pool.map(login, range(72)))
|
||||
list(pool.map(login, range(72)))
|
||||
finally:
|
||||
stop.set()
|
||||
observer.join(15)
|
||||
@@ -183,9 +194,16 @@ def main():
|
||||
"SELECT count(*) FROM login_buckets WHERE bucket<>'global'"
|
||||
)
|
||||
)
|
||||
assert buckets == len(admitted), (
|
||||
"Rejected random accounts must not allocate buckets"
|
||||
local_capacity = [
|
||||
x
|
||||
for x in limited
|
||||
if x.get("error_message")
|
||||
== "Authentication concurrency limit exceeded"
|
||||
]
|
||||
assert buckets == len(admitted) + len(local_capacity), (
|
||||
"Only attempts passing the shared SQL limiter may allocate account state"
|
||||
)
|
||||
assert buckets <= 16 + int(8 * duration) + 1
|
||||
report["flood"] = {
|
||||
"requests": 72,
|
||||
"concurrency": 12,
|
||||
@@ -195,6 +213,9 @@ def main():
|
||||
),
|
||||
"both_replicas_observed": True,
|
||||
"new_account_buckets": buckets,
|
||||
"local_concurrency_rejections": len(local_capacity),
|
||||
"shared_limiter_rejections": len(limited)
|
||||
- len(local_capacity),
|
||||
"shared_admission_bound": 16 + int(8 * duration) + 1,
|
||||
"limited_median_seconds": statistics.median(
|
||||
x["seconds"] for x in limited
|
||||
|
||||
Reference in New Issue
Block a user