summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuang Yee <guang.yee@suse.com>2018-10-25 13:01:23 -0700
committerGuang Yee <guang.yee@suse.com>2018-10-26 08:13:39 -0700
commit6779838a242b222672721407cc320672ab24067a (patch)
tree4360754d7b7bb20f390e9c5db402bcf722780236
parentfc51082ef43e316bbfa65c16dd6483af1f2092e7 (diff)
Skip the services with no endpoints when parsing service catalog
When parsing the service catalog to find the source, audit middleware should skip over the services which have no endpoints instead of assuming they will have at least one endpoint. Change-Id: I287873e99338d95baaf20d52ecb3a43763a401fc Closes-Bug: #1800017
Notes
Notes (review): Code-Review+2: Morgan Fainberg <morgan.fainberg@gmail.com> Code-Review+2: Colleen Murphy <colleen@gazlene.net> Workflow+1: Colleen Murphy <colleen@gazlene.net> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Sun, 28 Oct 2018 11:39:32 +0000 Reviewed-on: https://review.openstack.org/613410 Project: openstack/keystonemiddleware Branch: refs/heads/master
-rw-r--r--keystonemiddleware/audit/_api.py5
-rw-r--r--keystonemiddleware/tests/unit/audit/test_audit_api.py17
-rw-r--r--releasenotes/notes/bug-1800017-0e5a9b8f62b5ca60.yaml7
3 files changed, 29 insertions, 0 deletions
diff --git a/keystonemiddleware/audit/_api.py b/keystonemiddleware/audit/_api.py
index d05d732..e692151 100644
--- a/keystonemiddleware/audit/_api.py
+++ b/keystonemiddleware/audit/_api.py
@@ -261,6 +261,11 @@ class OpenStackAuditApi(object):
261 261
262 default_endpoint = None 262 default_endpoint = None
263 for endp in catalog: 263 for endp in catalog:
264 if not endp['endpoints']:
265 self._log.warning(
266 'Skipping service %s as it have no endpoints.',
267 endp['name'])
268 continue
264 endpoint_urls = endp['endpoints'][0] 269 endpoint_urls = endp['endpoints'][0]
265 admin_urlparse = urlparse.urlparse( 270 admin_urlparse = urlparse.urlparse(
266 endpoint_urls.get('adminURL', '')) 271 endpoint_urls.get('adminURL', ''))
diff --git a/keystonemiddleware/tests/unit/audit/test_audit_api.py b/keystonemiddleware/tests/unit/audit/test_audit_api.py
index 367d7d0..1512e9d 100644
--- a/keystonemiddleware/tests/unit/audit/test_audit_api.py
+++ b/keystonemiddleware/tests/unit/audit/test_audit_api.py
@@ -303,6 +303,23 @@ class AuditApiLogicTest(base.BaseAuditMiddlewareTest):
303 payload = self.get_payload('GET', url, environ=env_headers) 303 payload = self.get_payload('GET', url, environ=env_headers)
304 self.assertEqual((payload['target']['addresses'][0]['url']), "unknown") 304 self.assertEqual((payload['target']['addresses'][0]['url']), "unknown")
305 305
306 def test_service_with_no_endpoints(self):
307 env_headers = {'HTTP_X_SERVICE_CATALOG':
308 '''[{"endpoints_links": [],
309 "endpoints": [],
310 "type": "foo",
311 "name": "bar"}]''',
312 'HTTP_X_USER_ID': 'user_id',
313 'HTTP_X_USER_NAME': 'user_name',
314 'HTTP_X_AUTH_TOKEN': 'token',
315 'HTTP_X_PROJECT_ID': 'tenant_id',
316 'HTTP_X_IDENTITY_STATUS': 'Confirmed',
317 'REQUEST_METHOD': 'GET'}
318
319 url = 'http://public_host:8774/v2/' + str(uuid.uuid4()) + '/servers'
320 payload = self.get_payload('GET', url, environ=env_headers)
321 self.assertEqual(payload['target']['name'], "unknown")
322
306 def test_no_auth_token(self): 323 def test_no_auth_token(self):
307 # Test cases where API requests such as Swift list public containers 324 # Test cases where API requests such as Swift list public containers
308 # which does not require an auth token. In these cases, CADF event 325 # which does not require an auth token. In these cases, CADF event
diff --git a/releasenotes/notes/bug-1800017-0e5a9b8f62b5ca60.yaml b/releasenotes/notes/bug-1800017-0e5a9b8f62b5ca60.yaml
new file mode 100644
index 0000000..0b1c75f
--- /dev/null
+++ b/releasenotes/notes/bug-1800017-0e5a9b8f62b5ca60.yaml
@@ -0,0 +1,7 @@
1---
2fixes:
3 - |
4 [`bug 1800017 <https://bugs.launchpad.net/keystonemiddleware/+bug/1800017>`_]
5 Fix audit middleware service catalog parsing for the scenario where a
6 service does not contain any endpoints. In that case, we should just skip
7 over that service.