Skip to content

Commit

Permalink
Add validation for OSAPI server name length.
Browse files Browse the repository at this point in the history
Diablo Fix for LP Bug #962515.

Change-Id: Ifa1ca56a33ca517679fa80bfd10b962eeebe3a76
  • Loading branch information
dprince committed Apr 11, 2012
1 parent 61fc0b8 commit 1ebec57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nova/api/openstack/create_instance_helper.py
Expand Up @@ -248,6 +248,10 @@ def _validate_server_name(self, value):
msg = _("Server name is an empty string")
raise exc.HTTPBadRequest(explanation=msg)

if not len(value) < 256:
msg = _("Server name must be less than 256 characters.")
raise exc.HTTPBadRequest(explanation=msg)

def _get_kernel_ramdisk_from_image(self, req, image_service, image_id):
"""Fetch an image from the ImageService, then if present, return the
associated kernel and ramdisk image IDs.
Expand Down
19 changes: 19 additions & 0 deletions nova/tests/api/openstack/test_servers.py
Expand Up @@ -2294,6 +2294,16 @@ def test_update_server_name_v1_1(self):
self.assertEqual(res_dict['server']['id'], 1)
self.assertEqual(res_dict['server']['name'], 'server_test')

def test_update_server_name_too_long_v1_1(self):
self.stubs.Set(nova.db.api, 'instance_get',
return_server_with_attributes(name='server_test'))
req = webob.Request.blank('/v1.1/fake/servers/1')
req.method = 'PUT'
req.content_type = 'application/json'
req.body = json.dumps({'server': {'name': 'x' * 256}})
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)

def test_update_server_access_ipv4_v1_1(self):
self.stubs.Set(nova.db.api, 'instance_get',
return_server_with_attributes(access_ipv4='0.0.0.0'))
Expand Down Expand Up @@ -3634,6 +3644,15 @@ def test_create_instance_admin_pass_xml(self):
self.assertEquals(server.nodeName, 'server')
self.assertEqual(16, len(server.getAttribute('adminPass')))

def test_create_instance_with_name_too_long(self):
personality = None
body_dict = self._create_personality_request_dict(personality)
body_dict['server']['name'] = 'X' * 256
request = self._get_create_request_json(body_dict)
compute_api, response = \
self._run_create_instance_with_mock_compute_api(request)
self.assertEquals(response.status_int, 400)


class TestGetKernelRamdiskFromImage(test.TestCase):
"""
Expand Down

0 comments on commit 1ebec57

Please sign in to comment.