1
# Copyright (c) 2012 OpenStack, LLC
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
17
import nova.api.sizelimit
18
from nova import flags
22
MAX_REQUEST_BODY_SIZE = FLAGS.osapi_max_request_body_size
25
class TestRequestBodySizeLimiter(test.TestCase):
28
super(TestRequestBodySizeLimiter, self).setUp()
32
return webob.Response()
34
self.middleware = nova.api.sizelimit.RequestBodySizeLimiter(fake_app)
35
self.request = webob.Request.blank('/', method='POST')
37
def test_content_length_acceptable(self):
38
self.request.headers['Content-Length'] = MAX_REQUEST_BODY_SIZE
39
self.request.body = "0" * MAX_REQUEST_BODY_SIZE
40
response = self.request.get_response(self.middleware)
41
self.assertEqual(response.status_int, 200)
43
def test_content_length_to_large(self):
44
self.request.headers['Content-Length'] = MAX_REQUEST_BODY_SIZE + 1
45
response = self.request.get_response(self.middleware)
46
self.assertEqual(response.status_int, 400)
48
def test_request_to_large(self):
49
self.request.body = "0" * (MAX_REQUEST_BODY_SIZE + 1)
50
response = self.request.get_response(self.middleware)
51
self.assertEqual(response.status_int, 400)