Skip to content

Commit

Permalink
Force trailing slash in base_url capabilities field (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem authored Dec 2, 2021
1 parent de1e94a commit c4c4ef7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changelog
6.2.0 (unreleased)
------------------

- Nothing changed yet.
**New features**

- ``base_url`` field in server's capabilities will be added a trailing slash (``/``)
if missing.


6.1.0 (2020-06-23)
Expand Down
4 changes: 4 additions & 0 deletions kinto_attachment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def includeme(config):
extra_base_url = settings.get('attachment.extra.base_url',
settings.get('attachment.base_url'))

# Force trailing slash since attachment locations have no leading slash.
if extra_base_url and not extra_base_url.endswith("/"):
extra_base_url += "/"

# Expose capability.
config.add_api_capability("attachments",
version=__version__,
Expand Down
7 changes: 7 additions & 0 deletions kinto_attachment/tests/test_plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ def test_includeme_raises_error_if_wrong_resource_settings_is_defined(self):
self.includeme(settings={"attachment.resources.fennec.base_path": "foobar"})
assert str(excinfo.value) == ('`base_path` is not a supported setting name. '
'Read `attachment.resources.fennec.base_path`')

def test_base_url_is_added_a_trailing_slash(self):
config = self.includeme(settings={
"attachment.base_path": "/tmp",
"attachment.base_url": "http://cdn.com",
})
assert config.registry.api_capabilities["attachments"]["base_url"] == "http://cdn.com/"

0 comments on commit c4c4ef7

Please sign in to comment.