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 | 44f0127 | 2017-01-27 18:44:14 -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 TokensV3Test(base.BaseIdentityV3Test): |
| 23 | |
Ken'ichi Ohmichi | 44f0127 | 2017-01-27 18:44:14 -0800 | [diff] [blame] | 24 | @decorators.idempotent_id('6f8e4436-fc96-4282-8122-e41df57197a9') |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 25 | def test_create_token(self): |
| 26 | |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 27 | creds = self.os_primary.credentials |
Chris Hoge | 4f6117a | 2015-03-20 12:39:33 -0500 | [diff] [blame] | 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 | |
Marc Koderer | 8afdf6c | 2016-04-28 17:24:15 -0500 | [diff] [blame] | 33 | # 'user_domain_id' needs to be specified otherwise tempest.lib assumes |
Tom Cocozzello | 5e3cff1 | 2016-02-23 14:18:56 -0600 | [diff] [blame] | 34 | # it to be 'default' |
| 35 | token_id, resp = self.non_admin_token.get_token( |
| 36 | user_id=user_id, |
Brant Knudson | dd9f805 | 2016-10-21 13:38:10 -0500 | [diff] [blame] | 37 | username=username, |
Tom Cocozzello | 5e3cff1 | 2016-02-23 14:18:56 -0600 | [diff] [blame] | 38 | user_domain_id=user_domain_id, |
| 39 | password=password, |
| 40 | auth_data=True) |
Jane Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 41 | |
| 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 Knudson | dd9f805 | 2016-10-21 13:38:10 -0500 | [diff] [blame] | 53 | 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 Igawa | f9009b4 | 2017-04-10 14:49:29 +0900 | [diff] [blame^] | 57 | self.assertIsNotNone(subject_id, 'Expected user ID in token.') |
Jane Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 58 | |
| 59 | subject_name = resp['user']['name'] |
Brant Knudson | dd9f805 | 2016-10-21 13:38:10 -0500 | [diff] [blame] | 60 | if username: |
| 61 | self.assertEqual(subject_name, username) |
| 62 | else: |
| 63 | # Expect a user name, but don't know what it will be. |
Masayuki Igawa | f9009b4 | 2017-04-10 14:49:29 +0900 | [diff] [blame^] | 64 | self.assertIsNotNone(subject_name, 'Expected user name in token.') |
Jane Zadorozhna | f7b3973 | 2015-06-10 14:19:33 +0300 | [diff] [blame] | 65 | |
| 66 | self.assertEqual(resp['methods'][0], 'password') |