Merge "Validate keypair create request body"
This commit is contained in:
commit
0296a2d249
@ -70,8 +70,13 @@ class KeypairController(object):
|
||||
|
||||
context = req.environ['nova.context']
|
||||
authorize(context)
|
||||
|
||||
try:
|
||||
params = body['keypair']
|
||||
name = params['name']
|
||||
except KeyError:
|
||||
msg = _("Invalid request body")
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
try:
|
||||
if 'public_key' in params:
|
||||
|
@ -295,6 +295,18 @@ class KeypairsTest(test.TestCase):
|
||||
self.assertTrue('key_name' in server_dict)
|
||||
self.assertEquals(server_dict['key_name'], '')
|
||||
|
||||
def test_keypair_create_with_invalid_keypairBody(self):
|
||||
body = {'alpha': {'name': 'create_test'}}
|
||||
req = webob.Request.blank('/v1.1/fake/os-keypairs')
|
||||
req.method = 'POST'
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
res_dict = jsonutils.loads(res.body)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
self.assertEqual(res_dict['badRequest']['message'],
|
||||
"Invalid request body")
|
||||
|
||||
|
||||
class KeypairsXMLSerializerTest(test.TestCase):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user