From 8599aa5d8393e3217e04bd8fb4bca2b2eaa41a69 Mon Sep 17 00:00:00 2001 From: David Stanek Date: Fri, 13 Jun 2014 18:28:36 +0000 Subject: [PATCH] Fixes catalog URL formatting to never return None The old behavior was to return None if the URL template was not a string (or not string-like). This was a mistake because a None should never be able to make its way into the catalog. This is based off of an IRC discussion that spawned from: https://review.openstack.org/#/c/81528/4/keystone/catalog/backends/sql.py Change-Id: I12b0362d3869a3ec8dc1a6fa34e934a221deecbc Partial-bug: #1230279 --- keystone/catalog/core.py | 4 +++- keystone/tests/unit/catalog/test_core.py | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/keystone/catalog/core.py b/keystone/catalog/core.py index fffe95273..743bf7c24 100644 --- a/keystone/catalog/core.py +++ b/keystone/catalog/core.py @@ -37,7 +37,9 @@ def format_url(url, data): try: result = url.replace('$(', '%(') % data except AttributeError: - return None + LOG.error(_('Malformed endpoint - %(url)r is not a string'), + {"url": url}) + raise exception.MalformedEndpoint(endpoint=url) except KeyError as e: LOG.error(_("Malformed endpoint %(url)s - unknown key %(keyerror)s"), {"url": url, diff --git a/keystone/tests/unit/catalog/test_core.py b/keystone/tests/unit/catalog/test_core.py index 37d73e61b..7b142ed98 100644 --- a/keystone/tests/unit/catalog/test_core.py +++ b/keystone/tests/unit/catalog/test_core.py @@ -46,9 +46,10 @@ class FormatUrlTests(testtools.TestCase): def test_formatting_a_non_string(self): def _test(url_template): - expected_url = None - actual_url = core.format_url(url_template, {}) - self.assertEqual(actual_url, expected_url) + self.assertRaises(exception.MalformedEndpoint, + core.format_url, + url_template, + {}) _test(None) _test(object())