summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorBrian Lamar <brian.lamar@rackspace.com>2011-02-28 14:49:03 -0500
committerBrian Lamar <brian.lamar@rackspace.com>2011-02-28 14:49:03 -0500
commit05a96b320cf1d6b911b0edb11df0ed408a894e77 (patch)
treed08600d2ac9fd748fec1e052eb9faedab7a679ce /nova/tests
parent4aa2ffe87744d3653c741d4d3e019114e3e9e5bf (diff)
Edited `nova.api.openstack.common:limited` method to raise an HTTPBadRequest
exception if a negative limit or offset is given. I'm not confident that this is the correct approach, because I guess this method could be called out of an API/WSGI context, but the method *is* located in the OpenStack API module and is currently only used in WSGI-capable methods, so we should be safe.
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/test_common.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py
index 59d850157..92023362c 100644
--- a/nova/tests/api/openstack/test_common.py
+++ b/nova/tests/api/openstack/test_common.py
@@ -19,6 +19,7 @@
Test suites for 'common' code used throughout the OpenStack HTTP API.
"""
+import webob.exc
from webob import Request
@@ -160,3 +161,23 @@ class LimiterTest(test.TestCase):
self.assertEqual(limited(items, req, max_limit=2000), items[3:])
req = Request.blank('/?offset=3000&limit=10')
self.assertEqual(limited(items, req, max_limit=2000), [])
+
+ def test_limiter_negative_limit(self):
+ """
+ Test a negative limit.
+ """
+ def _limit_large():
+ limited(self.large, req, max_limit=2000)
+
+ req = Request.blank('/?limit=-3000')
+ self.assertRaises(webob.exc.HTTPBadRequest, _limit_large)
+
+ def test_limiter_negative_offset(self):
+ """
+ Test a negative offset.
+ """
+ def _limit_large():
+ limited(self.large, req, max_limit=2000)
+
+ req = Request.blank('/?offset=-30')
+ self.assertRaises(webob.exc.HTTPBadRequest, _limit_large)