Convert maximum length to integer in name_check
This patch converts maximum_length to integer in name_check middleware if read from proxy-server.conf file. Change-Id: I28d66fd1b7ce56ca5540cb7189d084c36e063d43 Closes-Bug: 1372397
This commit is contained in:
parent
6d5206325a
commit
0c0ac09a46
@ -59,7 +59,7 @@ class NameCheckMiddleware(object):
|
||||
self.conf = conf
|
||||
self.forbidden_chars = self.conf.get('forbidden_chars',
|
||||
FORBIDDEN_CHARS)
|
||||
self.maximum_length = self.conf.get('maximum_length', MAX_LENGTH)
|
||||
self.maximum_length = int(self.conf.get('maximum_length', MAX_LENGTH))
|
||||
self.forbidden_regexp = self.conf.get('forbidden_regexp',
|
||||
FORBIDDEN_REGEXP)
|
||||
if self.forbidden_regexp:
|
||||
@ -120,18 +120,20 @@ class NameCheckMiddleware(object):
|
||||
if self.check_character(req):
|
||||
return HTTPBadRequest(
|
||||
request=req,
|
||||
body=("Object/Container name contains forbidden chars from %s"
|
||||
body=("Object/Container/Account name contains forbidden "
|
||||
"chars from %s"
|
||||
% self.forbidden_chars))(env, start_response)
|
||||
elif self.check_length(req):
|
||||
return HTTPBadRequest(
|
||||
request=req,
|
||||
body=("Object/Container name longer than the allowed maximum "
|
||||
body=("Object/Container/Account name longer than the "
|
||||
"allowed maximum "
|
||||
"%s" % self.maximum_length))(env, start_response)
|
||||
elif self.check_regexp(req):
|
||||
return HTTPBadRequest(
|
||||
request=req,
|
||||
body=("Object/Container name contains a forbidden substring "
|
||||
"from regular expression %s"
|
||||
body=("Object/Container/Account name contains a forbidden "
|
||||
"substring from regular expression %s"
|
||||
% self.forbidden_regexp))(env, start_response)
|
||||
else:
|
||||
# Pass on to downstream WSGI component
|
||||
|
@ -58,17 +58,39 @@ class TestNameCheckMiddleware(unittest.TestCase):
|
||||
self.test_check)
|
||||
self.assertEquals(
|
||||
resp.body,
|
||||
("Object/Container name contains forbidden chars from %s"
|
||||
% self.conf['forbidden_chars']))
|
||||
("Object/Container/Account name contains forbidden chars "
|
||||
"from %s" % self.conf['forbidden_chars']))
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
def test_maximum_length_from_config(self):
|
||||
# test invalid length
|
||||
orig_test_check = self.test_check
|
||||
conf = {'maximum_length': "500"}
|
||||
self.test_check = name_check.filter_factory(conf)(FakeApp())
|
||||
path = '/V1.0/a/c' + 'o' * (500 - 8)
|
||||
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
|
||||
).get_response(self.test_check)
|
||||
self.assertEquals(
|
||||
resp.body,
|
||||
("Object/Container/Account name longer than the allowed "
|
||||
"maximum 500"))
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
# test valid length
|
||||
path = '/V1.0/a/c' + 'o' * (MAX_LENGTH - 10)
|
||||
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
|
||||
).get_response(self.test_check)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assertEquals(resp.body, 'OK')
|
||||
self.test_check = orig_test_check
|
||||
|
||||
def test_invalid_length(self):
|
||||
path = '/V1.0/' + 'c' * (MAX_LENGTH - 5)
|
||||
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
|
||||
).get_response(self.test_check)
|
||||
self.assertEquals(
|
||||
resp.body,
|
||||
("Object/Container name longer than the allowed maximum %s"
|
||||
("Object/Container/Account name longer than the allowed maximum %s"
|
||||
% self.conf['maximum_length']))
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
@ -80,8 +102,8 @@ class TestNameCheckMiddleware(unittest.TestCase):
|
||||
self.test_check)
|
||||
self.assertEquals(
|
||||
resp.body,
|
||||
("Object/Container name contains a forbidden substring "
|
||||
"from regular expression %s"
|
||||
("Object/Container/Account name contains a forbidden "
|
||||
"substring from regular expression %s"
|
||||
% self.conf['forbidden_regexp']))
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user