blob: a928ad9f4f3293719cd3c3094672e7851b6241d7 [file] [log] [blame]
Chris Hoge4f6117a2015-03-20 12:39:33 -05001# 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 Zadorozhnaf7b39732015-06-10 14:19:33 +030016from oslo_utils import timeutils
17import six
Chris Hoge4f6117a2015-03-20 12:39:33 -050018from tempest.api.identity import base
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080019from tempest.lib import decorators
Chris Hoge4f6117a2015-03-20 12:39:33 -050020
21
22class TokensTest(base.BaseIdentityV2Test):
zhufl8e3aacd2020-04-27 14:46:46 +080023 """Test tokens in identity v2 API"""
Chris Hoge4f6117a2015-03-20 12:39:33 -050024
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080025 @decorators.idempotent_id('65ae3b78-91ff-467b-a705-f6678863b8ec')
Chris Hoge4f6117a2015-03-20 12:39:33 -050026 def test_create_token(self):
zhufl8e3aacd2020-04-27 14:46:46 +080027 """Test creating token for user via v2 API"""
Chris Hoge4f6117a2015-03-20 12:39:33 -050028 token_client = self.non_admin_token_client
29
30 # get a token for the user
Jordan Pittier8160d312017-04-18 11:52:23 +020031 creds = self.os_primary.credentials
Chris Hoge4f6117a2015-03-20 12:39:33 -050032 username = creds.username
33 password = creds.password
34 tenant_name = creds.tenant_name
35
Jane Zadorozhnaf7b39732015-06-10 14:19:33 +030036 body = token_client.auth(username, password, tenant_name)
Chris Hoge4f6117a2015-03-20 12:39:33 -050037
Jane Zadorozhnaf7b39732015-06-10 14:19:33 +030038 self.assertNotEmpty(body['token']['id'])
39 self.assertIsInstance(body['token']['id'], six.string_types)
40
41 now = timeutils.utcnow()
42 expires_at = timeutils.normalize_time(
43 timeutils.parse_isotime(body['token']['expires']))
44 self.assertGreater(expires_at, now)
45
46 self.assertEqual(body['token']['tenant']['id'],
Andrea Frittoli (andreaf)848c4a12016-06-09 11:09:02 +010047 creds.tenant_id)
Chris Hoge4f6117a2015-03-20 12:39:33 -050048 self.assertEqual(body['token']['tenant']['name'],
49 tenant_name)
Jane Zadorozhnaf7b39732015-06-10 14:19:33 +030050
Andrea Frittoli (andreaf)848c4a12016-06-09 11:09:02 +010051 self.assertEqual(body['user']['id'], creds.user_id)