blob: b742e692d57bc3fd2985eca6d713d6edc687ca56 [file] [log] [blame]
Jane Zadorozhnabfc72372015-06-16 17:32:59 +03001# Copyright 2015 OpenStack Foundation
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.
15
Jane Zadorozhnabfc72372015-06-16 17:32:59 +030016from tempest.api.identity import base
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050017from tempest.lib import exceptions as lib_exc
Jane Zadorozhnabfc72372015-06-16 17:32:59 +030018from tempest import test
19
20
21class IdentityTenantsTest(base.BaseIdentityV2Test):
22
23 credentials = ['primary', 'alt']
24
25 @test.idempotent_id('ecae2459-243d-4ba1-ad02-65f15dc82b78')
26 def test_list_tenants_returns_only_authorized_tenants(self):
27 alt_tenant_name = self.alt_manager.credentials.credentials.tenant_name
Daniel Melladob04da902015-11-20 17:43:12 +010028 resp = self.non_admin_tenants_client.list_tenants()
Jane Zadorozhnabfc72372015-06-16 17:32:59 +030029
30 # check that user can see only that tenants that he presents in so user
31 # can successfully authenticate using his credentials and tenant name
32 # from received tenants list
33 for tenant in resp['tenants']:
34 body = self.non_admin_token_client.auth(
35 self.os.credentials.username,
36 self.os.credentials.password,
37 tenant['name'])
38 self.assertNotEmpty(body['token']['id'])
39 self.assertEqual(body['token']['tenant']['id'], tenant['id'])
40 self.assertEqual(body['token']['tenant']['name'], tenant['name'])
41 self.assertEqual(body['user']['id'], self.os.credentials.user_id)
42
43 # check that user cannot log in to alt user's tenant
44 self.assertRaises(
45 lib_exc.Unauthorized,
46 self.non_admin_token_client.auth,
47 self.os.credentials.username,
48 self.os.credentials.password,
49 alt_tenant_name)