ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 15 | |
Adam Gandelman | 85f5bed | 2014-06-19 16:48:17 -0700 | [diff] [blame] | 16 | import StringIO |
| 17 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 18 | from tempest_lib import exceptions as lib_exc |
| 19 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 20 | from tempest.api.compute import base |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 21 | from tempest import clients |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 22 | from tempest.common.utils import data_utils |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 23 | from tempest import config |
Daryl Walleck | dc9e0c4 | 2012-04-02 16:51:26 -0500 | [diff] [blame] | 24 | from tempest import exceptions |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 25 | from tempest.openstack.common import log as logging |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 26 | from tempest import test |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 27 | |
Matthew Treinish | b0a78fc | 2014-01-29 16:49:12 +0000 | [diff] [blame] | 28 | CONF = config.CONF |
| 29 | |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 30 | LOG = logging.getLogger(__name__) |
| 31 | |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 32 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 33 | class AuthorizationTestJSON(base.BaseV2ComputeTest): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 34 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 35 | def resource_setup(cls): |
Adam Gandelman | 85f5bed | 2014-06-19 16:48:17 -0700 | [diff] [blame] | 36 | if not CONF.service_available.glance: |
| 37 | raise cls.skipException('Glance is not available.') |
Salvatore Orlando | 5a33724 | 2014-01-15 22:49:22 +0000 | [diff] [blame] | 38 | # No network resources required for this test |
| 39 | cls.set_network_resources() |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 40 | super(AuthorizationTestJSON, cls).resource_setup() |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 41 | if not cls.multi_user: |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 42 | msg = "Need >1 user" |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 43 | raise cls.skipException(msg) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 44 | cls.client = cls.os.servers_client |
| 45 | cls.images_client = cls.os.images_client |
Adam Gandelman | 85f5bed | 2014-06-19 16:48:17 -0700 | [diff] [blame] | 46 | cls.glance_client = cls.os.image_client |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 47 | cls.keypairs_client = cls.os.keypairs_client |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 48 | cls.security_client = cls.os.security_groups_client |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 49 | |
Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 50 | creds = cls.isolated_creds.get_alt_creds() |
| 51 | cls.alt_manager = clients.Manager(credentials=creds) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 52 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 53 | cls.alt_client = cls.alt_manager.servers_client |
| 54 | cls.alt_images_client = cls.alt_manager.images_client |
| 55 | cls.alt_keypairs_client = cls.alt_manager.keypairs_client |
| 56 | cls.alt_security_client = cls.alt_manager.security_groups_client |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 57 | |
David Kranz | 0fb1429 | 2015-02-11 15:55:20 -0500 | [diff] [blame] | 58 | server = cls.create_test_server(wait_until='ACTIVE') |
| 59 | cls.server = cls.client.get_server(server['id']) |
Jay Pipes | 3f981df | 2012-03-27 18:59:44 -0400 | [diff] [blame] | 60 | |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 61 | name = data_utils.rand_name('image') |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 62 | body = cls.glance_client.create_image(name=name, |
| 63 | container_format='bare', |
| 64 | disk_format='raw', |
| 65 | is_public=False) |
Adam Gandelman | 85f5bed | 2014-06-19 16:48:17 -0700 | [diff] [blame] | 66 | image_id = body['id'] |
| 67 | image_file = StringIO.StringIO(('*' * 1024)) |
David Kranz | 34f1878 | 2015-01-06 13:43:55 -0500 | [diff] [blame] | 68 | body = cls.glance_client.update_image(image_id, data=image_file) |
Adam Gandelman | 85f5bed | 2014-06-19 16:48:17 -0700 | [diff] [blame] | 69 | cls.glance_client.wait_for_image_status(image_id, 'active') |
David Kranz | a5299eb | 2015-01-15 17:24:05 -0500 | [diff] [blame] | 70 | cls.image = cls.images_client.get_image(image_id) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 71 | |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 72 | cls.keypairname = data_utils.rand_name('keypair') |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 73 | cls.keypairs_client.create_keypair(cls.keypairname) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 74 | |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 75 | name = data_utils.rand_name('security') |
| 76 | description = data_utils.rand_name('description') |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 77 | cls.security_group = cls.security_client.create_security_group( |
nayna-patel | eda1d12 | 2013-03-20 14:44:31 +0000 | [diff] [blame] | 78 | name, description) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 79 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 80 | parent_group_id = cls.security_group['id'] |
| 81 | ip_protocol = 'tcp' |
| 82 | from_port = 22 |
| 83 | to_port = 22 |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 84 | cls.rule = cls.security_client.create_security_group_rule( |
nayna-patel | eda1d12 | 2013-03-20 14:44:31 +0000 | [diff] [blame] | 85 | parent_group_id, ip_protocol, from_port, to_port) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 86 | |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 87 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 88 | def resource_cleanup(cls): |
Matthew Treinish | f7fca6a | 2013-12-09 16:27:23 +0000 | [diff] [blame] | 89 | if cls.multi_user: |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 90 | cls.images_client.delete_image(cls.image['id']) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 91 | cls.keypairs_client.delete_keypair(cls.keypairname) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 92 | cls.security_client.delete_security_group(cls.security_group['id']) |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 93 | super(AuthorizationTestJSON, cls).resource_cleanup() |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 94 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 95 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 96 | def test_get_server_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 97 | # A GET request for a server on another user's account should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 98 | self.assertRaises(lib_exc.NotFound, self.alt_client.get_server, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 99 | self.server['id']) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 100 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 101 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 102 | def test_delete_server_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 103 | # A DELETE request for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 104 | self.assertRaises(lib_exc.NotFound, self.alt_client.delete_server, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 105 | self.server['id']) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 106 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 107 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 108 | def test_update_server_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 109 | # An update server request for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 110 | self.assertRaises(lib_exc.NotFound, self.alt_client.update_server, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 111 | self.server['id'], name='test') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 112 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 113 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 114 | def test_list_server_addresses_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 115 | # A list addresses request for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 116 | self.assertRaises(lib_exc.NotFound, self.alt_client.list_addresses, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 117 | self.server['id']) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 118 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 119 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 120 | def test_list_server_addresses_by_network_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 121 | # A list address/network request for another user's server should fail |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 122 | server_id = self.server['id'] |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 123 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 124 | self.alt_client.list_addresses_by_network, server_id, |
| 125 | 'public') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 126 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 127 | @test.attr(type='gate') |
sapan-kona | 3793976 | 2012-06-28 20:22:43 +0530 | [diff] [blame] | 128 | def test_list_servers_with_alternate_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 129 | # A list on servers from one tenant should not |
| 130 | # show on alternate tenant |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 131 | # Listing servers from alternate tenant |
sapan-kona | 3793976 | 2012-06-28 20:22:43 +0530 | [diff] [blame] | 132 | alt_server_ids = [] |
| 133 | resp, body = self.alt_client.list_servers() |
| 134 | alt_server_ids = [s['id'] for s in body['servers']] |
| 135 | self.assertNotIn(self.server['id'], alt_server_ids) |
| 136 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 137 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 138 | def test_change_password_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 139 | # A change password request for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 140 | self.assertRaises(lib_exc.NotFound, self.alt_client.change_password, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 141 | self.server['id'], 'newpass') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 142 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 143 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 144 | def test_reboot_server_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 145 | # A reboot request for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 146 | self.assertRaises(lib_exc.NotFound, self.alt_client.reboot, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 147 | self.server['id'], 'HARD') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 148 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 149 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 150 | def test_rebuild_server_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 151 | # A rebuild request for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 152 | self.assertRaises(lib_exc.NotFound, self.alt_client.rebuild, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 153 | self.server['id'], self.image_ref_alt) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 154 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 155 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 156 | def test_resize_server_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 157 | # A resize request for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 158 | self.assertRaises(lib_exc.NotFound, self.alt_client.resize, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 159 | self.server['id'], self.flavor_ref_alt) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 160 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 161 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 162 | def test_create_image_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 163 | # A create image request for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 164 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 165 | self.alt_images_client.create_image, |
| 166 | self.server['id'], 'testImage') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 167 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 168 | @test.attr(type='gate') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 169 | def test_create_server_with_unauthorized_image(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 170 | # Server creation with another user's image should fail |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 171 | self.assertRaises(exceptions.BadRequest, self.alt_client.create_server, |
| 172 | 'test', self.image['id'], self.flavor_ref) |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 173 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 174 | @test.attr(type='gate') |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 175 | def test_create_server_fails_when_tenant_incorrect(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 176 | # A create server request should fail if the tenant id does not match |
| 177 | # the current user |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 178 | # Change the base URL to impersonate another user |
| 179 | self.alt_client.auth_provider.set_alt_auth_data( |
| 180 | request_part='url', |
| 181 | auth_data=self.client.auth_provider.auth_data |
| 182 | ) |
| 183 | self.assertRaises(exceptions.BadRequest, |
| 184 | self.alt_client.create_server, 'test', |
| 185 | self.image['id'], self.flavor_ref) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 186 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 187 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 188 | def test_create_keypair_in_analt_user_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 189 | # A create keypair request should fail if the tenant id does not match |
| 190 | # the current user |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 191 | # POST keypair with other user tenant |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 192 | k_name = data_utils.rand_name('keypair-') |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 193 | try: |
| 194 | # Change the base URL to impersonate another user |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 195 | self.alt_keypairs_client.auth_provider.set_alt_auth_data( |
| 196 | request_part='url', |
| 197 | auth_data=self.keypairs_client.auth_provider.auth_data |
| 198 | ) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 199 | resp = {} |
| 200 | resp['status'] = None |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 201 | self.assertRaises(exceptions.BadRequest, |
| 202 | self.alt_keypairs_client.create_keypair, k_name) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 203 | finally: |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 204 | # Next request the base_url is back to normal |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 205 | if (resp['status'] is not None): |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 206 | self.alt_keypairs_client.delete_keypair(k_name) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 207 | LOG.error("Create keypair request should not happen " |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 208 | "if the tenant id does not match the current user") |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 209 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 210 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 211 | def test_get_keypair_of_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 212 | # A GET request for another user's keypair should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 213 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 214 | self.alt_keypairs_client.get_keypair, |
| 215 | self.keypairname) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 216 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 217 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 218 | def test_delete_keypair_of_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 219 | # A DELETE request for another user's keypair should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 220 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 221 | self.alt_keypairs_client.delete_keypair, |
| 222 | self.keypairname) |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 223 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 224 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 225 | def test_get_image_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 226 | # A GET request for an image on another user's account should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 227 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 228 | self.alt_images_client.get_image, self.image['id']) |
rajalakshmi-ganesan | 32f8db6 | 2012-05-18 19:13:40 +0530 | [diff] [blame] | 229 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 230 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 231 | def test_delete_image_for_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 232 | # A DELETE request for another user's image should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 233 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 234 | self.alt_images_client.delete_image, |
| 235 | self.image['id']) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 236 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 237 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 238 | def test_create_security_group_in_analt_user_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 239 | # A create security group request should fail if the tenant id does not |
| 240 | # match the current user |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 241 | # POST security group with other user tenant |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 242 | s_name = data_utils.rand_name('security-') |
| 243 | s_description = data_utils.rand_name('security') |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 244 | try: |
| 245 | # Change the base URL to impersonate another user |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 246 | self.alt_security_client.auth_provider.set_alt_auth_data( |
| 247 | request_part='url', |
| 248 | auth_data=self.security_client.auth_provider.auth_data |
| 249 | ) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 250 | resp = {} |
| 251 | resp['status'] = None |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 252 | self.assertRaises(exceptions.BadRequest, |
| 253 | self.alt_security_client.create_security_group, |
| 254 | s_name, s_description) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 255 | finally: |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 256 | # Next request the base_url is back to normal |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 257 | if resp['status'] is not None: |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 258 | self.alt_security_client.delete_security_group(resp['id']) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 259 | LOG.error("Create Security Group request should not happen if" |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 260 | "the tenant id does not match the current user") |
| 261 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 262 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 263 | def test_get_security_group_of_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 264 | # A GET request for another user's security group should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 265 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 266 | self.alt_security_client.get_security_group, |
| 267 | self.security_group['id']) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 268 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 269 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 270 | def test_delete_security_group_of_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 271 | # A DELETE request for another user's security group should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 272 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 273 | self.alt_security_client.delete_security_group, |
| 274 | self.security_group['id']) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 275 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 276 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 277 | def test_create_security_group_rule_in_analt_user_tenant(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 278 | # A create security group rule request should fail if the tenant id |
| 279 | # does not match the current user |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 280 | # POST security group rule with other user tenant |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 281 | parent_group_id = self.security_group['id'] |
| 282 | ip_protocol = 'icmp' |
| 283 | from_port = -1 |
| 284 | to_port = -1 |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 285 | try: |
| 286 | # Change the base URL to impersonate another user |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 287 | self.alt_security_client.auth_provider.set_alt_auth_data( |
| 288 | request_part='url', |
| 289 | auth_data=self.security_client.auth_provider.auth_data |
| 290 | ) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 291 | resp = {} |
| 292 | resp['status'] = None |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 293 | self.assertRaises(exceptions.BadRequest, |
| 294 | self.alt_security_client. |
| 295 | create_security_group_rule, |
| 296 | parent_group_id, ip_protocol, from_port, |
| 297 | to_port) |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 298 | finally: |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 299 | # Next request the base_url is back to normal |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 300 | if resp['status'] is not None: |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 301 | self.alt_security_client.delete_security_group_rule(resp['id']) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 302 | LOG.error("Create security group rule request should not " |
rajalakshmi-ganesan | 184daad | 2012-05-18 14:47:38 +0530 | [diff] [blame] | 303 | "happen if the tenant id does not match the" |
| 304 | " current user") |
| 305 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 306 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 307 | def test_delete_security_group_rule_of_alt_account_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 308 | # A DELETE request for another user's security group rule |
| 309 | # should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 310 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 311 | self.alt_security_client.delete_security_group_rule, |
| 312 | self.rule['id']) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 313 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 314 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 315 | def test_set_metadata_of_alt_account_server_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 316 | # A set metadata for another user's server should fail |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 317 | req_metadata = {'meta1': 'data1', 'meta2': 'data2'} |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 318 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 319 | self.alt_client.set_server_metadata, |
| 320 | self.server['id'], |
| 321 | req_metadata) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 322 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 323 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 324 | def test_set_metadata_of_alt_account_image_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 325 | # A set metadata for another user's image should fail |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 326 | req_metadata = {'meta1': 'value1', 'meta2': 'value2'} |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 327 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 328 | self.alt_images_client.set_image_metadata, |
| 329 | self.image['id'], req_metadata) |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 330 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 331 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 332 | def test_get_metadata_of_alt_account_server_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 333 | # A get metadata for another user's server should fail |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 334 | req_metadata = {'meta1': 'data1'} |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 335 | self.client.set_server_metadata(self.server['id'], req_metadata) |
hi2suresh | 31bb7cb | 2013-03-14 04:53:49 +0000 | [diff] [blame] | 336 | self.addCleanup(self.client.delete_server_metadata_item, |
| 337 | self.server['id'], 'meta1') |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 338 | self.assertRaises(lib_exc.NotFound, |
hi2suresh | 31bb7cb | 2013-03-14 04:53:49 +0000 | [diff] [blame] | 339 | self.alt_client.get_server_metadata_item, |
| 340 | self.server['id'], 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 341 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 342 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 343 | def test_get_metadata_of_alt_account_image_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 344 | # A get metadata for another user's image should fail |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 345 | req_metadata = {'meta1': 'value1'} |
hi2suresh | d0e2412 | 2013-03-15 03:06:53 +0000 | [diff] [blame] | 346 | self.addCleanup(self.images_client.delete_image_metadata_item, |
| 347 | self.image['id'], 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 348 | self.images_client.set_image_metadata(self.image['id'], |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 349 | req_metadata) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 350 | self.assertRaises(lib_exc.NotFound, |
hi2suresh | d0e2412 | 2013-03-15 03:06:53 +0000 | [diff] [blame] | 351 | self.alt_images_client.get_image_metadata_item, |
| 352 | self.image['id'], 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 353 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 354 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 355 | def test_delete_metadata_of_alt_account_server_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 356 | # A delete metadata for another user's server should fail |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 357 | req_metadata = {'meta1': 'data1'} |
hi2suresh | d0e2412 | 2013-03-15 03:06:53 +0000 | [diff] [blame] | 358 | self.addCleanup(self.client.delete_server_metadata_item, |
| 359 | self.server['id'], 'meta1') |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 360 | self.client.set_server_metadata(self.server['id'], req_metadata) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 361 | self.assertRaises(lib_exc.NotFound, |
hi2suresh | d0e2412 | 2013-03-15 03:06:53 +0000 | [diff] [blame] | 362 | self.alt_client.delete_server_metadata_item, |
| 363 | self.server['id'], 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 364 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 365 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 366 | def test_delete_metadata_of_alt_account_image_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 367 | # A delete metadata for another user's image should fail |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 368 | req_metadata = {'meta1': 'data1'} |
hi2suresh | d0e2412 | 2013-03-15 03:06:53 +0000 | [diff] [blame] | 369 | self.addCleanup(self.images_client.delete_image_metadata_item, |
| 370 | self.image['id'], 'meta1') |
rajalakshmi-ganesan | 929a32a | 2012-05-29 18:00:25 +0530 | [diff] [blame] | 371 | self.images_client.set_image_metadata(self.image['id'], |
| 372 | req_metadata) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 373 | self.assertRaises(lib_exc.NotFound, |
hi2suresh | d0e2412 | 2013-03-15 03:06:53 +0000 | [diff] [blame] | 374 | self.alt_images_client.delete_image_metadata_item, |
| 375 | self.image['id'], 'meta1') |
rajalakshmi-ganesan | 72ea31a | 2012-05-25 11:59:10 +0530 | [diff] [blame] | 376 | |
Yuiko Takada | e9999d6 | 2014-03-06 09:22:54 +0000 | [diff] [blame] | 377 | @test.attr(type='gate') |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 378 | def test_get_console_output_of_alt_account_server_fails(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 379 | # A Get Console Output for another user's server should fail |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 380 | self.assertRaises(lib_exc.NotFound, |
Chris Yeoh | 8b4eaa5 | 2013-02-06 18:03:10 +1030 | [diff] [blame] | 381 | self.alt_client.get_console_output, |
| 382 | self.server['id'], 10) |