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 |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 20 | |
| 21 | |
| 22 | class TokensTest(base.BaseIdentityV2Test): |
zhufl | 8e3aacd | 2020-04-27 14:46:46 +0800 | [diff] [blame] | 23 | """Test tokens in identity v2 API""" |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 24 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame] | 25 | @decorators.idempotent_id('65ae3b78-91ff-467b-a705-f6678863b8ec') |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 26 | def test_create_token(self): |
zhufl | 8e3aacd | 2020-04-27 14:46:46 +0800 | [diff] [blame] | 27 | """Test creating token for user via v2 API""" |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 28 | token_client = self.non_admin_token_client |
| 29 | |
| 30 | # get a token for the user |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 31 | creds = self.os_primary.credentials |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 32 | username = creds.username |
| 33 | password = creds.password |
| 34 | tenant_name = creds.tenant_name |
| 35 | |
Jane Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 36 | body = token_client.auth(username, password, tenant_name) |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 37 | |
Jane Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 38 | 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) | 848c4a1 | 2016-06-09 11:09:02 +0100 | [diff] [blame] | 47 | creds.tenant_id) |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 48 | self.assertEqual(body['token']['tenant']['name'], |
| 49 | tenant_name) |
Jane Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 50 | |
Andrea Frittoli (andreaf) | 848c4a1 | 2016-06-09 11:09:02 +0100 | [diff] [blame] | 51 | self.assertEqual(body['user']['id'], creds.user_id) |