-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add config and docs for limits (#5626)
- Loading branch information
Showing
7 changed files
with
231 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import annotations | ||
|
||
from flask import Flask | ||
from flask import Request | ||
from flask import request | ||
from flask.testing import FlaskClient | ||
|
||
|
||
def test_max_content_length(app: Flask, client: FlaskClient) -> None: | ||
app.config["MAX_CONTENT_LENGTH"] = 50 | ||
|
||
@app.post("/") | ||
def index(): | ||
request.form["myfile"] | ||
AssertionError() | ||
|
||
@app.errorhandler(413) | ||
def catcher(error): | ||
return "42" | ||
|
||
rv = client.post("/", data={"myfile": "foo" * 50}) | ||
assert rv.data == b"42" | ||
|
||
|
||
def test_limit_config(app: Flask): | ||
app.config["MAX_CONTENT_LENGTH"] = 100 | ||
app.config["MAX_FORM_MEMORY_SIZE"] = 50 | ||
app.config["MAX_FORM_PARTS"] = 3 | ||
r = Request({}) | ||
|
||
# no app context, use Werkzeug defaults | ||
assert r.max_content_length is None | ||
assert r.max_form_memory_size == 500_000 | ||
assert r.max_form_parts == 1_000 | ||
|
||
# in app context, use config | ||
with app.app_context(): | ||
assert r.max_content_length == 100 | ||
assert r.max_form_memory_size == 50 | ||
assert r.max_form_parts == 3 | ||
|
||
# regardless of app context, use override | ||
r.max_content_length = 90 | ||
r.max_form_memory_size = 30 | ||
r.max_form_parts = 4 | ||
|
||
assert r.max_content_length == 90 | ||
assert r.max_form_memory_size == 30 | ||
assert r.max_form_parts == 4 | ||
|
||
with app.app_context(): | ||
assert r.max_content_length == 90 | ||
assert r.max_form_memory_size == 30 | ||
assert r.max_form_parts == 4 |