File size: 1,652 Bytes
27e707f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | """Check that the live login rate limit is per client behind the platform proxy.
One machine exhausts its per-address login limit; a second machine with a different public address
then makes one attempt inside the same 60-second window. A 401 for the second machine means clients
are told apart correctly; a 429 means every caller shares one bucket (wrong proxy hop count).
Usernames are random and never exist, so no account is locked or touched.
"""
import argparse
import json
import secrets
import sys
import time
import httpx
def attempt(client, base):
return client.post(base + '/api/v2/auth/login', json={'username': 'probe-' + secrets.token_hex(8),
'password': 'not-a-real-password-' + secrets.token_hex(4)}).status_code
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--base', default='https://gaurav711-hyperflow.hf.space')
parser.add_argument('--mode', choices=['exhaust', 'probe'], required=True)
parser.add_argument('--at', type=float, help='probe: unix time to send the single attempt')
args = parser.parse_args()
with httpx.Client(timeout=30) as client:
if args.mode == 'exhaust':
statuses = [attempt(client, args.base) for _ in range(13)]
result = {'mode': 'exhaust', 'statuses': statuses, 'limited': statuses[-1] == 429, 'at': time.time()}
else:
time.sleep(max(0, args.at - time.time()))
result = {'mode': 'probe', 'status': attempt(client, args.base), 'at': time.time()}
print(json.dumps(result))
sys.exit(0)
if __name__ == '__main__':
main()
|