Skip to content

Commit

Permalink
fix: Redirect after authentication on http://localhost without /
Browse files Browse the repository at this point in the history
* fix: manage root path properly when we join them
  • Loading branch information
FabienArcellier committed Aug 9, 2024
1 parent 4ad359e commit 447f581
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/writer/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,17 @@ def urljoin(*args):
>>> "app1/edit"
>>> urljoin("/app1/", "/edit")
>>> "app1/edit"
>>> "/app1/edit"
"""
root_part = args[0]
root_part_is_root_path = root_part.startswith('/') and len(root_part) > 1

url_strip_parts = []
for part in args:
if part:
url_strip_parts.append(urlstrip(part))

return '/'.join(url_strip_parts)
return '/'.join(url_strip_parts) if root_part_is_root_path is False else '/' + '/'.join(url_strip_parts)

def urlstrip(url_path: str):
"""
Expand Down
5 changes: 4 additions & 1 deletion tests/backend/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def test_basicauth_authentication_module_disabled_when_server_setup_hook_is_disa
("http://localhost", "/"),
("http://localhost/", "/"),
("http://localhost/any", "/any"),
("http://localhost/any/", "/any/")
("http://localhost/any/", "/any/"),
("/any/yolo", "/any/yolo")
])
def test_url_path_scenarios(self, path: str, expected_path: str):
assert auth.urlpath(path) == expected_path
Expand All @@ -63,6 +64,8 @@ def test_url_split_scenarios(self, path: str, expected_path: str):
@pytest.mark.parametrize("path1,path2,expected_path", [
("/", "any", "/any"),
("", "any", "any"),
("/yolo", "any", "/yolo/any"),
("/yolo", "/any", "/yolo/any"),
("http://localhost", "any", "http://localhost/any"),
("http://localhost/", "/any", "http://localhost/any"),
("http://localhost/yolo", "/any", "http://localhost/yolo/any"),
Expand Down

0 comments on commit 447f581

Please sign in to comment.