forked from p15670423/monkey
Island: Remove trailing slashes before registering a URL
Strict slashes seems to not handle a case when URL is defined with a trailing slash, but request is sent without one. Removing trailing slashes before registering a URL will solve the burden of remembering to register URLS without slashes
This commit is contained in:
parent
74ca26657e
commit
5d36b7a981
|
@ -128,7 +128,7 @@ class FlaskDIWrapper:
|
||||||
raise ValueError(f"Resource {resource.__name__} has no defined URLs")
|
raise ValueError(f"Resource {resource.__name__} has no defined URLs")
|
||||||
|
|
||||||
self._reserve_urls(resource.urls)
|
self._reserve_urls(resource.urls)
|
||||||
|
resource.urls = map(lambda url: url.rstrip("/"), resource.urls)
|
||||||
dependencies = self._container.resolve_dependencies(resource)
|
dependencies = self._container.resolve_dependencies(resource)
|
||||||
self._api.add_resource(resource, *resource.urls, resource_class_args=dependencies)
|
self._api.add_resource(resource, *resource.urls, resource_class_args=dependencies)
|
||||||
|
|
||||||
|
|
|
@ -81,3 +81,11 @@ def test_url_check_slash_stripping__path_separation(resource_manager):
|
||||||
# Following shouldn't raise and exception
|
# Following shouldn't raise and exception
|
||||||
resource_manager.add_resource(resource3)
|
resource_manager.add_resource(resource3)
|
||||||
resource_manager.add_resource(resource4)
|
resource_manager.add_resource(resource4)
|
||||||
|
|
||||||
|
|
||||||
|
def test_trailing_slash_removal(resource_manager):
|
||||||
|
bogus_endpoint = "/beef/face"
|
||||||
|
resource3 = get_mock_resource("res3", [f"{bogus_endpoint}/"])
|
||||||
|
resource_manager.add_resource(resource3)
|
||||||
|
registered_rules = resource_manager._api.app.url_map._rules
|
||||||
|
assert any([rule.rule == bogus_endpoint for rule in registered_rules])
|
||||||
|
|
Loading…
Reference in New Issue