Fixes bug 992149-Some new tests to test_keypairs.py and test_authorization.py
Change-Id: I892c97d805c0800e6ad801137508278d65bd5166
diff --git a/tempest/tests/test_authorization.py b/tempest/tests/test_authorization.py
index e66446d..44000a5 100644
--- a/tempest/tests/test_authorization.py
+++ b/tempest/tests/test_authorization.py
@@ -16,6 +16,7 @@
cls.os = openstack.Manager()
cls.client = cls.os.servers_client
cls.images_client = cls.os.images_client
+ cls.keypairs_client = cls.os.keypairs_client
cls.config = cls.os.config
cls.image_ref = cls.config.compute.image_ref
cls.flavor_ref = cls.config.compute.flavor_ref
@@ -37,6 +38,7 @@
cls.other_manager = openstack.AltManager()
cls.other_client = cls.other_manager.servers_client
cls.other_images_client = cls.other_manager.images_client
+ cls.other_keypairs_client = cls.other_manager.keypairs_client
except exceptions.AuthenticationFailure:
# multi_user is already set to false, just fall through
pass
@@ -56,11 +58,16 @@
cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
resp, cls.image = cls.images_client.get_image(image_id)
+ cls.keypairname = rand_name('keypair')
+ resp, keypair = \
+ cls.keypairs_client.create_keypair(cls.keypairname)
+
@classmethod
def tearDownClass(cls):
if cls.multi_user:
cls.client.delete_server(cls.server['id'])
cls.images_client.delete_image(cls.image['id'])
+ cls.keypairs_client.delete_keypair(cls.keypairname)
@raises(exceptions.NotFound)
@attr(type='negative')
@@ -160,3 +167,43 @@
finally:
# Reset the base_url...
self.other_client.base_url = saved_base_url
+
+ @raises(exceptions.BadRequest)
+ @attr(type='negative')
+ @utils.skip_unless_attr('multi_user', 'Second user not configured')
+ def test_create_keypair_in_another_user_tenant(self):
+ """
+ A create keypair request should fail if the tenant id does not match
+ the current user
+ """
+ #POST keypair with other user tenant
+ k_name = rand_name('keypair-')
+ self.other_keypairs_client._set_auth()
+ self.saved_base_url = self.other_keypairs_client.base_url
+ try:
+ # Change the base URL to impersonate another user
+ self.other_keypairs_client.base_url = self.keypairs_client.base_url
+ resp = {}
+ resp['status'] = None
+ resp, _ = self.other_keypairs_client.create_keypair(k_name)
+ finally:
+ # Reset the base_url...
+ self.other_keypairs_client.base_url = self.saved_base_url
+ if (resp['status'] != None):
+ resp, _ = self.other_keypairs_client.delete_keypair(k_name)
+ self.fail("Create keypair request should not happen if the"
+ " tenant id does not match the current user")
+
+ @raises(exceptions.NotFound)
+ @attr(type='negative')
+ @utils.skip_unless_attr('multi_user', 'Second user not configured')
+ def test_get_keypair_of_other_account_fails(self):
+ """A GET request for another user's keypair should fail"""
+ self.other_keypairs_client.get_keypair(self.keypairname)
+
+ @raises(exceptions.NotFound)
+ @attr(type='negative')
+ @utils.skip_unless_attr('multi_user', 'Second user not configured')
+ def test_delete_keypair_of_other_account_fails(self):
+ """A DELETE request for another user's keypair should fail"""
+ self.other_keypairs_client.delete_keypair(self.keypairname)
diff --git a/tempest/tests/test_keypairs.py b/tempest/tests/test_keypairs.py
index fde9de1..d3ba213 100644
--- a/tempest/tests/test_keypairs.py
+++ b/tempest/tests/test_keypairs.py
@@ -62,6 +62,29 @@
self.assertEqual(202, resp.status)
@attr(type='smoke')
+ @unittest.skip("Skipped until the Bug #980688 is resolved")
+ def test_get_keypair_detail(self):
+ """Keypair should be created, Got details by name and deleted"""
+ k_name = rand_name('keypair-')
+ resp, keypair = self.client.create_keypair(k_name)
+ try:
+ resp, keypair_detail = self.client.get_keypair(k_name)
+ self.assertEqual(200, resp.status)
+ self.assertTrue('name' in keypair_detail)
+ self.assertTrue('public_key' in keypair_detail)
+ self.assertEqual(keypair_detail['name'], k_name,
+ "The created keypair name is not equal to requested name")
+ public_key = keypair_detail['public_key']
+ self.assertTrue(public_key is not None,
+ "Field public_key is empty or not found.")
+ except:
+ self.fail("GET keypair details requested by keypair name"
+ " has failed")
+ finally:
+ resp, _ = self.client.delete_keypair(k_name)
+ self.assertEqual(202, resp.status)
+
+ @attr(type='smoke')
def test_keypair_create_with_pub_key(self):
"""Keypair should be created with a given public key"""
k_name = rand_name('keypair-')