Adds a whitelist for endpoint catalog substitution

Change-Id: If02327d70d0143d805969fe927898f08eb84c4c2
Closes-Bug: #1354208
This commit is contained in:
David Stanek
2014-08-15 14:59:48 +00:00
committed by Tristan Cacqueray
parent 9d4e22b497
commit 2989ff257e
5 changed files with 55 additions and 0 deletions

View File

@@ -10,14 +10,26 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo.config import fixture as config_fixture
import testtools
from keystone.catalog import core
from keystone import config
from keystone import exception
CONF = config.CONF
class FormatUrlTests(testtools.TestCase):
def setUp(self):
super(FormatUrlTests, self).setUp()
fixture = self.useFixture(config_fixture.Config(CONF))
fixture.config(
group='catalog',
endpoint_substitution_whitelist=['host', 'port', 'part1', 'part2'])
def test_successful_formatting(self):
url_template = 'http://%(host)s:%(port)d/%(part1)s/%(part2)s'
values = {'host': 'server', 'port': 9090, 'part1': 'A', 'part2': 'B'}
@@ -53,3 +65,12 @@ class FormatUrlTests(testtools.TestCase):
_test(None)
_test(object())
def test_substitution_with_key_not_whitelisted(self):
url_template = 'http://%(host)s:%(port)d/%(part1)s/%(part2)s/%(part3)s'
values = {'host': 'server', 'port': 9090,
'part1': 'A', 'part2': 'B', 'part3': 'C'}
self.assertRaises(exception.MalformedEndpoint,
core.format_url,
url_template,
values)