blob: 042c821b94a4a5a7cfabe941396012f955262679 [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 Ohmichi44f01272017-01-27 18:44:14 -080019from tempest.lib import decorators
Chris Hoge4f6117a2015-03-20 12:39:33 -050020
21
22class TokensV3Test(base.BaseIdentityV3Test):
23
Ken'ichi Ohmichi44f01272017-01-27 18:44:14 -080024 @decorators.idempotent_id('6f8e4436-fc96-4282-8122-e41df57197a9')
Chris Hoge4f6117a2015-03-20 12:39:33 -050025 def test_create_token(self):
26
Jordan Pittier8160d312017-04-18 11:52:23 +020027 creds = self.os_primary.credentials
Chris Hoge4f6117a2015-03-20 12:39:33 -050028 user_id = creds.user_id
29 username = creds.username
30 password = creds.password
Tom Cocozzello5e3cff12016-02-23 14:18:56 -060031 user_domain_id = creds.user_domain_id
Chris Hoge4f6117a2015-03-20 12:39:33 -050032
Marc Koderer8afdf6c2016-04-28 17:24:15 -050033 # 'user_domain_id' needs to be specified otherwise tempest.lib assumes
Tom Cocozzello5e3cff12016-02-23 14:18:56 -060034 # it to be 'default'
35 token_id, resp = self.non_admin_token.get_token(
36 user_id=user_id,
Brant Knudsondd9f8052016-10-21 13:38:10 -050037 username=username,
Tom Cocozzello5e3cff12016-02-23 14:18:56 -060038 user_domain_id=user_domain_id,
39 password=password,
40 auth_data=True)
Jane Zadorozhnaf7b39732015-06-10 14:19:33 +030041
42 self.assertNotEmpty(token_id)
43 self.assertIsInstance(token_id, six.string_types)
44
45 now = timeutils.utcnow()
46 expires_at = timeutils.normalize_time(
47 timeutils.parse_isotime(resp['expires_at']))
48 self.assertGreater(resp['expires_at'],
49 resp['issued_at'])
50 self.assertGreater(expires_at, now)
51
52 subject_id = resp['user']['id']
Brant Knudsondd9f8052016-10-21 13:38:10 -050053 if user_id:
54 self.assertEqual(subject_id, user_id)
55 else:
56 # Expect a user ID, but don't know what it will be.
Masayuki Igawaf9009b42017-04-10 14:49:29 +090057 self.assertIsNotNone(subject_id, 'Expected user ID in token.')
Jane Zadorozhnaf7b39732015-06-10 14:19:33 +030058
59 subject_name = resp['user']['name']
Brant Knudsondd9f8052016-10-21 13:38:10 -050060 if username:
61 self.assertEqual(subject_name, username)
62 else:
63 # Expect a user name, but don't know what it will be.
Masayuki Igawaf9009b42017-04-10 14:49:29 +090064 self.assertIsNotNone(subject_name, 'Expected user name in token.')
Jane Zadorozhnaf7b39732015-06-10 14:19:33 +030065
66 self.assertEqual(resp['methods'][0], 'password')