|
| 1 | +import random |
| 2 | +import string |
1 | 3 | from unittest.mock import Mock
|
2 | 4 |
|
3 | 5 | import pytest
|
4 |
| -from aiohttp.web_app import Application |
5 | 6 | from ipv8.util import succeed
|
6 | 7 |
|
7 | 8 | from tribler.core.components.libtorrent.restapi.create_torrent_endpoint import CreateTorrentEndpoint
|
8 | 9 | from tribler.core.components.libtorrent.settings import DownloadDefaultsSettings
|
9 | 10 | from tribler.core.components.restapi.rest.base_api_test import do_request
|
10 |
| -from tribler.core.components.restapi.rest.rest_manager import error_middleware |
| 11 | +from tribler.core.components.restapi.rest.rest_endpoint import HTTP_REQUEST_ENTITY_TOO_LARGE, MAX_REQUEST_SIZE |
11 | 12 | from tribler.core.tests.tools.common import TESTS_DATA_DIR
|
12 | 13 |
|
13 | 14 |
|
@@ -77,6 +78,31 @@ def fake_create_torrent_file(*_, **__):
|
77 | 78 | assert expected_response == error_response
|
78 | 79 |
|
79 | 80 |
|
| 81 | +async def test_create_torrent_of_large_size(rest_api): |
| 82 | + """ |
| 83 | + Testing whether the API returns a formatted 413 error if request size is above set client size. |
| 84 | + """ |
| 85 | + |
| 86 | + post_data = { |
| 87 | + "description": ''.join(random.choice(string.ascii_letters) for _ in range(MAX_REQUEST_SIZE)) |
| 88 | + } |
| 89 | + |
| 90 | + error_response = await do_request( |
| 91 | + rest_api, 'createtorrent', |
| 92 | + expected_code=HTTP_REQUEST_ENTITY_TOO_LARGE, |
| 93 | + request_type='POST', |
| 94 | + post_data=post_data |
| 95 | + ) |
| 96 | + |
| 97 | + expected_response = { |
| 98 | + "error": { |
| 99 | + "handled": True, |
| 100 | + "message": f"Request size is larger than {MAX_REQUEST_SIZE} bytes" |
| 101 | + } |
| 102 | + } |
| 103 | + assert expected_response == error_response |
| 104 | + |
| 105 | + |
80 | 106 | async def test_create_torrent_missing_files_parameter(rest_api):
|
81 | 107 | expected_json = {"error": "files parameter missing"}
|
82 | 108 | await do_request(rest_api, 'createtorrent', expected_code=400, expected_json=expected_json, request_type='POST')
|
0 commit comments