Skip to content

Commit

Permalink
Allow blank passwords in changePassword action
Browse files Browse the repository at this point in the history
* Fixes bug 992661

Change-Id: Ia07e27586719e231f5ef99f4b25b8d9ba6e7f6ca
  • Loading branch information
bcwaldon committed May 1, 2012
1 parent ac21815 commit 21352ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions nova/api/openstack/compute/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def _action_create_image(self, node):
return self._deserialize_image_action(node, ('name',))

def _action_change_password(self, node):
if not node.getAttribute("adminPass"):
if not node.hasAttribute("adminPass"):
raise AttributeError("No adminPass was specified in request")
return {"adminPass": node.getAttribute("adminPass")}

Expand Down Expand Up @@ -964,7 +964,7 @@ def _action_change_password(self, req, id, body):
msg = _("No adminPass was specified")
raise exc.HTTPBadRequest(explanation=msg)
password = body['changePassword']['adminPass']
if not isinstance(password, basestring) or password == '':
if not isinstance(password, basestring):
msg = _("Invalid adminPass")
raise exc.HTTPBadRequest(explanation=msg)
server = self._get_server(context, id)
Expand Down
21 changes: 14 additions & 7 deletions nova/tests/api/openstack/compute/test_server_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,15 @@ def test_server_change_password_bad_request(self):
req, FAKE_UUID, body)

def test_server_change_password_empty_string(self):
mock_method = MockSetAdminPassword()
self.stubs.Set(nova.compute.api.API, 'set_admin_password', mock_method)
body = {'changePassword': {'adminPass': ''}}

req = fakes.HTTPRequest.blank(self.url)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_change_password,
req, FAKE_UUID, body)
self.controller._action_change_password(req, FAKE_UUID, body)

self.assertEqual(mock_method.instance_id, self.uuid)
self.assertEqual(mock_method.password, '')

def test_server_change_password_none(self):
body = {'changePassword': {'adminPass': None}}
Expand Down Expand Up @@ -764,10 +768,13 @@ def test_change_pass_empty_pass(self):
<changePassword
xmlns="http://docs.openstack.org/compute/api/v1.1"
adminPass=""/> """
self.assertRaises(AttributeError,
self.deserializer.deserialize,
serial_request,
'action')
request = self.deserializer.deserialize(serial_request, 'action')
expected = {
"changePassword": {
"adminPass": "",
},
}
self.assertEquals(request['body'], expected)

def test_reboot(self):
serial_request = """<?xml version="1.0" encoding="UTF-8"?>
Expand Down

0 comments on commit 21352ee

Please sign in to comment.