Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 17 | |
| 18 | from nose.plugins.attrib import attr |
| 19 | from nose.tools import raises |
Wayne Vestal Weeks | fa07a0e | 2012-10-05 14:34:40 -0400 | [diff] [blame] | 20 | from nose import SkipTest |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 21 | import unittest2 as unittest |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 22 | |
| 23 | from tempest import openstack |
Rohit Karajgi | aeddf63 | 2012-05-04 05:39:13 -0700 | [diff] [blame] | 24 | from tempest.common.utils.data_utils import rand_name, parse_image_id |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 25 | from tempest import exceptions |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 26 | from tempest.tests.compute.base import BaseComputeTest |
| 27 | from tempest.tests import compute |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 28 | |
| 29 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 30 | class AuthorizationTest(BaseComputeTest): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 31 | |
| 32 | @classmethod |
| 33 | def setUpClass(cls): |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 34 | if not compute.MULTI_USER: |
| 35 | msg = "Need >1 user" |
Wayne Vestal Weeks | fa07a0e | 2012-10-05 14:34:40 -0400 | [diff] [blame] | 36 | raise SkipTest(msg) |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 37 | |
| 38 | super(AuthorizationTest, cls).setUpClass() |
| 39 | |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 40 | cls.client = cls.os.servers_client |
| 41 | cls.images_client = cls.os.images_client |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 42 | cls.keypairs_client = cls.os.keypairs_client |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 43 | cls.security_client = cls.os.security_groups_client |
rajalakshmi-ganesan | 72ea31a | 2012-05-25 11:59:10 +0530 | [diff] [blame] | 44 | cls.console_outputs_client = cls.os.console_outputs_client |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 45 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 46 | if cls.config.compute.allow_tenant_isolation: |
| 47 | creds = cls._get_isolated_creds() |
| 48 | username, tenant_name, password = creds |
| 49 | cls.alt_manager = openstack.Manager(username=username, |
| 50 | password=password, |
| 51 | tenant_name=tenant_name) |
| 52 | else: |
| 53 | # Use the alt_XXX credentials in the config file |
| 54 | cls.alt_manager = openstack.AltManager() |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 55 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 56 | cls.alt_client = cls.alt_manager.servers_client |
| 57 | cls.alt_images_client = cls.alt_manager.images_client |
| 58 | cls.alt_keypairs_client = cls.alt_manager.keypairs_client |
| 59 | cls.alt_security_client = cls.alt_manager.security_groups_client |
| 60 | cls.alt_console_outputs_client = cls.alt_manager.console_outputs_client |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 61 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 62 | cls.alt_security_client._set_auth() |
| 63 | name = rand_name('server') |
| 64 | resp, server = cls.client.create_server(name, cls.image_ref, |
| 65 | cls.flavor_ref) |
| 66 | cls.client.wait_for_server_status(server['id'], 'ACTIVE') |
| 67 | resp, cls.server = cls.client.get_server(server['id']) |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 68 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 69 | name = rand_name('image') |
| 70 | resp, body = cls.client.create_image(server['id'], name) |
| 71 | image_id = parse_image_id(resp['location']) |
| 72 | cls.images_client.wait_for_image_resp_code(image_id, 200) |
| 73 | cls.images_client.wait_for_image_status(image_id, 'ACTIVE') |
| 74 | resp, cls.image = cls.images_client.get_image(image_id) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 75 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 76 | cls.keypairname = rand_name('keypair') |
| 77 | resp, keypair = \ |
| 78 | cls.keypairs_client.create_keypair(cls.keypairname) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 79 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 80 | name = rand_name('security') |
| 81 | description = rand_name('description') |
| 82 | resp, cls.security_group = \ |
| 83 | cls.security_client.create_security_group(name, description) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 84 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 85 | parent_group_id = cls.security_group['id'] |
| 86 | ip_protocol = 'tcp' |
| 87 | from_port = 22 |
| 88 | to_port = 22 |
| 89 | resp, cls.rule =\ |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 90 | cls.security_client.create_security_group_rule( |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 91 | parent_group_id, |
| 92 | ip_protocol, from_port, |
| 93 | to_port) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 94 | |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 95 | @classmethod |
| 96 | def tearDownClass(cls): |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 97 | if compute.MULTI_USER: |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 98 | cls.client.delete_server(cls.server['id']) |
| 99 | cls.images_client.delete_image(cls.image['id']) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 100 | cls.keypairs_client.delete_keypair(cls.keypairname) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 101 | cls.security_client.delete_security_group(cls.security_group['id']) |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 102 | super(AuthorizationTest, cls).tearDownClass() |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 103 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 104 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 105 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 106 | def test_get_server_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 107 | """A GET request for a server on another user's account should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 108 | self.alt_client.get_server(self.server['id']) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 109 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 110 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 111 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 112 | def test_delete_server_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 113 | """A DELETE request for another user's server should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 114 | self.alt_client.delete_server(self.server['id']) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 115 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 116 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 117 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 118 | def test_update_server_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 119 | """An update server request for another user's server should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 120 | self.alt_client.update_server(self.server['id'], name='test') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 121 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 122 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 123 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 124 | def test_list_server_addresses_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 125 | """A list addresses request for another user's server should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 126 | self.alt_client.list_addresses(self.server['id']) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 127 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 128 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 129 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 130 | def test_list_server_addresses_by_network_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 131 | """ |
| 132 | A list address/network request for another user's server should fail |
| 133 | """ |
| 134 | server_id = self.server['id'] |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 135 | self.alt_client.list_addresses_by_network(server_id, 'public') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 136 | |
sapan-kona | 3793976 | 2012-06-28 20:22:43 +0530 | [diff] [blame] | 137 | def test_list_servers_with_alternate_tenant(self): |
| 138 | """ |
| 139 | A list on servers from one tenant should not |
| 140 | show on alternate tenant |
| 141 | """ |
| 142 | #Listing servers from alternate tenant |
| 143 | alt_server_ids = [] |
| 144 | resp, body = self.alt_client.list_servers() |
| 145 | alt_server_ids = [s['id'] for s in body['servers']] |
| 146 | self.assertNotIn(self.server['id'], alt_server_ids) |
| 147 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 148 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 149 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 150 | def test_change_password_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 151 | """A change password request for another user's server should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 152 | self.alt_client.change_password(self.server['id'], 'newpass') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 153 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 154 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 155 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 156 | def test_reboot_server_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 157 | """A reboot request for another user's server should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 158 | self.alt_client.reboot(self.server['id'], 'HARD') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 159 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 160 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 161 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 162 | def test_rebuild_server_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 163 | """A rebuild request for another user's server should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 164 | self.alt_client.rebuild(self.server['id'], self.image_ref_alt) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 165 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 166 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 167 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 168 | def test_resize_server_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 169 | """A resize request for another user's server should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 170 | self.alt_client.resize(self.server['id'], self.flavor_ref_alt) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 171 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 172 | @raises(exceptions.NotFound) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 173 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 174 | def test_create_image_for_alt_account_fails(self): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 175 | """A create image request for another user's server should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 176 | self.alt_images_client.create_image(self.server['id'], 'testImage') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 177 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 178 | @raises(exceptions.BadRequest) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 179 | @attr(type='negative') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 180 | def test_create_server_with_unauthorized_image(self): |
| 181 | """Server creation with another user's image should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 182 | self.alt_client.create_server('test', self.image['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 183 | self.flavor_ref) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 184 | |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 185 | @raises(exceptions.BadRequest) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 186 | @attr(type='negative') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 187 | def test_create_server_fails_when_tenant_incorrect(self): |
| 188 | """ |
| 189 | A create server request should fail if the tenant id does not match |
| 190 | the current user |
| 191 | """ |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 192 | saved_base_url = self.alt_client.base_url |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 193 | try: |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 194 | # Change the base URL to impersonate another user |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 195 | self.alt_client.base_url = self.client.base_url |
| 196 | self.alt_client.create_server('test', self.image['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 197 | self.flavor_ref) |
Jay Pipes | ff10d55 | 2012-04-06 14:18:50 -0400 | [diff] [blame] | 198 | finally: |
| 199 | # Reset the base_url... |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 200 | self.alt_client.base_url = saved_base_url |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 201 | |
| 202 | @raises(exceptions.BadRequest) |
| 203 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 204 | def test_create_keypair_in_analt_user_tenant(self): |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 205 | """ |
| 206 | A create keypair request should fail if the tenant id does not match |
| 207 | the current user |
| 208 | """ |
| 209 | #POST keypair with other user tenant |
| 210 | k_name = rand_name('keypair-') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 211 | self.alt_keypairs_client._set_auth() |
| 212 | self.saved_base_url = self.alt_keypairs_client.base_url |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 213 | try: |
| 214 | # Change the base URL to impersonate another user |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 215 | self.alt_keypairs_client.base_url = self.keypairs_client.base_url |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 216 | resp = {} |
| 217 | resp['status'] = None |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 218 | resp, _ = self.alt_keypairs_client.create_keypair(k_name) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 219 | finally: |
| 220 | # Reset the base_url... |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 221 | self.alt_keypairs_client.base_url = self.saved_base_url |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 222 | if (resp['status'] is not None): |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 223 | resp, _ = self.alt_keypairs_client.delete_keypair(k_name) |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 224 | self.fail("Create keypair request should not happen " |
| 225 | "if the tenant id does not match the current user") |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 226 | |
| 227 | @raises(exceptions.NotFound) |
| 228 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 229 | def test_get_keypair_of_alt_account_fails(self): |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 230 | """A GET request for another user's keypair should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 231 | self.alt_keypairs_client.get_keypair(self.keypairname) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 232 | |
| 233 | @raises(exceptions.NotFound) |
| 234 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 235 | def test_delete_keypair_of_alt_account_fails(self): |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 236 | """A DELETE request for another user's keypair should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 237 | self.alt_keypairs_client.delete_keypair(self.keypairname) |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 238 | |
| 239 | @raises(exceptions.NotFound) |
| 240 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 241 | def test_get_image_for_alt_account_fails(self): |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 242 | """A GET request for an image on another user's account should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 243 | self.alt_images_client.get_image(self.image['id']) |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 244 | |
| 245 | @raises(exceptions.NotFound) |
| 246 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 247 | def test_delete_image_for_alt_account_fails(self): |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 248 | """A DELETE request for another user's image should fail""" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 249 | self.alt_images_client.delete_image(self.image['id']) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 250 | |
| 251 | @raises(exceptions.BadRequest) |
| 252 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 253 | def test_create_security_group_in_analt_user_tenant(self): |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 254 | """ |
| 255 | A create security group request should fail if the tenant id does not |
| 256 | match the current user |
| 257 | """ |
| 258 | #POST security group with other user tenant |
| 259 | s_name = rand_name('security-') |
| 260 | s_description = rand_name('security') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 261 | self.saved_base_url = self.alt_security_client.base_url |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 262 | try: |
| 263 | # Change the base URL to impersonate another user |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 264 | self.alt_security_client.base_url = self.security_client.base_url |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 265 | resp = {} |
| 266 | resp['status'] = None |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 267 | resp, body = self.alt_security_client.create_security_group( |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 268 | s_name, |
| 269 | s_description) |
| 270 | finally: |
| 271 | # Reset the base_url... |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 272 | self.alt_security_client.base_url = self.saved_base_url |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 273 | if resp['status'] is not None: |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 274 | resp, _ = \ |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 275 | self.alt_security_client.delete_security_group(body['id']) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 276 | self.fail("Create Security Group request should not happen if" |
| 277 | "the tenant id does not match the current user") |
| 278 | |
| 279 | @raises(exceptions.NotFound) |
| 280 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 281 | def test_get_security_group_of_alt_account_fails(self): |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 282 | """A GET request for another user's security group should fail""" |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 283 | self.alt_security_client.get_security_group(self.security_group['id']) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 284 | |
| 285 | @raises(exceptions.NotFound) |
| 286 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 287 | def test_delete_security_group_of_alt_account_fails(self): |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 288 | """A DELETE request for another user's security group should fail""" |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 289 | self.alt_security_client.delete_security_group( |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 290 | self.security_group['id']) |
| 291 | |
| 292 | @raises(exceptions.BadRequest) |
| 293 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 294 | def test_create_security_group_rule_in_analt_user_tenant(self): |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 295 | """ |
| 296 | A create security group rule request should fail if the tenant id |
| 297 | does not match the current user |
| 298 | """ |
| 299 | #POST security group rule with other user tenant |
| 300 | parent_group_id = self.security_group['id'] |
| 301 | ip_protocol = 'icmp' |
| 302 | from_port = -1 |
| 303 | to_port = -1 |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 304 | self.saved_base_url = self.alt_security_client.base_url |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 305 | try: |
| 306 | # Change the base URL to impersonate another user |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 307 | self.alt_security_client.base_url = self.security_client.base_url |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 308 | resp = {} |
| 309 | resp['status'] = None |
| 310 | resp, body = \ |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 311 | self.alt_security_client.create_security_group_rule( |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 312 | parent_group_id, |
| 313 | ip_protocol, from_port, |
| 314 | to_port) |
| 315 | finally: |
| 316 | # Reset the base_url... |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 317 | self.alt_security_client.base_url = self.saved_base_url |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 318 | if resp['status'] is not None: |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 319 | resp, _ = \ |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 320 | self.alt_security_client.delete_security_group_rule( |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 321 | body['id']) |
| 322 | self.fail("Create security group rule request should not " |
| 323 | "happen if the tenant id does not match the" |
| 324 | " current user") |
| 325 | |
| 326 | @unittest.skip("Skipped until the Bug #1001118 is resolved") |
| 327 | @raises(exceptions.NotFound) |
| 328 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 329 | def test_delete_security_group_rule_of_alt_account_fails(self): |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 330 | """ |
| 331 | A DELETE request for another user's security group rule |
| 332 | should fail |
| 333 | """ |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 334 | self.alt_security_client.delete_security_group_rule(self.rule['id']) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 335 | |
| 336 | @raises(exceptions.NotFound) |
| 337 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 338 | def test_set_metadata_of_alt_account_server_fails(self): |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 339 | """ A set metadata for another user's server should fail """ |
| 340 | req_metadata = {'meta1': 'data1', 'meta2': 'data2'} |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 341 | self.alt_client.set_server_metadata(self.server['id'], req_metadata) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 342 | |
| 343 | @raises(exceptions.NotFound) |
| 344 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 345 | def test_set_metadata_of_alt_account_image_fails(self): |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 346 | """ A set metadata for another user's image should fail """ |
| 347 | req_metadata = {'meta1': 'value1', 'meta2': 'value2'} |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 348 | self.alt_images_client.set_image_metadata(self.image['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 349 | req_metadata) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 350 | |
| 351 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 352 | def test_get_metadata_of_alt_account_server_fails(self): |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 353 | """ A get metadata for another user's server should fail """ |
| 354 | req_metadata = {'meta1': 'data1'} |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 355 | self.client.set_server_metadata(self.server['id'], req_metadata) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 356 | try: |
| 357 | resp, meta = \ |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 358 | self.alt_client.get_server_metadata_item(self.server['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 359 | 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 360 | except exceptions.NotFound: |
| 361 | pass |
| 362 | finally: |
| 363 | resp, body = \ |
| 364 | self.client.delete_server_metadata_item(self.server['id'], 'meta1') |
| 365 | |
| 366 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 367 | def test_get_metadata_of_alt_account_image_fails(self): |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 368 | """ A get metadata for another user's image should fail """ |
| 369 | req_metadata = {'meta1': 'value1'} |
| 370 | self.images_client.set_image_metadata(self.image['id'], |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 371 | req_metadata) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 372 | try: |
| 373 | resp, meta = \ |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 374 | self.alt_images_client.get_image_metadata_item(self.image['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 375 | 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 376 | except exceptions.NotFound: |
| 377 | pass |
| 378 | finally: |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 379 | resp, body = self.images_client.delete_image_metadata_item( |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 380 | self.image['id'], 'meta1') |
| 381 | |
| 382 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 383 | def test_delete_metadata_of_alt_account_server_fails(self): |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 384 | """ A delete metadata for another user's server should fail """ |
| 385 | req_metadata = {'meta1': 'data1'} |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 386 | self.client.set_server_metadata(self.server['id'], req_metadata) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 387 | try: |
| 388 | resp, body = \ |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 389 | self.alt_client.delete_server_metadata_item(self.server['id'], |
| 390 | 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 391 | except exceptions.NotFound: |
| 392 | pass |
| 393 | finally: |
| 394 | resp, body = \ |
| 395 | self.client.delete_server_metadata_item(self.server['id'], 'meta1') |
| 396 | |
| 397 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 398 | def test_delete_metadata_of_alt_account_image_fails(self): |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 399 | """ A delete metadata for another user's image should fail """ |
| 400 | req_metadata = {'meta1': 'data1'} |
| 401 | self.images_client.set_image_metadata(self.image['id'], |
| 402 | req_metadata) |
| 403 | try: |
| 404 | resp, body = \ |
Zhongyue Luo | e6321ef | 2012-09-17 16:45:50 +0800 | [diff] [blame] | 405 | self.alt_images_client.delete_image_metadata_item(self.image['id'], |
| 406 | 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 407 | except exceptions.NotFound: |
| 408 | pass |
| 409 | finally: |
| 410 | resp, body = \ |
| 411 | self.images_client.delete_image_metadata_item(self.image['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 412 | 'meta1') |
rajalakshmi-ganesan | 72ea31a | 2012-05-25 11:59:10 +0530 | [diff] [blame] | 413 | |
| 414 | @raises(exceptions.NotFound) |
| 415 | @attr(type='negative') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 416 | def test_get_console_output_of_alt_account_server_fails(self): |
rajalakshmi-ganesan | 72ea31a | 2012-05-25 11:59:10 +0530 | [diff] [blame] | 417 | """ |
| 418 | A Get Console Output for another user's server should fail |
| 419 | """ |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 420 | self.alt_console_outputs_client.get_console_output(self.server['id'], |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 421 | 10) |