diff --git a/app/__init__.py b/app/__init__.py index 338f04a..a212815 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -40,6 +40,7 @@ def create_app(test_config: dict | None = None) -> Flask: app = Flask(__name__, template_folder="templates", static_folder="../static") app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1) + app.config["MAX_CONTENT_LENGTH"] = 64 * 1024 if test_config: app.config.update(test_config) @@ -56,6 +57,10 @@ def create_app(test_config: dict | None = None) -> Flask: ) app.limiter = limiter + @app.errorhandler(413) + def handle_payload_too_large(_exc): + return jsonify({"error": "El cuerpo de la solicitud excede el lĂ­mite permitido."}), 413 + @app.errorhandler(429) def handle_rate_limit(_exc): return ( diff --git a/tests/test_app.py b/tests/test_app.py index 20befc8..dcc16f9 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -703,6 +703,18 @@ def test_parse_body_rejects_non_dict_json(client): assert resp.status_code == 400 +def test_request_body_exceeding_max_content_length_returns_413(client): + test_client, _ = client + oversized = '{"padding": "' + ("a" * (65 * 1024)) + '"}' + resp = test_client.post( + "/api/appointments", + data=oversized, + content_type="application/json", + ) + assert resp.status_code == 413 + assert "error" in resp.get_json() + + def test_zoom_api_error_status_passthrough_returns_401(client, monkeypatch): test_client, _ = client monkeypatch.setattr(