blob: 7d48870ee2acffc890ab5d5874352fc9f35419f5 [file] [log] [blame]
DavidPurcellb25f93d2017-01-27 12:46:27 -05001# Copyright 2017 AT&T Corporation.
DavidPurcell029d8c32017-01-06 15:27:41 -05002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Felipe Monteiro2fe986d2018-03-20 21:53:51 +000016import functools
Felipe Monteirob0595652017-01-23 16:51:58 -050017import logging
Felipe Monteiro8eda8cc2017-03-22 14:15:14 +000018import sys
19
Felipe Monteiro44d77842018-03-21 02:42:59 +000020from oslo_log import versionutils
Felipe Monteiro38f344b2017-11-03 12:59:15 +000021from oslo_utils import excutils
Felipe Monteiro8eda8cc2017-03-22 14:15:14 +000022import six
Felipe Monteirob0595652017-01-23 16:51:58 -050023
DavidPurcell029d8c32017-01-06 15:27:41 -050024from tempest import config
25from tempest.lib import exceptions
raiesmh088590c0c2017-03-14 18:06:52 +053026from tempest import test
DavidPurcell029d8c32017-01-06 15:27:41 -050027
Felipe Monteiro88a5bab2017-08-31 04:00:32 +010028from patrole_tempest_plugin import policy_authority
DavidPurcell029d8c32017-01-06 15:27:41 -050029from patrole_tempest_plugin import rbac_exceptions
Rick Bartraed950052017-06-29 17:20:33 -040030from patrole_tempest_plugin import requirements_authority
DavidPurcell029d8c32017-01-06 15:27:41 -050031
32CONF = config.CONF
33LOG = logging.getLogger(__name__)
34
Felipe Monteiro973a1bc2017-06-14 21:23:54 +010035_SUPPORTED_ERROR_CODES = [403, 404]
Cliff Parsons35a77112018-05-07 14:03:40 -050036_DEFAULT_ERROR_CODE = 403
Felipe Monteiro973a1bc2017-06-14 21:23:54 +010037
Sean Pryor7f8993f2017-08-14 12:53:17 -040038RBACLOG = logging.getLogger('rbac_reporting')
39
DavidPurcell029d8c32017-01-06 15:27:41 -050040
Cliff Parsons35a77112018-05-07 14:03:40 -050041def action(service, rule='', rules=None,
42 expected_error_code=_DEFAULT_ERROR_CODE, expected_error_codes=None,
Felipe Monteiro44d77842018-03-21 02:42:59 +000043 extra_target_data=None):
Felipe Monteirof2b58d72017-08-31 22:40:36 +010044 """A decorator for verifying OpenStack policy enforcement.
Felipe Monteirod5d76b82017-03-20 23:18:50 +000045
Felipe Monteiro01d633b2017-08-16 20:17:26 +010046 A decorator which allows for positive and negative RBAC testing. Given:
Rick Bartraed950052017-06-29 17:20:33 -040047
Masayuki Igawa80b9aab2018-01-09 17:00:45 +090048 * an OpenStack service,
49 * a policy action (``rule``) enforced by that service, and
50 * the test role defined by ``[patrole] rbac_test_role``
Felipe Monteirod5d76b82017-03-20 23:18:50 +000051
Felipe Monteiro01d633b2017-08-16 20:17:26 +010052 determines whether the test role has sufficient permissions to perform an
53 API call that enforces the ``rule``.
Felipe Monteirod5d76b82017-03-20 23:18:50 +000054
Felipe Monteiro01d633b2017-08-16 20:17:26 +010055 This decorator should only be applied to an instance or subclass of
Masayuki Igawa80b9aab2018-01-09 17:00:45 +090056 ``tempest.test.BaseTestCase``.
Felipe Monteiro01d633b2017-08-16 20:17:26 +010057
58 The result from ``_is_authorized`` is used to determine the *expected*
59 test result. The *actual* test result is determined by running the
60 Tempest test this decorator applies to.
61
62 Below are the following possibilities from comparing the *expected* and
63 *actual* results:
64
65 1) If *expected* is True and the test passes (*actual*), this is a success.
66 2) If *expected* is True and the test fails (*actual*), this results in a
67 `Forbidden` exception failure.
68 3) If *expected* is False and the test passes (*actual*), this results in
69 an `OverPermission` exception failure.
70 4) If *expected* is False and the test fails (*actual*), this is a success.
71
72 As such, negative and positive testing can be applied using this decorator.
73
Felipe Monteiro44d77842018-03-21 02:42:59 +000074 :param str service: An OpenStack service. Examples: "nova" or "neutron".
75 :param str rule: (DEPRECATED) A policy action defined in a policy.json file
76 or in code.
77 :param list rules: A list of policy actions defined in a policy.json file
78 or in code. The rules are logical-ANDed together to derive the expected
79 result.
Felipe Monteiro01d633b2017-08-16 20:17:26 +010080
81 .. note::
82
83 Patrole currently only supports custom JSON policy files.
84
Felipe Monteiro44d77842018-03-21 02:42:59 +000085 :param int expected_error_code: Overrides default value of 403 (Forbidden)
Felipe Monteiro973a1bc2017-06-14 21:23:54 +010086 with endpoint-specific error code. Currently only supports 403 and 404.
87 Support for 404 is needed because some services, like Neutron,
88 intentionally throw a 404 for security reasons.
Felipe Monteirod5d76b82017-03-20 23:18:50 +000089
Felipe Monteiro01d633b2017-08-16 20:17:26 +010090 .. warning::
91
92 A 404 should not be provided *unless* the endpoint masks a
Felipe Monteirof2b58d72017-08-31 22:40:36 +010093 ``Forbidden`` exception as a ``NotFound`` exception.
Felipe Monteiro01d633b2017-08-16 20:17:26 +010094
Cliff Parsons35a77112018-05-07 14:03:40 -050095 :param list expected_error_codes: When the ``rules`` list parameter is
96 used, then this list indicates the expected error code to use if one
97 of the rules does not allow the role being tested. This list must
98 coincide with and its elements remain in the same order as the rules
99 in the rules list.
100
101 Example::
102 rules=["api_action1", "api_action2"]
103 expected_error_codes=[404, 403]
104
105 a) If api_action1 fails and api_action2 passes, then the expected
106 error code is 404.
107 b) if api_action2 fails and api_action1 passes, then the expected
108 error code is 403.
109 c) if both api_action1 and api_action2 fail, then the expected error
110 code is the first error seen (404).
111
112 If an error code is missing from the list, it is defaulted to 403.
113
Felipe Monteiro44d77842018-03-21 02:42:59 +0000114 :param dict extra_target_data: Dictionary, keyed with ``oslo.policy``
115 generic check names, whose values are string literals that reference
116 nested ``tempest.test.BaseTestCase`` attributes. Used by
117 ``oslo.policy`` for performing matching against attributes that are
118 sent along with the API calls. Example::
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100119
120 extra_target_data={
121 "target.token.user_id":
122 "os_alt.auth_provider.credentials.user_id"
123 })
124
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100125 :raises NotFound: If ``service`` is invalid.
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100126 :raises Forbidden: For item (2) above.
127 :raises RbacOverPermission: For item (3) above.
128
129 Examples::
130
131 @rbac_rule_validation.action(
132 service="nova", rule="os_compute_api:os-agents")
133 def test_list_agents_rbac(self):
Felipe Monteiro1c8620a2018-02-25 18:52:22 +0000134 # The call to `override_role` is mandatory.
135 with self.rbac_utils.override_role(self):
136 self.agents_client.list_agents()
Felipe Monteirod5d76b82017-03-20 23:18:50 +0000137 """
Felipe Monteiro0854ded2017-05-05 16:30:55 +0100138
139 if extra_target_data is None:
140 extra_target_data = {}
141
Cliff Parsons35a77112018-05-07 14:03:40 -0500142 rules, expected_error_codes = _prepare_multi_policy(rule, rules,
143 expected_error_code,
144 expected_error_codes)
Felipe Monteiro44d77842018-03-21 02:42:59 +0000145
Sean Pryor7f8993f2017-08-14 12:53:17 -0400146 def decorator(test_func):
Felipe Monteirof6eb8622017-08-06 06:08:02 +0100147 role = CONF.patrole.rbac_test_role
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100148
Felipe Monteiro2fe986d2018-03-20 21:53:51 +0000149 @functools.wraps(test_func)
DavidPurcell029d8c32017-01-06 15:27:41 -0500150 def wrapper(*args, **kwargs):
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100151 if args and isinstance(args[0], test.BaseTestCase):
152 test_obj = args[0]
153 else:
154 raise rbac_exceptions.RbacResourceSetupFailed(
155 '`rbac_rule_validation` decorator can only be applied to '
156 'an instance of `tempest.test.BaseTestCase`.')
raiesmh088590c0c2017-03-14 18:06:52 +0530157
Felipe Monteiro44d77842018-03-21 02:42:59 +0000158 allowed = True
159 disallowed_rules = []
160 for rule in rules:
161 _allowed = _is_authorized(
162 test_obj, service, rule, extra_target_data)
163 if not _allowed:
164 disallowed_rules.append(rule)
165 allowed = allowed and _allowed
Felipe Monteirod5d76b82017-03-20 23:18:50 +0000166
Cliff Parsons35a77112018-05-07 14:03:40 -0500167 exp_error_code = expected_error_code
168 if disallowed_rules:
169 # Choose the first disallowed rule and expect the error
170 # code corresponding to it.
171 first_error_index = rules.index(disallowed_rules[0])
172 exp_error_code = expected_error_codes[first_error_index]
173 LOG.debug("%s: Expecting %d to be raised for policy name: %s",
174 test_func.__name__, exp_error_code,
175 disallowed_rules[0])
176
Rick Bartra12998942017-03-17 17:35:45 -0400177 expected_exception, irregular_msg = _get_exception_type(
Cliff Parsons35a77112018-05-07 14:03:40 -0500178 exp_error_code)
DavidPurcell029d8c32017-01-06 15:27:41 -0500179
Sean Pryor7f8993f2017-08-14 12:53:17 -0400180 test_status = 'Allowed'
181
DavidPurcell029d8c32017-01-06 15:27:41 -0500182 try:
Sean Pryor7f8993f2017-08-14 12:53:17 -0400183 test_func(*args, **kwargs)
Rick Bartra503c5572017-03-09 13:49:58 -0500184 except rbac_exceptions.RbacInvalidService as e:
Felipe Monteiro48c913d2017-03-15 12:07:48 -0400185 msg = ("%s is not a valid service." % service)
Sean Pryor7f8993f2017-08-14 12:53:17 -0400186 test_status = ('Error, %s' % (msg))
Felipe Monteiro48c913d2017-03-15 12:07:48 -0400187 LOG.error(msg)
188 raise exceptions.NotFound(
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100189 "%s RbacInvalidService was: %s" % (msg, e))
Samantha Blanco36bea052017-07-19 12:01:59 -0400190 except (expected_exception,
191 rbac_exceptions.RbacConflictingPolicies,
192 rbac_exceptions.RbacMalformedResponse) as e:
Sean Pryor7f8993f2017-08-14 12:53:17 -0400193 test_status = 'Denied'
Felipe Monteiro8eda8cc2017-03-22 14:15:14 +0000194 if irregular_msg:
195 LOG.warning(irregular_msg.format(rule, service))
DavidPurcell029d8c32017-01-06 15:27:41 -0500196 if allowed:
Felipe Monteiro44d77842018-03-21 02:42:59 +0000197 msg = ("Role %s was not allowed to perform the following "
198 "actions: %s. Expected allowed actions: %s. "
199 "Expected disallowed actions: %s." % (
200 role, sorted(rules),
201 sorted(set(rules) - set(disallowed_rules)),
202 sorted(disallowed_rules)))
DavidPurcell029d8c32017-01-06 15:27:41 -0500203 LOG.error(msg)
204 raise exceptions.Forbidden(
Felipe Monteiro4bf66a22017-05-07 14:44:21 +0100205 "%s Exception was: %s" % (msg, e))
Felipe Monteiro8eda8cc2017-03-22 14:15:14 +0000206 except Exception as e:
Felipe Monteiro38f344b2017-11-03 12:59:15 +0000207 with excutils.save_and_reraise_exception():
208 exc_info = sys.exc_info()
209 error_details = six.text_type(exc_info[1])
210 msg = ("An unexpected exception has occurred during test: "
211 "%s. Exception was: %s" % (test_func.__name__,
212 error_details))
213 test_status = 'Error, %s' % (error_details)
214 LOG.error(msg)
DavidPurcell029d8c32017-01-06 15:27:41 -0500215 else:
216 if not allowed:
Felipe Monteiro44d77842018-03-21 02:42:59 +0000217 msg = (
218 "OverPermission: Role %s was allowed to perform the "
219 "following disallowed actions: %s" % (
220 role, sorted(disallowed_rules)
221 )
222 )
223 LOG.error(msg)
224 raise rbac_exceptions.RbacOverPermission(msg)
raiesmh088590c0c2017-03-14 18:06:52 +0530225 finally:
Sean Pryor7f8993f2017-08-14 12:53:17 -0400226 if CONF.patrole_log.enable_reporting:
227 RBACLOG.info(
228 "[Service]: %s, [Test]: %s, [Rule]: %s, "
229 "[Expected]: %s, [Actual]: %s",
230 service, test_func.__name__, rule,
231 "Allowed" if allowed else "Denied",
232 test_status)
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100233
Felipe Monteiro2fe986d2018-03-20 21:53:51 +0000234 return wrapper
DavidPurcell029d8c32017-01-06 15:27:41 -0500235 return decorator
Rick Bartra12998942017-03-17 17:35:45 -0400236
237
Cliff Parsons35a77112018-05-07 14:03:40 -0500238def _prepare_multi_policy(rule, rules, exp_error_code, exp_error_codes):
239
240 if exp_error_codes:
241 if not rules:
242 msg = ("The `rules` list must be provided if using the "
243 "`expected_error_codes` list.")
244 raise ValueError(msg)
245 if len(rules) != len(exp_error_codes):
246 msg = ("The `expected_error_codes` list is not the same length "
247 "as the `rules` list.")
248 raise ValueError(msg)
249 if exp_error_code:
250 deprecation_msg = (
251 "The `exp_error_code` argument has been deprecated in favor "
252 "of `exp_error_codes` and will be removed in a future "
253 "version.")
254 versionutils.report_deprecated_feature(LOG, deprecation_msg)
255 LOG.debug("The `exp_error_codes` argument will be used instead of "
256 "`exp_error_code`.")
257 if not isinstance(exp_error_codes, (tuple, list)):
258 exp_error_codes = [exp_error_codes]
259 else:
260 exp_error_codes = []
261 if exp_error_code:
262 exp_error_codes.append(exp_error_code)
263
Felipe Monteiro44d77842018-03-21 02:42:59 +0000264 if rules is None:
265 rules = []
266 elif not isinstance(rules, (tuple, list)):
267 rules = [rules]
268 if rule:
269 deprecation_msg = (
270 "The `rule` argument has been deprecated in favor of `rules` "
271 "and will be removed in a future version.")
272 versionutils.report_deprecated_feature(LOG, deprecation_msg)
273 if rules:
274 LOG.debug("The `rules` argument will be used instead of `rule`.")
275 else:
276 rules.append(rule)
Cliff Parsons35a77112018-05-07 14:03:40 -0500277
278 # Fill in the exp_error_codes if needed. This is needed for the scenarios
279 # where no exp_error_codes array is provided, so the error codes must be
280 # set to the default error code value and there must be the same number
281 # of error codes as rules.
282 num_ecs = len(exp_error_codes)
283 num_rules = len(rules)
284 if (num_ecs < num_rules):
285 for i in range(num_rules - num_ecs):
286 exp_error_codes.append(_DEFAULT_ERROR_CODE)
287
288 return rules, exp_error_codes
Felipe Monteiro44d77842018-03-21 02:42:59 +0000289
290
Felipe Monteiro318a0bf2018-02-27 06:57:10 -0500291def _is_authorized(test_obj, service, rule, extra_target_data):
Felipe Monteirodea13842017-07-05 04:11:18 +0100292 """Validates whether current RBAC role has permission to do policy action.
293
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100294 :param test_obj: An instance or subclass of ``tempest.test.BaseTestCase``.
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100295 :param service: The OpenStack service that enforces ``rule``.
296 :param rule: The name of the policy action. Examples include
297 "identity:create_user" or "os_compute_api:os-agents".
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100298 :param extra_target_data: Dictionary, keyed with ``oslo.policy`` generic
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100299 check names, whose values are string literals that reference nested
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100300 ``tempest.test.BaseTestCase`` attributes. Used by ``oslo.policy`` for
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100301 performing matching against attributes that are sent along with the API
302 calls.
Sean Pryor7f8993f2017-08-14 12:53:17 -0400303
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100304 :returns: True if the current RBAC role can perform the policy action,
305 else False.
Sean Pryor7f8993f2017-08-14 12:53:17 -0400306
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100307 :raises RbacResourceSetupFailed: If `project_id` or `user_id` are missing
308 from the `auth_provider` attribute in `test_obj`.
Felipe Monteirodea13842017-07-05 04:11:18 +0100309 """
Sean Pryor7f8993f2017-08-14 12:53:17 -0400310
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100311 try:
Felipe Monteiroe8d93e02017-07-19 20:52:20 +0100312 project_id = test_obj.os_primary.credentials.project_id
313 user_id = test_obj.os_primary.credentials.user_id
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100314 except AttributeError as e:
Felipe Monteiroe8d93e02017-07-19 20:52:20 +0100315 msg = ("{0}: project_id or user_id not found in os_primary.credentials"
316 .format(e))
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100317 LOG.error(msg)
318 raise rbac_exceptions.RbacResourceSetupFailed(msg)
319
Felipe Monteiro4ef7e532018-03-11 07:17:11 -0400320 role = CONF.patrole.rbac_test_role
321 # Test RBAC against custom requirements. Otherwise use oslo.policy.
322 if CONF.patrole.test_custom_requirements:
323 authority = requirements_authority.RequirementsAuthority(
324 CONF.patrole.custom_requirements_file, service)
325 else:
326 formatted_target_data = _format_extra_target_data(
327 test_obj, extra_target_data)
328 authority = policy_authority.PolicyAuthority(
329 project_id, user_id, service,
330 extra_target_data=formatted_target_data)
331 is_allowed = authority.allowed(rule, role)
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100332
Felipe Monteiro4ef7e532018-03-11 07:17:11 -0400333 if is_allowed:
334 LOG.debug("[Action]: %s, [Role]: %s is allowed!", rule,
335 role)
336 else:
337 LOG.debug("[Action]: %s, [Role]: %s is NOT allowed!",
338 rule, role)
339
340 return is_allowed
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100341
342
Felipe Monteiro973a1bc2017-06-14 21:23:54 +0100343def _get_exception_type(expected_error_code=403):
344 """Dynamically calculate the expected exception to be caught.
345
346 Dynamically calculate the expected exception to be caught by the test case.
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100347 Only ``Forbidden`` and ``NotFound`` exceptions are permitted. ``NotFound``
348 is supported because Neutron, for security reasons, masks ``Forbidden``
349 exceptions as ``NotFound`` exceptions.
Felipe Monteiro973a1bc2017-06-14 21:23:54 +0100350
351 :param expected_error_code: the integer representation of the expected
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100352 exception to be caught. Must be contained in
353 ``_SUPPORTED_ERROR_CODES``.
Felipe Monteiro973a1bc2017-06-14 21:23:54 +0100354 :returns: tuple of the exception type corresponding to
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100355 ``expected_error_code`` and a message explaining that a non-Forbidden
Felipe Monteiro973a1bc2017-06-14 21:23:54 +0100356 exception was expected, if applicable.
357 """
Rick Bartra12998942017-03-17 17:35:45 -0400358 expected_exception = None
359 irregular_msg = None
Felipe Monteiro973a1bc2017-06-14 21:23:54 +0100360
361 if not isinstance(expected_error_code, six.integer_types) \
Sean Pryor7f8993f2017-08-14 12:53:17 -0400362 or expected_error_code not in _SUPPORTED_ERROR_CODES:
Felipe Monteiro973a1bc2017-06-14 21:23:54 +0100363 msg = ("Please pass an expected error code. Currently "
364 "supported codes: {0}".format(_SUPPORTED_ERROR_CODES))
365 LOG.error(msg)
366 raise rbac_exceptions.RbacInvalidErrorCode(msg)
Felipe Monteiro78fc4892017-04-12 21:33:39 +0100367
Rick Bartra12998942017-03-17 17:35:45 -0400368 if expected_error_code == 403:
369 expected_exception = exceptions.Forbidden
370 elif expected_error_code == 404:
371 expected_exception = exceptions.NotFound
372 irregular_msg = ("NotFound exception was caught for policy action "
373 "{0}. The service {1} throws a 404 instead of a 403, "
374 "which is irregular.")
Rick Bartra12998942017-03-17 17:35:45 -0400375
376 return expected_exception, irregular_msg
Felipe Monteirofd1db982017-04-13 21:19:41 +0100377
378
379def _format_extra_target_data(test_obj, extra_target_data):
380 """Formats the "extra_target_data" dictionary with correct test data.
381
382 Before being formatted, "extra_target_data" is a dictionary that maps a
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100383 policy string like "trust.trustor_user_id" to a nested list of
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100384 ``tempest.test.BaseTestCase`` attributes. For example, the attribute list
Masayuki Igawa80b9aab2018-01-09 17:00:45 +0900385 in::
Felipe Monteirofd1db982017-04-13 21:19:41 +0100386
Masayuki Igawa80b9aab2018-01-09 17:00:45 +0900387 "trust.trustor_user_id": "os.auth_provider.credentials.user_id"
Felipe Monteirofd1db982017-04-13 21:19:41 +0100388
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100389 is parsed by iteratively calling ``getattr`` until the value of "user_id"
Masayuki Igawa80b9aab2018-01-09 17:00:45 +0900390 is resolved. The resulting dictionary returns::
Felipe Monteirofd1db982017-04-13 21:19:41 +0100391
Masayuki Igawa80b9aab2018-01-09 17:00:45 +0900392 "trust.trustor_user_id": "the user_id of the `os_primary` credential"
Felipe Monteirofd1db982017-04-13 21:19:41 +0100393
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100394 :param test_obj: An instance or subclass of ``tempest.test.BaseTestCase``.
395 :param extra_target_data: Dictionary, keyed with ``oslo.policy`` generic
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100396 check names, whose values are string literals that reference nested
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100397 ``tempest.test.BaseTestCase`` attributes. Used by ``oslo.policy`` for
Felipe Monteiro01d633b2017-08-16 20:17:26 +0100398 performing matching against attributes that are sent along with the API
399 calls.
400 :returns: Dictionary containing additional object data needed by
Felipe Monteirof2b58d72017-08-31 22:40:36 +0100401 ``oslo.policy`` to validate generic checks.
Felipe Monteirofd1db982017-04-13 21:19:41 +0100402 """
403 attr_value = test_obj
404 formatted_target_data = {}
405
406 for user_attribute, attr_string in extra_target_data.items():
407 attrs = attr_string.split('.')
408 for attr in attrs:
409 attr_value = getattr(attr_value, attr)
410 formatted_target_data[user_attribute] = attr_value
411
412 return formatted_target_data