| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
from osc_lib.cli import client_config |
| 14 |
from osc_lib.test import base |
| 15 |
|
| 16 |
|
| 17 |
class TestOSCConfig(base.TestCase): |
| 18 |
def setUp(self): |
| 19 |
super().setUp() |
| 20 |
|
| 21 |
self.cloud = client_config.OSC_Config() |
| 22 |
|
| 23 |
def test_auth_select_default_plugin(self): |
| 24 |
config = { |
| 25 |
'auth_type': 'admin_token', |
| 26 |
} |
| 27 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 28 |
self.assertEqual('admin_token', ret_config['auth_type']) |
| 29 |
|
| 30 |
def test_auth_select_default_plugin_password(self): |
| 31 |
config = { |
| 32 |
'username': 'fred', |
| 33 |
'user_id': 'fr3d', |
| 34 |
} |
| 35 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 36 |
self.assertEqual('password', ret_config['auth_type']) |
| 37 |
self.assertEqual('fred', ret_config['username']) |
| 38 |
self.assertEqual('fr3d', ret_config['user_id']) |
| 39 |
|
| 40 |
def test_auth_select_default_plugin_password_v2(self): |
| 41 |
config = { |
| 42 |
'identity_api_version': '2', |
| 43 |
'username': 'fred', |
| 44 |
} |
| 45 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 46 |
self.assertEqual('v2password', ret_config['auth_type']) |
| 47 |
self.assertEqual('fred', ret_config['username']) |
| 48 |
|
| 49 |
def test_auth_select_default_plugin_password_v2_int(self): |
| 50 |
config = { |
| 51 |
'identity_api_version': 2, |
| 52 |
'username': 'fred', |
| 53 |
} |
| 54 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 55 |
self.assertEqual('v2password', ret_config['auth_type']) |
| 56 |
self.assertEqual('fred', ret_config['username']) |
| 57 |
|
| 58 |
def test_auth_select_default_plugin_password_v3(self): |
| 59 |
config = { |
| 60 |
'identity_api_version': '3', |
| 61 |
'username': 'fred', |
| 62 |
} |
| 63 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 64 |
self.assertEqual('v3password', ret_config['auth_type']) |
| 65 |
self.assertEqual('fred', ret_config['username']) |
| 66 |
|
| 67 |
def test_auth_select_default_plugin_password_v3_int(self): |
| 68 |
config = { |
| 69 |
'identity_api_version': 3, |
| 70 |
'username': 'fred', |
| 71 |
} |
| 72 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 73 |
self.assertEqual('v3password', ret_config['auth_type']) |
| 74 |
self.assertEqual('fred', ret_config['username']) |
| 75 |
|
| 76 |
def test_auth_select_default_plugin_token(self): |
| 77 |
config = { |
| 78 |
'token': 'subway', |
| 79 |
} |
| 80 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 81 |
self.assertEqual('token', ret_config['auth_type']) |
| 82 |
self.assertEqual('subway', ret_config['token']) |
| 83 |
|
| 84 |
def test_auth_select_default_plugin_token_v2(self): |
| 85 |
config = { |
| 86 |
'identity_api_version': '2.2', |
| 87 |
'token': 'subway', |
| 88 |
} |
| 89 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 90 |
self.assertEqual('v2token', ret_config['auth_type']) |
| 91 |
self.assertEqual('subway', ret_config['token']) |
| 92 |
|
| 93 |
def test_auth_select_default_plugin_token_v3(self): |
| 94 |
config = { |
| 95 |
'identity_api_version': '3', |
| 96 |
'token': 'subway', |
| 97 |
} |
| 98 |
ret_config = self.cloud._auth_select_default_plugin(config) |
| 99 |
self.assertEqual('v3token', ret_config['auth_type']) |
| 100 |
self.assertEqual('subway', ret_config['token']) |
| 101 |
|
| 102 |
def test_auth_v2_arguments(self): |
| 103 |
config = { |
| 104 |
'identity_api_version': '2', |
| 105 |
'auth_type': 'v2password', |
| 106 |
'auth': { |
| 107 |
'username': 'fred', |
| 108 |
}, |
| 109 |
} |
| 110 |
ret_config = self.cloud._auth_v2_arguments(config) |
| 111 |
self.assertEqual('fred', ret_config['auth']['username']) |
| 112 |
self.assertNotIn('tenant_id', ret_config['auth']) |
| 113 |
self.assertNotIn('tenant_name', ret_config['auth']) |
| 114 |
|
| 115 |
config = { |
| 116 |
'identity_api_version': '3', |
| 117 |
'auth_type': 'v3password', |
| 118 |
'auth': { |
| 119 |
'username': 'fred', |
| 120 |
'project_id': 'id', |
| 121 |
}, |
| 122 |
} |
| 123 |
ret_config = self.cloud._auth_v2_arguments(config) |
| 124 |
self.assertEqual('fred', ret_config['auth']['username']) |
| 125 |
self.assertNotIn('tenant_id', ret_config['auth']) |
| 126 |
self.assertNotIn('tenant_name', ret_config['auth']) |
| 127 |
|
| 128 |
config = { |
| 129 |
'identity_api_version': '2', |
| 130 |
'auth_type': 'v2password', |
| 131 |
'auth': { |
| 132 |
'username': 'fred', |
| 133 |
'project_id': 'id', |
| 134 |
}, |
| 135 |
} |
| 136 |
ret_config = self.cloud._auth_v2_arguments(config) |
| 137 |
self.assertEqual('id', ret_config['auth']['tenant_id']) |
| 138 |
self.assertNotIn('tenant_name', ret_config['auth']) |
| 139 |
|
| 140 |
config = { |
| 141 |
'identity_api_version': '2', |
| 142 |
'auth_type': 'v2password', |
| 143 |
'auth': { |
| 144 |
'username': 'fred', |
| 145 |
'project_name': 'name', |
| 146 |
}, |
| 147 |
} |
| 148 |
ret_config = self.cloud._auth_v2_arguments(config) |
| 149 |
self.assertNotIn('tenant_id', ret_config['auth']) |
| 150 |
self.assertEqual('name', ret_config['auth']['tenant_name']) |
| 151 |
|
| 152 |
def test_auth_v2_ignore_v3(self): |
| 153 |
config = { |
| 154 |
'cloud': 'testcloud', |
| 155 |
'identity_api_version': '2', |
| 156 |
'auth_type': 'v2password', |
| 157 |
'auth': { |
| 158 |
'username': 'fred', |
| 159 |
'project_id': 'id', |
| 160 |
'project_domain_id': 'bad', |
| 161 |
}, |
| 162 |
} |
| 163 |
ret_config = self.cloud._auth_v2_ignore_v3(config) |
| 164 |
self.assertEqual('fred', ret_config['auth']['username']) |
| 165 |
self.assertNotIn('project_domain_id', ret_config['auth']) |
| 166 |
|
| 167 |
def test_auth_default_domain_not_set(self): |
| 168 |
config = { |
| 169 |
'identity_api_version': '3', |
| 170 |
'auth_type': 'v3oidcpassword', |
| 171 |
'default_domain': 'default', |
| 172 |
'auth': { |
| 173 |
'username': 'fred', |
| 174 |
'project_id': 'id', |
| 175 |
}, |
| 176 |
} |
| 177 |
ret_config = self.cloud._auth_default_domain(config) |
| 178 |
self.assertEqual('v3oidcpassword', ret_config['auth_type']) |
| 179 |
self.assertEqual('default', ret_config['default_domain']) |
| 180 |
self.assertEqual('fred', ret_config['auth']['username']) |
| 181 |
self.assertNotIn('project_domain_id', ret_config['auth']) |
| 182 |
self.assertNotIn('user_domain_id', ret_config['auth']) |
| 183 |
|
| 184 |
def test_auth_default_domain_use_default(self): |
| 185 |
config = { |
| 186 |
'identity_api_version': '3', |
| 187 |
'auth_type': 'v3password', |
| 188 |
'default_domain': 'default', |
| 189 |
'auth': { |
| 190 |
'username': 'fred', |
| 191 |
'project_id': 'id', |
| 192 |
}, |
| 193 |
} |
| 194 |
ret_config = self.cloud._auth_default_domain(config) |
| 195 |
self.assertEqual('v3password', ret_config['auth_type']) |
| 196 |
self.assertEqual('default', ret_config['default_domain']) |
| 197 |
self.assertEqual('fred', ret_config['auth']['username']) |
| 198 |
self.assertEqual('default', ret_config['auth']['project_domain_id']) |
| 199 |
self.assertEqual('default', ret_config['auth']['user_domain_id']) |
| 200 |
|
| 201 |
def test_auth_default_domain_use_given(self): |
| 202 |
config = { |
| 203 |
'identity_api_version': '3', |
| 204 |
'auth_type': 'v3password', |
| 205 |
'default_domain': 'default', |
| 206 |
'auth': { |
| 207 |
'username': 'fred', |
| 208 |
'project_id': 'id', |
| 209 |
'project_domain_id': 'proj', |
| 210 |
'user_domain_id': 'use', |
| 211 |
}, |
| 212 |
} |
| 213 |
ret_config = self.cloud._auth_default_domain(config) |
| 214 |
self.assertEqual('v3password', ret_config['auth_type']) |
| 215 |
self.assertEqual('default', ret_config['default_domain']) |
| 216 |
self.assertEqual('fred', ret_config['auth']['username']) |
| 217 |
self.assertEqual('proj', ret_config['auth']['project_domain_id']) |
| 218 |
self.assertEqual('use', ret_config['auth']['user_domain_id']) |
| 219 |
|
| 220 |
def test_auth_config_hook_default(self): |
| 221 |
config = {} |
| 222 |
ret_config = self.cloud.auth_config_hook(config) |
| 223 |
self.assertEqual('password', ret_config['auth_type']) |