Fix metadata validation in share api
Currently validation method _check_metadata_properties() expects that metadata parameter is a dict which contains string keys and values, but this assumption is incorrect, because user can specify key without value or vice versa. Change-Id: I5cc863bb89f986815a4f6c1addf593f2da62530f Closes-Bug: #1392827
This commit is contained in:
parent
1a2ec3da9b
commit
9c72d34df7
@ -525,7 +525,7 @@ class API(base.Base):
|
|||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
||||||
for k, v in six.iteritems(metadata):
|
for k, v in six.iteritems(metadata):
|
||||||
if len(k) == 0:
|
if not k:
|
||||||
msg = _("Metadata property key is blank")
|
msg = _("Metadata property key is blank")
|
||||||
LOG.warn(msg)
|
LOG.warn(msg)
|
||||||
raise exception.InvalidShareMetadata(message=msg)
|
raise exception.InvalidShareMetadata(message=msg)
|
||||||
@ -533,6 +533,10 @@ class API(base.Base):
|
|||||||
msg = _("Metadata property key is greater than 255 characters")
|
msg = _("Metadata property key is greater than 255 characters")
|
||||||
LOG.warn(msg)
|
LOG.warn(msg)
|
||||||
raise exception.InvalidShareMetadataSize(message=msg)
|
raise exception.InvalidShareMetadataSize(message=msg)
|
||||||
|
if not v:
|
||||||
|
msg = _("Metadata property value is blank")
|
||||||
|
LOG.warn(msg)
|
||||||
|
raise exception.InvalidShareMetadata(message=msg)
|
||||||
if len(v) > 1023:
|
if len(v) > 1023:
|
||||||
msg = _("Metadata property value is "
|
msg = _("Metadata property value is "
|
||||||
"greater than 1023 characters")
|
"greater than 1023 characters")
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import ddt
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
from oslo.serialization import jsonutils
|
from oslo.serialization import jsonutils
|
||||||
import webob
|
import webob
|
||||||
@ -83,6 +84,7 @@ def fake_update_share_metadata(self, context, share, diff):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
class ShareMetaDataTest(test.TestCase):
|
class ShareMetaDataTest(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -293,13 +295,17 @@ class ShareMetaDataTest(test.TestCase):
|
|||||||
self.controller.update_all, req, self.req_id,
|
self.controller.update_all, req, self.req_id,
|
||||||
expected)
|
expected)
|
||||||
|
|
||||||
def test_update_all_malformed_data(self):
|
@ddt.data(['asdf'],
|
||||||
|
{'key': None},
|
||||||
|
{None: 'value'},
|
||||||
|
{None: None})
|
||||||
|
def test_update_all_malformed_data(self, metadata):
|
||||||
self.stubs.Set(manila.db, 'share_metadata_update',
|
self.stubs.Set(manila.db, 'share_metadata_update',
|
||||||
return_create_share_metadata)
|
return_create_share_metadata)
|
||||||
req = fakes.HTTPRequest.blank(self.url)
|
req = fakes.HTTPRequest.blank(self.url)
|
||||||
req.method = 'PUT'
|
req.method = 'PUT'
|
||||||
req.content_type = "application/json"
|
req.content_type = "application/json"
|
||||||
expected = {'metadata': ['asdf']}
|
expected = {'metadata': metadata}
|
||||||
req.body = jsonutils.dumps(expected)
|
req.body = jsonutils.dumps(expected)
|
||||||
|
|
||||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
hacking>=0.9.2,<0.10
|
hacking>=0.9.2,<0.10
|
||||||
|
|
||||||
coverage>=3.6
|
coverage>=3.6
|
||||||
|
ddt>=0.4.0
|
||||||
discover
|
discover
|
||||||
fixtures>=0.3.14
|
fixtures>=0.3.14
|
||||||
mock>=1.0
|
mock>=1.0
|
||||||
|
Loading…
Reference in New Issue
Block a user