blob: 1fcff8dd08b901fe21b74afbb961c58fa242b47c [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
16from tempest_lib import exceptions as lib_exc
17
18from tempest.api.identity import base
19from tempest import test
20
21
22class IdentityTenantsTest(base.BaseIdentityV2Test):
23
24 credentials = ['primary', 'alt']
25
26 @test.idempotent_id('ecae2459-243d-4ba1-ad02-65f15dc82b78')
27 def test_list_tenants_returns_only_authorized_tenants(self):
28 alt_tenant_name = self.alt_manager.credentials.credentials.tenant_name
29 resp = self.non_admin_client.list_tenants()
30
31 # check that user can see only that tenants that he presents in so user
32 # can successfully authenticate using his credentials and tenant name
33 # from received tenants list
34 for tenant in resp['tenants']:
35 body = self.non_admin_token_client.auth(
36 self.os.credentials.username,
37 self.os.credentials.password,
38 tenant['name'])
39 self.assertNotEmpty(body['token']['id'])
40 self.assertEqual(body['token']['tenant']['id'], tenant['id'])
41 self.assertEqual(body['token']['tenant']['name'], tenant['name'])
42 self.assertEqual(body['user']['id'], self.os.credentials.user_id)
43
44 # check that user cannot log in to alt user's tenant
45 self.assertRaises(
46 lib_exc.Unauthorized,
47 self.non_admin_token_client.auth,
48 self.os.credentials.username,
49 self.os.credentials.password,
50 alt_tenant_name)