summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-03-29 10:40:35 -0400
committerBrian Waldon <brian.waldon@rackspace.com>2011-03-29 10:40:35 -0400
commit793de5cef9fb539a4fb3ba976d83adde38a589c1 (patch)
tree935fb207d4449401e04d3790e54e6b1101c93d0b
parentf460d75ae355ee76b6c51d884162f00076140716 (diff)
downloadnova-793de5cef9fb539a4fb3ba976d83adde38a589c1.tar.gz
nova-793de5cef9fb539a4fb3ba976d83adde38a589c1.tar.xz
nova-793de5cef9fb539a4fb3ba976d83adde38a589c1.zip
adding more tests; making name checks more robust
-rw-r--r--nova/api/openstack/servers.py11
-rw-r--r--nova/tests/api/openstack/test_servers.py26
2 files changed, 34 insertions, 3 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index e9bc0a797..29c491716 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -250,8 +250,15 @@ class Controller(wsgi.Controller):
if 'name' in inst_dict['server']:
name = inst_dict['server']['name']
- if not isinstance(name, basestring) or name == '':
- return exc.HTTPBadRequest()
+ if not isinstance(name, basestring):
+ msg = _("Server name is not a string or unicode")
+ return exc.HTTPBadRequest(msg)
+
+ name = name.strip()
+
+ if name == '':
+ msg = _("Server name is an empty string")
+ return exc.HTTPBadRequest(msg)
update_dict['display_name'] = name
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 506b24b8b..ef4cf55b8 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -448,7 +448,31 @@ class ServersTest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 422)
- def test_update_bad_name(self):
+ def test_update_nonstring_name(self):
+ """ Confirm that update is filtering params """
+ inst_dict = dict(name=12, adminPass='bacon')
+ self.body = json.dumps(dict(server=inst_dict))
+
+ req = webob.Request.blank('/v1.0/servers/1')
+ req.method = 'PUT'
+ req.content_type = "application/json"
+ req.body = self.body
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 400)
+
+ def test_update_whitespace_name(self):
+ """ Confirm that update is filtering params """
+ inst_dict = dict(name=' ', adminPass='bacon')
+ self.body = json.dumps(dict(server=inst_dict))
+
+ req = webob.Request.blank('/v1.0/servers/1')
+ req.method = 'PUT'
+ req.content_type = "application/json"
+ req.body = self.body
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 400)
+
+ def test_update_null_name(self):
""" Confirm that update is filtering params """
inst_dict = dict(name='', adminPass='bacon')
self.body = json.dumps(dict(server=inst_dict))