Skip to content

Commit

Permalink
fix: validate queue listing limits in proxy
Browse files Browse the repository at this point in the history
Adds the appropriate unit test to show that this works and keeps
working for the forseeable future.

Change-Id: I25d3ba3f9b1e3a51d8ba86171cd7329585c3e080
Closes-Bug: 1234481
  • Loading branch information
Alejandro Cabrera committed Oct 9, 2013
1 parent 2273b2f commit 39d0d2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 0 additions & 1 deletion marconi/proxy/storage/__init__.py
Expand Up @@ -3,7 +3,6 @@
from marconi.proxy.storage import base
from marconi.proxy.storage import exceptions # NOQA


# NOTE(cpp-cabrera): Hoist classes into package namespace
CatalogueBase = base.CatalogueBase
DriverBase = base.DriverBase
Expand Down
17 changes: 16 additions & 1 deletion marconi/proxy/transport/wsgi/queues.py
Expand Up @@ -31,13 +31,20 @@
import json

import falcon
from oslo.config import cfg
import six

from marconi.openstack.common import log
from marconi.proxy.utils import (
forward, lookup, helpers, http, partition
)
from marconi.queues import storage # NOQA
from marconi.queues.transport import validation as validate
from marconi.queues.transport.wsgi import exceptions as wsgi_exceptions


LOG = log.getLogger(__name__)
STORAGE_LIMITS = cfg.CONF['queues:limits:storage']


class Listing(object):
Expand All @@ -62,6 +69,14 @@ def on_get(self, request, response):
request.get_param_as_bool('detailed', store=kwargs)

resp = collections.defaultdict(list)
limit = kwargs.get('limit',
STORAGE_LIMITS.default_queue_paging)

try:
validate.queue_listing(limit=limit)
except validate.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex))

for queue in self._catalogue.list(project):
queue_name = queue['name']
if queue_name < kwargs.get('marker', ''):
Expand All @@ -74,7 +89,7 @@ def on_get(self, request, response):
entry['metadata'] = queue['metadata']
resp['queues'].append(entry)
kwargs['marker'] = queue_name
if len(resp['queues']) == kwargs.get('limit', 0):
if len(resp['queues']) == limit:
break

if not resp:
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/proxy/test_queues.py
Expand Up @@ -132,6 +132,12 @@ def test_list_queues_with_option_detailed(self):
for entry in doc['queues']:
self.assertIn('metadata', entry)

@ddt.data(-1, 0, 30)
def test_list_queues_raises_400_with_invalid_limit(self, limit):
self.simulate_get('/v1/queues',
query_string='limit={0}'.format(limit))
self.assertEqual(self.srmock.status, falcon.HTTP_400)


@ddt.ddt
class QueuesWithNoPartitionsTest(base.TestBase):
Expand Down

0 comments on commit 39d0d2f

Please sign in to comment.