(self)
| 41 | |
| 42 | class TestFormParser: |
| 43 | def test_limiting(self): |
| 44 | data = b"foo=Hello+World&bar=baz" |
| 45 | req = Request.from_values( |
| 46 | input_stream=io.BytesIO(data), |
| 47 | content_length=len(data), |
| 48 | content_type="application/x-www-form-urlencoded", |
| 49 | method="POST", |
| 50 | ) |
| 51 | req.max_content_length = 400 |
| 52 | assert req.form["foo"] == "Hello World" |
| 53 | |
| 54 | req = Request.from_values( |
| 55 | input_stream=io.BytesIO(data), |
| 56 | content_length=len(data), |
| 57 | content_type="application/x-www-form-urlencoded", |
| 58 | method="POST", |
| 59 | ) |
| 60 | req.max_form_memory_size = 7 |
| 61 | pytest.raises(RequestEntityTooLarge, lambda: req.form["foo"]) |
| 62 | |
| 63 | req = Request.from_values( |
| 64 | input_stream=io.BytesIO(data), |
| 65 | content_length=len(data), |
| 66 | content_type="application/x-www-form-urlencoded", |
| 67 | method="POST", |
| 68 | ) |
| 69 | req.max_form_memory_size = 400 |
| 70 | assert req.form["foo"] == "Hello World" |
| 71 | |
| 72 | input_stream = io.BytesIO(b"foo=123456") |
| 73 | req = Request.from_values( |
| 74 | input_stream=input_stream, |
| 75 | content_type="application/x-www-form-urlencoded", |
| 76 | method="POST", |
| 77 | ) |
| 78 | req.max_content_length = 4 |
| 79 | pytest.raises(RequestEntityTooLarge, lambda: req.form["foo"]) |
| 80 | # content-length was set, so request could exit early without reading anything |
| 81 | assert input_stream.read() == b"foo=123456" |
| 82 | |
| 83 | data = ( |
| 84 | b"--foo\r\nContent-Disposition: form-field; name=foo\r\n\r\n" |
| 85 | b"Hello World\r\n" |
| 86 | b"--foo\r\nContent-Disposition: form-field; name=bar\r\n\r\n" |
| 87 | b"bar=baz\r\n--foo--" |
| 88 | ) |
| 89 | req = Request.from_values( |
| 90 | input_stream=io.BytesIO(data), |
| 91 | content_length=len(data), |
| 92 | content_type="multipart/form-data; boundary=foo", |
| 93 | method="POST", |
| 94 | ) |
| 95 | req.max_content_length = 400 |
| 96 | assert req.form["foo"] == "Hello World" |
| 97 | |
| 98 | req = Request.from_values( |
| 99 | input_stream=io.BytesIO(data), |
| 100 | content_length=len(data), |
nothing calls this directly
no test coverage detected