Andrea Frittoli | 9efbe95 | 2015-01-29 12:43:09 +0000 | [diff] [blame] | 1 | # Copyright 2015 Hewlett-Packard Development Company, L.P. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 15 | from oslo_config import cfg |
Andrea Frittoli | 9efbe95 | 2015-01-29 12:43:09 +0000 | [diff] [blame] | 16 | |
| 17 | from tempest import auth |
| 18 | from tempest.common import cred_provider |
| 19 | from tempest.common import tempest_fixtures as fixtures |
Andrea Frittoli (andreaf) | abf0d6f | 2015-03-23 15:14:02 +0000 | [diff] [blame] | 20 | from tempest import config |
Jamie Lennox | c429e6a | 2015-02-24 10:42:42 +1100 | [diff] [blame] | 21 | from tempest.services.identity.v2.json import token_client as v2_client |
Andrea Frittoli | 9efbe95 | 2015-01-29 12:43:09 +0000 | [diff] [blame] | 22 | from tempest.services.identity.v3.json import token_client as v3_client |
Andrea Frittoli (andreaf) | abf0d6f | 2015-03-23 15:14:02 +0000 | [diff] [blame] | 23 | from tempest.tests import fake_config |
Andrea Frittoli | 9efbe95 | 2015-01-29 12:43:09 +0000 | [diff] [blame] | 24 | from tempest.tests import fake_identity |
Andrea Frittoli (andreaf) | abf0d6f | 2015-03-23 15:14:02 +0000 | [diff] [blame] | 25 | # Note(andreaf): once credentials tests move to tempest-lib, I will copy the |
| 26 | # parts of them required by these here. |
Andrea Frittoli | 9efbe95 | 2015-01-29 12:43:09 +0000 | [diff] [blame] | 27 | from tempest.tests import test_credentials as test_creds |
| 28 | |
| 29 | |
| 30 | class ConfiguredV2CredentialsTests(test_creds.CredentialsTests): |
| 31 | attributes = { |
| 32 | 'username': 'fake_username', |
| 33 | 'password': 'fake_password', |
| 34 | 'tenant_name': 'fake_tenant_name' |
| 35 | } |
| 36 | |
| 37 | identity_response = fake_identity._fake_v2_response |
| 38 | credentials_class = auth.KeystoneV2Credentials |
| 39 | tokenclient_class = v2_client.TokenClientJSON |
| 40 | identity_version = 'v2' |
| 41 | |
| 42 | def setUp(self): |
| 43 | super(ConfiguredV2CredentialsTests, self).setUp() |
Andrea Frittoli (andreaf) | abf0d6f | 2015-03-23 15:14:02 +0000 | [diff] [blame] | 44 | self.useFixture(fake_config.ConfigFixture()) |
| 45 | self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate) |
Andrea Frittoli | 9efbe95 | 2015-01-29 12:43:09 +0000 | [diff] [blame] | 46 | self.stubs.Set(self.tokenclient_class, 'raw_request', |
| 47 | self.identity_response) |
| 48 | |
| 49 | def _verify_credentials(self, credentials_class, filled=True, |
| 50 | identity_version=None): |
| 51 | for ctype in cred_provider.CREDENTIAL_TYPES: |
| 52 | if identity_version is None: |
| 53 | creds = cred_provider.get_configured_credentials( |
| 54 | credential_type=ctype, fill_in=filled) |
| 55 | else: |
| 56 | creds = cred_provider.get_configured_credentials( |
| 57 | credential_type=ctype, fill_in=filled, |
| 58 | identity_version=identity_version) |
| 59 | self._check(creds, credentials_class, filled) |
| 60 | |
| 61 | def test_get_configured_credentials(self): |
| 62 | self.useFixture(fixtures.LockFixture('auth_version')) |
| 63 | self._verify_credentials(credentials_class=self.credentials_class) |
| 64 | |
| 65 | def test_get_configured_credentials_unfilled(self): |
| 66 | self.useFixture(fixtures.LockFixture('auth_version')) |
| 67 | self._verify_credentials(credentials_class=self.credentials_class, |
| 68 | filled=False) |
| 69 | |
| 70 | def test_get_configured_credentials_version(self): |
| 71 | # version specified and not loaded from config |
| 72 | self.useFixture(fixtures.LockFixture('auth_version')) |
| 73 | self._verify_credentials(credentials_class=self.credentials_class, |
| 74 | identity_version=self.identity_version) |
| 75 | |
| 76 | def test_is_valid(self): |
| 77 | creds = self._get_credentials() |
| 78 | self.assertTrue(creds.is_valid()) |
| 79 | |
| 80 | |
| 81 | class ConfiguredV3CredentialsTests(ConfiguredV2CredentialsTests): |
| 82 | attributes = { |
| 83 | 'username': 'fake_username', |
| 84 | 'password': 'fake_password', |
| 85 | 'project_name': 'fake_project_name', |
| 86 | 'user_domain_name': 'fake_domain_name' |
| 87 | } |
| 88 | |
| 89 | credentials_class = auth.KeystoneV3Credentials |
| 90 | identity_response = fake_identity._fake_v3_response |
| 91 | tokenclient_class = v3_client.V3TokenClientJSON |
| 92 | identity_version = 'v3' |
| 93 | |
| 94 | def setUp(self): |
| 95 | super(ConfiguredV3CredentialsTests, self).setUp() |
| 96 | # Additional config items reset by cfg fixture after each test |
| 97 | cfg.CONF.set_default('auth_version', 'v3', group='identity') |
| 98 | # Identity group items |
| 99 | for prefix in ['', 'alt_', 'admin_']: |
| 100 | cfg.CONF.set_default(prefix + 'domain_name', 'fake_domain_name', |
| 101 | group='identity') |