add assert error information
There are the same error resp.status_int in different operators of one function, then I can't point out which one returns this status_int. Therefore, I assert error information. Change-Id: I58bcba97a9f92e43e0f8ef26b801b69a6906af41
This commit is contained in:
parent
026c5b9b7c
commit
a3dbc139c3
@ -26,6 +26,7 @@ from swift.common.swob import Request, HTTPException
|
|||||||
from swift.common.http import HTTP_REQUEST_ENTITY_TOO_LARGE, \
|
from swift.common.http import HTTP_REQUEST_ENTITY_TOO_LARGE, \
|
||||||
HTTP_BAD_REQUEST, HTTP_LENGTH_REQUIRED, HTTP_NOT_IMPLEMENTED
|
HTTP_BAD_REQUEST, HTTP_LENGTH_REQUIRED, HTTP_NOT_IMPLEMENTED
|
||||||
from swift.common import constraints, utils
|
from swift.common import constraints, utils
|
||||||
|
from swift.common.constraints import MAX_OBJECT_NAME_LENGTH
|
||||||
|
|
||||||
|
|
||||||
class TestConstraints(unittest.TestCase):
|
class TestConstraints(unittest.TestCase):
|
||||||
@ -49,16 +50,23 @@ class TestConstraints(unittest.TestCase):
|
|||||||
|
|
||||||
def test_check_metadata_empty_name(self):
|
def test_check_metadata_empty_name(self):
|
||||||
headers = {'X-Object-Meta-': 'Value'}
|
headers = {'X-Object-Meta-': 'Value'}
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
resp = constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'object').status_int, HTTP_BAD_REQUEST)
|
'/', headers=headers), 'object')
|
||||||
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('Metadata name cannot be empty', resp.body)
|
||||||
|
|
||||||
def test_check_metadata_non_utf8(self):
|
def test_check_metadata_non_utf8(self):
|
||||||
headers = {'X-Account-Meta-Foo': b'\xff'}
|
headers = {'X-Account-Meta-Foo': b'\xff'}
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
resp = constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'account').status_int, HTTP_BAD_REQUEST)
|
'/', headers=headers), 'account')
|
||||||
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('Metadata must be valid UTF-8', resp.body)
|
||||||
|
|
||||||
headers = {b'X-Container-Meta-\xff': 'foo'}
|
headers = {b'X-Container-Meta-\xff': 'foo'}
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
resp = constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'container').status_int, HTTP_BAD_REQUEST)
|
'/', headers=headers), 'container')
|
||||||
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('Metadata must be valid UTF-8', resp.body)
|
||||||
# Object's OK; its metadata isn't serialized as JSON
|
# Object's OK; its metadata isn't serialized as JSON
|
||||||
headers = {'X-Object-Meta-Foo': b'\xff'}
|
headers = {'X-Object-Meta-Foo': b'\xff'}
|
||||||
self.assertIsNone(constraints.check_metadata(Request.blank(
|
self.assertIsNone(constraints.check_metadata(Request.blank(
|
||||||
@ -69,34 +77,31 @@ class TestConstraints(unittest.TestCase):
|
|||||||
headers = {'X-Object-Meta-%s' % name: 'v'}
|
headers = {'X-Object-Meta-%s' % name: 'v'}
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
self.assertEqual(constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'object'), None)
|
'/', headers=headers), 'object'), None)
|
||||||
|
|
||||||
name = 'a' * (constraints.MAX_META_NAME_LENGTH + 1)
|
name = 'a' * (constraints.MAX_META_NAME_LENGTH + 1)
|
||||||
headers = {'X-Object-Meta-%s' % name: 'v'}
|
headers = {'X-Object-Meta-%s' % name: 'v'}
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
resp = constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'object').status_int, HTTP_BAD_REQUEST)
|
'/', headers=headers), 'object')
|
||||||
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
('X-Object-Meta-%s' % name).lower(),
|
('X-Object-Meta-%s' % name).lower(), resp.body.lower())
|
||||||
constraints.check_metadata(Request.blank(
|
self.assertIn('Metadata name too long', resp.body)
|
||||||
'/', headers=headers), 'object').body.lower())
|
|
||||||
|
|
||||||
def test_check_metadata_value_length(self):
|
def test_check_metadata_value_length(self):
|
||||||
value = 'a' * constraints.MAX_META_VALUE_LENGTH
|
value = 'a' * constraints.MAX_META_VALUE_LENGTH
|
||||||
headers = {'X-Object-Meta-Name': value}
|
headers = {'X-Object-Meta-Name': value}
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
self.assertEqual(constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'object'), None)
|
'/', headers=headers), 'object'), None)
|
||||||
|
|
||||||
value = 'a' * (constraints.MAX_META_VALUE_LENGTH + 1)
|
value = 'a' * (constraints.MAX_META_VALUE_LENGTH + 1)
|
||||||
headers = {'X-Object-Meta-Name': value}
|
headers = {'X-Object-Meta-Name': value}
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
resp = constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'object').status_int, HTTP_BAD_REQUEST)
|
'/', headers=headers), 'object')
|
||||||
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('x-object-meta-name', resp.body.lower())
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'x-object-meta-name',
|
str(constraints.MAX_META_VALUE_LENGTH), resp.body)
|
||||||
constraints.check_metadata(Request.blank(
|
self.assertIn('Metadata value longer than 256', resp.body)
|
||||||
'/', headers=headers),
|
|
||||||
'object').body.lower())
|
|
||||||
self.assertIn(
|
|
||||||
str(constraints.MAX_META_VALUE_LENGTH),
|
|
||||||
constraints.check_metadata(Request.blank(
|
|
||||||
'/', headers=headers),
|
|
||||||
'object').body)
|
|
||||||
|
|
||||||
def test_check_metadata_count(self):
|
def test_check_metadata_count(self):
|
||||||
headers = {}
|
headers = {}
|
||||||
@ -104,9 +109,12 @@ class TestConstraints(unittest.TestCase):
|
|||||||
headers['X-Object-Meta-%d' % x] = 'v'
|
headers['X-Object-Meta-%d' % x] = 'v'
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
self.assertEqual(constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'object'), None)
|
'/', headers=headers), 'object'), None)
|
||||||
|
|
||||||
headers['X-Object-Meta-Too-Many'] = 'v'
|
headers['X-Object-Meta-Too-Many'] = 'v'
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
resp = constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'object').status_int, HTTP_BAD_REQUEST)
|
'/', headers=headers), 'object')
|
||||||
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('Too many metadata items', resp.body)
|
||||||
|
|
||||||
def test_check_metadata_size(self):
|
def test_check_metadata_size(self):
|
||||||
headers = {}
|
headers = {}
|
||||||
@ -130,8 +138,10 @@ class TestConstraints(unittest.TestCase):
|
|||||||
headers['X-Object-Meta-%04d%s' %
|
headers['X-Object-Meta-%04d%s' %
|
||||||
(x + 1, 'a' * (constraints.MAX_META_NAME_LENGTH - 4))] = \
|
(x + 1, 'a' * (constraints.MAX_META_NAME_LENGTH - 4))] = \
|
||||||
'v' * constraints.MAX_META_VALUE_LENGTH
|
'v' * constraints.MAX_META_VALUE_LENGTH
|
||||||
self.assertEqual(constraints.check_metadata(Request.blank(
|
resp = constraints.check_metadata(Request.blank(
|
||||||
'/', headers=headers), 'object').status_int, HTTP_BAD_REQUEST)
|
'/', headers=headers), 'object')
|
||||||
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('Total metadata too large', resp.body)
|
||||||
|
|
||||||
def test_check_object_creation_content_length(self):
|
def test_check_object_creation_content_length(self):
|
||||||
headers = {'Content-Length': str(constraints.MAX_FILE_SIZE),
|
headers = {'Content-Length': str(constraints.MAX_FILE_SIZE),
|
||||||
@ -141,9 +151,9 @@ class TestConstraints(unittest.TestCase):
|
|||||||
|
|
||||||
headers = {'Content-Length': str(constraints.MAX_FILE_SIZE + 1),
|
headers = {'Content-Length': str(constraints.MAX_FILE_SIZE + 1),
|
||||||
'Content-Type': 'text/plain'}
|
'Content-Type': 'text/plain'}
|
||||||
self.assertEqual(constraints.check_object_creation(
|
resp = constraints.check_object_creation(
|
||||||
Request.blank('/', headers=headers), 'object_name').status_int,
|
Request.blank('/', headers=headers), 'object_name')
|
||||||
HTTP_REQUEST_ENTITY_TOO_LARGE)
|
self.assertEqual(resp.status_int, HTTP_REQUEST_ENTITY_TOO_LARGE)
|
||||||
|
|
||||||
headers = {'Transfer-Encoding': 'chunked',
|
headers = {'Transfer-Encoding': 'chunked',
|
||||||
'Content-Type': 'text/plain'}
|
'Content-Type': 'text/plain'}
|
||||||
@ -152,26 +162,28 @@ class TestConstraints(unittest.TestCase):
|
|||||||
|
|
||||||
headers = {'Transfer-Encoding': 'gzip',
|
headers = {'Transfer-Encoding': 'gzip',
|
||||||
'Content-Type': 'text/plain'}
|
'Content-Type': 'text/plain'}
|
||||||
self.assertEqual(constraints.check_object_creation(Request.blank(
|
resp = constraints.check_object_creation(Request.blank(
|
||||||
'/', headers=headers), 'object_name').status_int,
|
'/', headers=headers), 'object_name')
|
||||||
HTTP_BAD_REQUEST)
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('Invalid Transfer-Encoding header value', resp.body)
|
||||||
|
|
||||||
headers = {'Content-Type': 'text/plain'}
|
headers = {'Content-Type': 'text/plain'}
|
||||||
self.assertEqual(constraints.check_object_creation(
|
resp = constraints.check_object_creation(
|
||||||
Request.blank('/', headers=headers), 'object_name').status_int,
|
Request.blank('/', headers=headers), 'object_name')
|
||||||
HTTP_LENGTH_REQUIRED)
|
self.assertEqual(resp.status_int, HTTP_LENGTH_REQUIRED)
|
||||||
|
|
||||||
headers = {'Content-Length': 'abc',
|
headers = {'Content-Length': 'abc',
|
||||||
'Content-Type': 'text/plain'}
|
'Content-Type': 'text/plain'}
|
||||||
self.assertEqual(constraints.check_object_creation(Request.blank(
|
resp = constraints.check_object_creation(Request.blank(
|
||||||
'/', headers=headers), 'object_name').status_int,
|
'/', headers=headers), 'object_name')
|
||||||
HTTP_BAD_REQUEST)
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('Invalid Content-Length header value', resp.body)
|
||||||
|
|
||||||
headers = {'Transfer-Encoding': 'gzip,chunked',
|
headers = {'Transfer-Encoding': 'gzip,chunked',
|
||||||
'Content-Type': 'text/plain'}
|
'Content-Type': 'text/plain'}
|
||||||
self.assertEqual(constraints.check_object_creation(Request.blank(
|
resp = constraints.check_object_creation(Request.blank(
|
||||||
'/', headers=headers), 'object_name').status_int,
|
'/', headers=headers), 'object_name')
|
||||||
HTTP_NOT_IMPLEMENTED)
|
self.assertEqual(resp.status_int, HTTP_NOT_IMPLEMENTED)
|
||||||
|
|
||||||
def test_check_object_creation_name_length(self):
|
def test_check_object_creation_name_length(self):
|
||||||
headers = {'Transfer-Encoding': 'chunked',
|
headers = {'Transfer-Encoding': 'chunked',
|
||||||
@ -179,20 +191,26 @@ class TestConstraints(unittest.TestCase):
|
|||||||
name = 'o' * constraints.MAX_OBJECT_NAME_LENGTH
|
name = 'o' * constraints.MAX_OBJECT_NAME_LENGTH
|
||||||
self.assertEqual(constraints.check_object_creation(Request.blank(
|
self.assertEqual(constraints.check_object_creation(Request.blank(
|
||||||
'/', headers=headers), name), None)
|
'/', headers=headers), name), None)
|
||||||
name = 'o' * (constraints.MAX_OBJECT_NAME_LENGTH + 1)
|
|
||||||
self.assertEqual(constraints.check_object_creation(
|
name = 'o' * (MAX_OBJECT_NAME_LENGTH + 1)
|
||||||
Request.blank('/', headers=headers), name).status_int,
|
resp = constraints.check_object_creation(
|
||||||
HTTP_BAD_REQUEST)
|
Request.blank('/', headers=headers), name)
|
||||||
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('Object name length of %d longer than %d' %
|
||||||
|
(MAX_OBJECT_NAME_LENGTH + 1, MAX_OBJECT_NAME_LENGTH),
|
||||||
|
resp.body)
|
||||||
|
|
||||||
def test_check_object_creation_content_type(self):
|
def test_check_object_creation_content_type(self):
|
||||||
headers = {'Transfer-Encoding': 'chunked',
|
headers = {'Transfer-Encoding': 'chunked',
|
||||||
'Content-Type': 'text/plain'}
|
'Content-Type': 'text/plain'}
|
||||||
self.assertEqual(constraints.check_object_creation(Request.blank(
|
self.assertEqual(constraints.check_object_creation(Request.blank(
|
||||||
'/', headers=headers), 'object_name'), None)
|
'/', headers=headers), 'object_name'), None)
|
||||||
|
|
||||||
headers = {'Transfer-Encoding': 'chunked'}
|
headers = {'Transfer-Encoding': 'chunked'}
|
||||||
self.assertEqual(constraints.check_object_creation(
|
resp = constraints.check_object_creation(
|
||||||
Request.blank('/', headers=headers), 'object_name').status_int,
|
Request.blank('/', headers=headers), 'object_name')
|
||||||
HTTP_BAD_REQUEST)
|
self.assertEqual(resp.status_int, HTTP_BAD_REQUEST)
|
||||||
|
self.assertIn('No content type', resp.body)
|
||||||
|
|
||||||
def test_check_object_creation_bad_content_type(self):
|
def test_check_object_creation_bad_content_type(self):
|
||||||
headers = {'Transfer-Encoding': 'chunked',
|
headers = {'Transfer-Encoding': 'chunked',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user