blob: 593bf2a2fc5e19afebf6d098609127d390a2a04f [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
19from tempest import test
20
21
22class TokensV3Test(base.BaseIdentityV3Test):
23
24 @test.idempotent_id('6f8e4436-fc96-4282-8122-e41df57197a9')
25 def test_create_token(self):
26
27 creds = self.os.credentials
28 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
Tom Cocozzello5e3cff12016-02-23 14:18:56 -060033 # 'user_domain_id' needs to be specified otherwise tempest_lib assumes
34 # it to be 'default'
35 token_id, resp = self.non_admin_token.get_token(
36 user_id=user_id,
37 user_domain_id=user_domain_id,
38 password=password,
39 auth_data=True)
Jane Zadorozhnaf7b39732015-06-10 14:19:33 +030040
41 self.assertNotEmpty(token_id)
42 self.assertIsInstance(token_id, six.string_types)
43
44 now = timeutils.utcnow()
45 expires_at = timeutils.normalize_time(
46 timeutils.parse_isotime(resp['expires_at']))
47 self.assertGreater(resp['expires_at'],
48 resp['issued_at'])
49 self.assertGreater(expires_at, now)
50
51 subject_id = resp['user']['id']
52 self.assertEqual(subject_id, user_id)
53
54 subject_name = resp['user']['name']
Chris Hoge4f6117a2015-03-20 12:39:33 -050055 self.assertEqual(subject_name, username)
Jane Zadorozhnaf7b39732015-06-10 14:19:33 +030056
57 self.assertEqual(resp['methods'][0], 'password')