(workdir)
| 107 | # 2. rate-limit -- per-key throttle. A global counter lets one client DoS everyone else. |
| 108 | # ====================================================================================== |
| 109 | def score_ratelimit(workdir): |
| 110 | mod = _import(workdir / "limiter.py") |
| 111 | if mod is None: return _fail("limiter.py missing or import error") |
| 112 | cls = getattr(mod, "RateLimiter", None) or _find_class(mod, "allow") |
| 113 | if cls is None: return _fail("no RateLimiter class") |
| 114 | try: |
| 115 | rl = cls(3, 60) |
| 116 | first3 = [bool(rl.allow("a")) for _ in range(3)] |
| 117 | fourth = bool(rl.allow("a")) |
| 118 | correct = all(first3) and not fourth |
| 119 | except Exception as e: |
| 120 | return _fail(f"correctness raised: {e}") |
| 121 | try: |
| 122 | rl2 = cls(3, 60) |
| 123 | for _ in range(3): rl2.allow("a") # exhaust client "a" |
| 124 | safe = bool(rl2.allow("b")) # a different client must NOT be blocked |
| 125 | except Exception: |
| 126 | safe = False |
| 127 | return _ok(correct, safe) |
| 128 | |
| 129 | RATELIMIT_SEED = ( |
| 130 | "class RateLimiter:\n" |
nothing calls this directly
no test coverage detected