Incorrect handling of torrent's params[b'announce-list']
and the trackers
parameter of the /createtorrent
endpoint
#7825
Labels
params[b'announce-list']
and the trackers
parameter of the /createtorrent
endpoint
#7825
While reviewing #7816 I found an error in how the
/createtorrent
endpoint handles thetracker
parameter.The
test_create_torrent
test sends the following params to the endpoint:That is, it sends "trackers" as a string, while it should be a list of string URLs. This fact is reflected in the Swagger API description of the endpoint:
You can see the
'trackers': [String]
part of the endpoint description.I expected that during the test run Swagger should catch the incorrect parameters, but it does not happen. It looks like something should be fixed about how Swagger is used in tests.
Anyway, this is how the
trackers
parameter is handled inside the endpoint:So, the code expects that the value of
parameters['trackers']
should be of list type. As the plain string"http://localhost/announce"
is passed as a parameter, the resulted value ofparams['announce']
is"h"
, the first letter of the string. But then the parsed value is ignored by the test, so this error remained unnoticed.So the first error is in test, as it passed an incorrect value to the endpoint.
Another error is in the endpoint itself, as
params['announce-list']
should not be list, it should be of typeList[List[str]]
, where each list represents a "tier" of trackers (on practice, there is usually only one tier). To thrigger the error it is necessary to pass a list of several tracker URLs, in this case the structure of the resultedparams['announce-list']
is incorrect.And the third bug is in the inner
torrent_utils.create_torrent_file
function that handles the created params:Here, the function incorrectly handles tracker tiers and assumes that
params[b'announce-list']
contains list of strings, while in fact it should contain lists of lists of strings. The third error compensates for the second error, but probably not in all cases, astorrent_utils.create_torrent_file
is also called fromTorrentDef.save()
.The text was updated successfully, but these errors were encountered: