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
This commit is contained in:
parent
7c1a342107
commit
8599aa5d83
@ -37,7 +37,9 @@ def format_url(url, data):
|
|||||||
try:
|
try:
|
||||||
result = url.replace('$(', '%(') % data
|
result = url.replace('$(', '%(') % data
|
||||||
except AttributeError:
|
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:
|
except KeyError as e:
|
||||||
LOG.error(_("Malformed endpoint %(url)s - unknown key %(keyerror)s"),
|
LOG.error(_("Malformed endpoint %(url)s - unknown key %(keyerror)s"),
|
||||||
{"url": url,
|
{"url": url,
|
||||||
|
@ -46,9 +46,10 @@ class FormatUrlTests(testtools.TestCase):
|
|||||||
|
|
||||||
def test_formatting_a_non_string(self):
|
def test_formatting_a_non_string(self):
|
||||||
def _test(url_template):
|
def _test(url_template):
|
||||||
expected_url = None
|
self.assertRaises(exception.MalformedEndpoint,
|
||||||
actual_url = core.format_url(url_template, {})
|
core.format_url,
|
||||||
self.assertEqual(actual_url, expected_url)
|
url_template,
|
||||||
|
{})
|
||||||
|
|
||||||
_test(None)
|
_test(None)
|
||||||
_test(object())
|
_test(object())
|
||||||
|
Loading…
Reference in New Issue
Block a user