blob: 76430ac012b4932cdf48c00a4ef327352b46c313 [file] [log] [blame]
Andrea Frittoli9efbe952015-01-29 12:43:09 +00001# 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 Hellmann583ce2c2015-03-11 14:55:46 +000015from oslo_config import cfg
Andrea Frittoli9efbe952015-01-29 12:43:09 +000016
17from tempest import auth
18from tempest.common import cred_provider
19from tempest.common import tempest_fixtures as fixtures
Andrea Frittoli (andreaf)abf0d6f2015-03-23 15:14:02 +000020from tempest import config
Jamie Lennoxc429e6a2015-02-24 10:42:42 +110021from tempest.services.identity.v2.json import token_client as v2_client
Andrea Frittoli9efbe952015-01-29 12:43:09 +000022from tempest.services.identity.v3.json import token_client as v3_client
Andrea Frittoli (andreaf)abf0d6f2015-03-23 15:14:02 +000023from tempest.tests import fake_config
Andrea Frittoli9efbe952015-01-29 12:43:09 +000024from tempest.tests import fake_identity
Andrea Frittoli (andreaf)abf0d6f2015-03-23 15:14:02 +000025# Note(andreaf): once credentials tests move to tempest-lib, I will copy the
26# parts of them required by these here.
Andrea Frittoli9efbe952015-01-29 12:43:09 +000027from tempest.tests import test_credentials as test_creds
28
29
30class 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)abf0d6f2015-03-23 15:14:02 +000044 self.useFixture(fake_config.ConfigFixture())
45 self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
Andrea Frittoli9efbe952015-01-29 12:43:09 +000046 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
81class 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')