nayna-patel | 914b471 | 2013-07-16 08:29:05 +0000 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 OpenStack Foundation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | from tempest.api.identity import base |
| 19 | from tempest.common.utils.data_utils import rand_name |
| 20 | from tempest.test import attr |
| 21 | |
| 22 | |
| 23 | class CredentialsTestJSON(base.BaseIdentityAdminTest): |
| 24 | _interface = 'json' |
| 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(CredentialsTestJSON, cls).setUpClass() |
| 29 | cls.projects = list() |
| 30 | cls.creds_list = [['project_id', 'user_id', 'id'], |
| 31 | ['access', 'secret']] |
| 32 | u_name = rand_name('user-') |
| 33 | u_desc = '%s description' % u_name |
| 34 | u_email = '%s@testmail.tm' % u_name |
| 35 | u_password = rand_name('pass-') |
| 36 | for i in range(2): |
| 37 | resp, cls.project = cls.v3_client.create_project( |
| 38 | rand_name('project-'), description=rand_name('project-desc-')) |
| 39 | assert resp['status'] == '201', "Expected %s" % resp['status'] |
| 40 | cls.projects.append(cls.project['id']) |
| 41 | |
| 42 | resp, cls.user_body = cls.v3_client.create_user( |
| 43 | u_name, description=u_desc, password=u_password, |
| 44 | email=u_email, project_id=cls.projects[0]) |
| 45 | assert resp['status'] == '201', "Expected: %s" % resp['status'] |
| 46 | |
| 47 | @classmethod |
| 48 | def tearDownClass(cls): |
| 49 | resp, _ = cls.v3_client.delete_user(cls.user_body['id']) |
| 50 | assert resp['status'] == '204', "Expected: %s" % resp['status'] |
| 51 | for p in cls.projects: |
| 52 | resp, _ = cls.v3_client.delete_project(p) |
| 53 | assert resp['status'] == '204', "Expected: %s" % resp['status'] |
| 54 | super(CredentialsTestJSON, cls).tearDownClass() |
| 55 | |
| 56 | def _delete_credential(self, cred_id): |
| 57 | resp, body = self.creds_client.delete_credential(cred_id) |
| 58 | self.assertEqual(resp['status'], '204') |
| 59 | |
| 60 | @attr(type='smoke') |
| 61 | def test_credentials_create_get_update_delete(self): |
| 62 | keys = [rand_name('Access-'), rand_name('Secret-')] |
| 63 | resp, cred = self.creds_client.create_credential( |
| 64 | keys[0], keys[1], self.user_body['id'], |
| 65 | self.projects[0]) |
| 66 | self.addCleanup(self._delete_credential, cred['id']) |
| 67 | self.assertEqual(resp['status'], '201') |
| 68 | for value1 in self.creds_list[0]: |
| 69 | self.assertIn(value1, cred) |
| 70 | for value2 in self.creds_list[1]: |
| 71 | self.assertIn(value2, cred['blob']) |
| 72 | |
| 73 | new_keys = [rand_name('NewAccess-'), rand_name('NewSecret-')] |
| 74 | resp, update_body = self.creds_client.update_credential( |
| 75 | cred['id'], access_key=new_keys[0], secret_key=new_keys[1], |
| 76 | project_id=self.projects[1]) |
| 77 | self.assertEqual(resp['status'], '200') |
| 78 | self.assertEqual(cred['id'], update_body['id']) |
| 79 | self.assertEqual(self.projects[1], update_body['project_id']) |
| 80 | self.assertEqual(self.user_body['id'], update_body['user_id']) |
| 81 | self.assertEqual(update_body['blob']['access'], new_keys[0]) |
| 82 | self.assertEqual(update_body['blob']['secret'], new_keys[1]) |
| 83 | |
| 84 | resp, get_body = self.creds_client.get_credential(cred['id']) |
| 85 | self.assertEqual(resp['status'], '200') |
| 86 | for value1 in self.creds_list[0]: |
| 87 | self.assertEqual(update_body[value1], |
| 88 | get_body[value1]) |
| 89 | for value2 in self.creds_list[1]: |
| 90 | self.assertEqual(update_body['blob'][value2], |
| 91 | get_body['blob'][value2]) |
| 92 | |
| 93 | @attr(type='smoke') |
| 94 | def test_credentials_list_delete(self): |
| 95 | created_cred_ids = list() |
| 96 | fetched_cred_ids = list() |
| 97 | |
| 98 | for i in range(2): |
| 99 | resp, cred = self.creds_client.create_credential( |
| 100 | rand_name('Access-'), rand_name('Secret-'), |
| 101 | self.user_body['id'], self.projects[0]) |
| 102 | self.assertEqual(resp['status'], '201') |
| 103 | created_cred_ids.append(cred['id']) |
| 104 | self.addCleanup(self._delete_credential, cred['id']) |
| 105 | |
| 106 | resp, creds = self.creds_client.list_credentials() |
| 107 | self.assertEqual(resp['status'], '200') |
| 108 | |
| 109 | for i in creds: |
| 110 | fetched_cred_ids.append(i['id']) |
| 111 | missing_creds = [c for c in created_cred_ids |
| 112 | if c not in fetched_cred_ids] |
| 113 | self.assertEqual(0, len(missing_creds), |
| 114 | "Failed to find cred %s in fetched list" % |
| 115 | ', '.join(m_cred for m_cred |
| 116 | in missing_creds)) |
| 117 | |
| 118 | |
| 119 | class CredentialsTestXML(CredentialsTestJSON): |
| 120 | _interface = 'xml' |