From f1cc8726058a5b3bc4b955e3441e498c2ead8471 Mon Sep 17 00:00:00 2001 From: zhangyanzi Date: Mon, 25 Nov 2013 19:33:49 +0800 Subject: [PATCH] The param 'readonly' is incorrect checked In the function os-update_readonly_flag, the param 'readonly' is incorrect checked, without the param in request, i think it should raise exception with message like "Must specify readonly in request." Change-Id: I19e15e988ffa2d093d374f6a33ce94d45ffe2c30 Closes-bug: 1254682 --- cinder/api/contrib/volume_actions.py | 4 ++++ cinder/tests/api/contrib/test_volume_actions.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py index 40179b9c7..61db01cf4 100644 --- a/cinder/api/contrib/volume_actions.py +++ b/cinder/api/contrib/volume_actions.py @@ -280,6 +280,10 @@ class VolumeActionsController(wsgi.Controller): raise webob.exc.HTTPNotFound(explanation=error.msg) readonly_flag = body['os-update_readonly_flag'].get('readonly') + if not readonly_flag: + msg = _("Must specify readonly in request.") + raise webob.exc.HTTPBadRequest(explanation=msg) + if isinstance(readonly_flag, basestring): try: readonly_flag = strutils.bool_from_string(readonly_flag, diff --git a/cinder/tests/api/contrib/test_volume_actions.py b/cinder/tests/api/contrib/test_volume_actions.py index 45658ac04..a348b5e3b 100644 --- a/cinder/tests/api/contrib/test_volume_actions.py +++ b/cinder/tests/api/contrib/test_volume_actions.py @@ -241,6 +241,8 @@ class VolumeActionsTest(test.TestCase): def make_update_readonly_flag_test(self, readonly, return_code): body = {"os-update_readonly_flag": {"readonly": readonly}} + if readonly is None: + body = {"os-update_readonly_flag": {}} req = webob.Request.blank('/v2/fake/volumes/1/action') req.method = "POST" req.body = jsonutils.dumps(body) @@ -254,6 +256,7 @@ class VolumeActionsTest(test.TestCase): make_update_readonly_flag_test(self, 'false', 202) make_update_readonly_flag_test(self, 'tt', 400) make_update_readonly_flag_test(self, 11, 400) + make_update_readonly_flag_test(self, None, 400) def stub_volume_get(self, context, volume_id): -- 2.45.2