blob: 1cee902bd056e9493030c6f7c676d33e3a03f140 [file] [log] [blame]
Colleen Murphy0e52d4e2018-02-17 21:29:40 +01001# Copyright 2018 SUSE Linux GmbH
2#
3# All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17import datetime
18
19from oslo_utils import timeutils
20
21from tempest.api.identity import base
Colleen Murphy0e52d4e2018-02-17 21:29:40 +010022from tempest.lib import decorators
23
24
Colleen Murphy0e52d4e2018-02-17 21:29:40 +010025class ApplicationCredentialsV3Test(base.BaseApplicationCredentialsV3Test):
26
27 def _list_app_creds(self, name=None):
28 kwargs = dict(user_id=self.user_id)
29 if name:
30 kwargs.update(name=name)
31 return self.non_admin_app_creds_client.list_application_credentials(
32 **kwargs)['application_credentials']
33
34 @decorators.idempotent_id('8080c75c-eddc-4786-941a-c2da7039ae61')
35 def test_create_application_credential(self):
36 app_cred = self.create_application_credential()
37
38 # Check that the secret appears in the create response
39 secret = app_cred['secret']
40
41 # Check that the secret is not retrievable after initial create
42 app_cred = self.non_admin_app_creds_client.show_application_credential(
43 user_id=self.user_id,
44 application_credential_id=app_cred['id']
45 )['application_credential']
46 self.assertNotIn('secret', app_cred)
47
48 # Check that the application credential is functional
49 token_id, resp = self.non_admin_token.get_token(
50 app_cred_id=app_cred['id'],
51 app_cred_secret=secret,
52 auth_data=True
53 )
54 self.assertEqual(resp['project']['id'], self.project_id)
55
56 @decorators.idempotent_id('852daf0c-42b5-4239-8466-d193d0543ed3')
57 def test_create_application_credential_expires(self):
58 expires_at = timeutils.utcnow() + datetime.timedelta(hours=1)
59
60 app_cred = self.create_application_credential(expires_at=expires_at)
61
62 expires_str = expires_at.isoformat()
63 self.assertEqual(expires_str, app_cred['expires_at'])
64
65 @decorators.idempotent_id('ff0cd457-6224-46e7-b79e-0ada4964a8a6')
66 def test_list_application_credentials(self):
67 self.create_application_credential()
68 self.create_application_credential()
69
70 app_creds = self._list_app_creds()
71 self.assertEqual(2, len(app_creds))
72
73 @decorators.idempotent_id('9bb5e5cc-5250-493a-8869-8b665f6aa5f6')
74 def test_query_application_credentials(self):
75 self.create_application_credential()
76 app_cred_two = self.create_application_credential()
77 app_cred_two_name = app_cred_two['name']
78
79 app_creds = self._list_app_creds(name=app_cred_two_name)
80 self.assertEqual(1, len(app_creds))
81 self.assertEqual(app_cred_two_name, app_creds[0]['name'])