Skip to content

Commit

Permalink
Limit number of multicalls to 20
Browse files Browse the repository at this point in the history
  • Loading branch information
di committed Apr 23, 2018
1 parent 20a53c7 commit f38ae14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/unit/legacy/api/xmlrpc/test_xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,14 @@ def test_missing_multicall_method(self):
assert exc.value.faultString == (
'ValueError: Method name not provided'
)

def test_too_many_multicalls_method(self):
request = pretend.stub()
args = [{'methodName': 'nah'}] * 21

with pytest.raises(xmlrpc.XMLRPCWrappedError) as exc:
xmlrpc.multicall(request, args)

assert exc.value.faultString == (
'ValueError: Multicall limit is 20 calls'
)
8 changes: 7 additions & 1 deletion warehouse/legacy/api/xmlrpc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
)


_MAX_MULTICALLS = 20


def xmlrpc_method(**kwargs):
"""
Support multiple endpoints serving the same views by chaining calls to
Expand Down Expand Up @@ -453,8 +456,11 @@ def multicall(request, args):
)

if not all(arg.get('methodName') for arg in args):
raise XMLRPCWrappedError(ValueError('Method name not provided'))

if len(args) > _MAX_MULTICALLS:
raise XMLRPCWrappedError(
ValueError('Method name not provided')
ValueError(f'Multicall limit is {_MAX_MULTICALLS} calls')
)

responses = []
Expand Down

0 comments on commit f38ae14

Please sign in to comment.