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:
Igor Malinovskiy 2014-12-12 16:39:35 +02:00
parent 1a2ec3da9b
commit 9c72d34df7
3 changed files with 14 additions and 3 deletions

View File

@ -525,7 +525,7 @@ class API(base.Base):
metadata = {}
for k, v in six.iteritems(metadata):
if len(k) == 0:
if not k:
msg = _("Metadata property key is blank")
LOG.warn(msg)
raise exception.InvalidShareMetadata(message=msg)
@ -533,6 +533,10 @@ class API(base.Base):
msg = _("Metadata property key is greater than 255 characters")
LOG.warn(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:
msg = _("Metadata property value is "
"greater than 1023 characters")

View File

@ -15,6 +15,7 @@
import uuid
import ddt
from oslo.config import cfg
from oslo.serialization import jsonutils
import webob
@ -83,6 +84,7 @@ def fake_update_share_metadata(self, context, share, diff):
pass
@ddt.ddt
class ShareMetaDataTest(test.TestCase):
def setUp(self):
@ -293,13 +295,17 @@ class ShareMetaDataTest(test.TestCase):
self.controller.update_all, req, self.req_id,
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',
return_create_share_metadata)
req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': ['asdf']}
expected = {'metadata': metadata}
req.body = jsonutils.dumps(expected)
self.assertRaises(webob.exc.HTTPBadRequest,

View File

@ -6,6 +6,7 @@
hacking>=0.9.2,<0.10
coverage>=3.6
ddt>=0.4.0
discover
fixtures>=0.3.14
mock>=1.0