fix: large carts upload all their files (Marcus's bugs of 11/11, B1 to B4)
B1: an upload start was limited to 60 per 15 minutes per session, so a 66-file cart failed with 'Muitas tentativas'; now 1000 per session and 3000 per source, and the Site waits Retry-After and retries quietly. B2: a failed file shows its error and 'Tentar de novo' on its own card, and payment stays blocked with 'Falta enviar N arquivos'. B3: after signing in again, an upload id the new session does not own (403) is dropped and the file starts again. B4: the quote is never created before every file is sent, and an untranslatable 422 is logged for Sentry. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
40
tests/upload_limits_test.py
Normal file
40
tests/upload_limits_test.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""The upload start limit: a large cart fits, and the per-source bucket
|
||||
still refuses above its own limit (Marcus's bugs of 2026-11-11, B1).
|
||||
|
||||
Run against the local stack: python -m tests.upload_limits_test
|
||||
"""
|
||||
import secrets
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.api.uploads import UPLOAD_START_IP_LIMIT, UPLOAD_START_LIMIT
|
||||
from app.core.auth import rate_limit
|
||||
from tests.smoke_test import Client
|
||||
|
||||
|
||||
def run():
|
||||
assert (UPLOAD_START_LIMIT, UPLOAD_START_IP_LIMIT) == (1000, 3000)
|
||||
client = Client()
|
||||
client.call('/session')
|
||||
# A 66-file cart, with retries, fits in one session. Each reservation is
|
||||
# cancelled so the pending-upload quota (unchanged) does not stop the test.
|
||||
for index in range(70):
|
||||
uid = client.call('/uploads', {'name': f'LIMIT-{index}.png', 'size': 1})['id']
|
||||
client.call(f'/uploads/{uid}', expected=200, method='DELETE')
|
||||
# The per-source bucket, exercised directly with a small limit: 3000 real
|
||||
# starts would only slow CI. A unique key keeps other suites out of it.
|
||||
key = 'upload-start-ip-test-' + secrets.token_hex(8)
|
||||
for _ in range(3):
|
||||
rate_limit('upload-start-ip', key, 3, 900)
|
||||
try:
|
||||
rate_limit('upload-start-ip', key, 3, 900)
|
||||
except HTTPException as error:
|
||||
assert error.status_code == 429, error
|
||||
assert error.headers.get('Retry-After') == '900', error.headers
|
||||
else:
|
||||
raise AssertionError('the per-source upload bucket accepted above its limit')
|
||||
print('PASS: 70 upload starts in one session; the per-source bucket refuses above its limit')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
Reference in New Issue
Block a user