summaryrefslogtreecommitdiff
path: root/keystone/tests/unit/server
diff options
context:
space:
mode:
authorMorgan Fainberg <morgan.fainberg@gmail.com>2018-09-28 13:08:37 -0700
committerMorgan Fainberg <morgan.fainberg@gmail.com>2018-09-28 13:42:24 -0700
commit1efecc92c09d5f691fac1e9373ff123b549ced39 (patch)
tree26b533bb7ce10b865d4da97898e530c1e8b0f836 /keystone/tests/unit/server
parent30bd48c205b489c7cf5a8f718b41f275f72b7fe5 (diff)
downloadkeystone-1efecc92c09d5f691fac1e9373ff123b549ced39.tar.gz
Properly replace flask view args in links
When the API Prefix is used in a Flask API, it is possible the flask view argument specification will bleed through to the self link instead of a properly formated url. The add_self_reference_links mechanism in keystone.server.flask.common now substitutes out the self link to the {} substitution and applies a .format() utilizing the view args to the URI in the self link. Change-Id: Ic5c89c285ed964de7411b273567bb97fcf43da06 closes-bug: #1794552
Diffstat (limited to 'keystone/tests/unit/server')
-rw-r--r--keystone/tests/unit/server/test_keystone_flask.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/keystone/tests/unit/server/test_keystone_flask.py b/keystone/tests/unit/server/test_keystone_flask.py
index bb65c9d10..a0deff326 100644
--- a/keystone/tests/unit/server/test_keystone_flask.py
+++ b/keystone/tests/unit/server/test_keystone_flask.py
@@ -610,3 +610,34 @@ class TestKeystoneFlaskCommon(rest.RestfulTestCase):
self.assertRaises(exception.ValidationError,
flask_common.ResourceBase._normalize_domain_id,
ref=ref_without_domain_id)
+
+ def test_api_prefix_self_referential_link_substitution(self):
+
+ view_arg = uuid.uuid4().hex
+
+ class TestResource(flask_common.ResourceBase):
+ api_prefix = '/<string:test_value>/nothing'
+
+ # use a dummy request context, no enforcement is happening
+ # therefore we don't need the heavy lifting of a full request
+ # run.
+ with self.test_request_context(
+ path='/%s/nothing/values' % view_arg,
+ base_url='https://localhost/'):
+ # explicitly set the view_args, this is a special case
+ # for a synthetic test case, usually one would rely on
+ # a full request stack to set these.
+ flask.request.view_args = {'test_value': view_arg}
+
+ # create dummy ref
+ ref = {'id': uuid.uuid4().hex}
+
+ # add the self referential link
+ TestResource._add_self_referential_link(
+ ref, collection_name='values')
+
+ # Check that the link in fact starts with what we expect
+ # including the explicit view arg.
+ self.assertTrue(ref['links']['self'].startswith(
+ 'https://localhost/v3/%s' % view_arg)
+ )