summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorRongze Zhu <zrzhit@gmail.com>2012-09-12 09:18:53 +0000
committerRongze Zhu <zrzhit@gmail.com>2012-09-13 05:19:55 +0000
commitcce5cf45f738ed95a96a4526253bec01a15277f0 (patch)
tree5aab122f9f70071a4f9857bc16a713b884643671 /nova/tests
parente72db9fe9345c48f4ea287643306d884c82f04f4 (diff)
Return 400 if create volume snapshot force parameter is invalid
Fixes bug #1014689 * Add is_valid_boolstr function in utils.py * Add force parameter check in SnapshotsController.create() * Add unittest for invalid force parameter. Change-Id: Ie6a07a2ac589da76f52a82b126a6d66e5987edc4
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_snapshots.py13
-rw-r--r--nova/tests/api/openstack/volume/test_snapshots.py10
2 files changed, 23 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_snapshots.py b/nova/tests/api/openstack/compute/contrib/test_snapshots.py
index ad2d9b322..5a9e8dbbb 100644
--- a/nova/tests/api/openstack/compute/contrib/test_snapshots.py
+++ b/nova/tests/api/openstack/compute/contrib/test_snapshots.py
@@ -165,6 +165,19 @@ class SnapshotApiTest(test.TestCase):
self.assertEqual(resp_dict['snapshot']['displayDescription'],
snapshot['display_description'])
+ # Test invalid force paramter
+ snapshot = {"volume_id": 12,
+ "force": '**&&^^%%$$##@@'}
+ body = dict(snapshot=snapshot)
+ req = webob.Request.blank('/v2/fake/os-snapshots')
+ req.method = 'POST'
+ req.body = jsonutils.dumps(body)
+ req.headers['content-type'] = 'application/json'
+
+ resp = req.get_response(fakes.wsgi_app())
+ LOG.debug(_("test_snapshot_create_force: param=%s"), _last_param)
+ self.assertEqual(resp.status_int, 400)
+
def test_snapshot_delete(self):
global _last_param
_last_param = {}
diff --git a/nova/tests/api/openstack/volume/test_snapshots.py b/nova/tests/api/openstack/volume/test_snapshots.py
index ef4724338..c65182cb7 100644
--- a/nova/tests/api/openstack/volume/test_snapshots.py
+++ b/nova/tests/api/openstack/volume/test_snapshots.py
@@ -114,6 +114,16 @@ class SnapshotApiTest(test.TestCase):
self.assertEqual(resp_dict['snapshot']['display_description'],
snapshot['display_description'])
+ # Test invalid force paramter
+ snapshot = {"volume_id": 12,
+ "force": '**&&^^%%$$##@@'}
+ body = dict(snapshot=snapshot)
+ req = fakes.HTTPRequest.blank('/v1/snapshots')
+ self.assertRaises(exception.InvalidParameterValue,
+ self.controller.create,
+ req,
+ body)
+
def test_snapshot_delete(self):
self.stubs.Set(volume.api.API, "get_snapshot", stub_snapshot_get)
self.stubs.Set(volume.api.API, "delete_snapshot", stub_snapshot_delete)