Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 1 | # 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 Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 16 | from oslo_utils import timeutils |
| 17 | import six |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 18 | from tempest.api.identity import base |
| 19 | from tempest import test |
| 20 | |
| 21 | |
| 22 | class 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 Cocozzello | 5e3cff1 | 2016-02-23 14:18:56 -0600 | [diff] [blame] | 31 | user_domain_id = creds.user_domain_id |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 32 | |
Tom Cocozzello | 5e3cff1 | 2016-02-23 14:18:56 -0600 | [diff] [blame] | 33 | # '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 Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 40 | |
| 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 Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 55 | self.assertEqual(subject_name, username) |
Jane Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 56 | |
| 57 | self.assertEqual(resp['methods'][0], 'password') |