Skip to content

Commit

Permalink
login: return url uses route_path instead of route_url
Browse files Browse the repository at this point in the history
move http_host to settings fixture
  • Loading branch information
robvdl committed Mar 8, 2024
1 parent 08ac707 commit e528356
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/sambal/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def login(request):
"""Login form."""
# Avoid looping the login page if accessed directly.
if request.matched_route.name == "login":
return_url = request.route_url("home")
return_url = request.route_path("home")
else:
return_url = request.POST.get("return_url", request.url)
return_url = request.POST.get("return_url", request.path)

if request.method == "POST":
if (form := LoginForm(request.POST)) and form.validate():
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def settings():
test_settings["samba.username"] = os.getenv("SAMBAL_SAMBA_USERNAME")
test_settings["samba.password"] = os.getenv("SAMBAL_SAMBA_PASSWORD")
test_settings["samba.realm"] = os.getenv("SAMBAL_SAMBA_REALM")
test_settings["http_host"] = "example.com"
return test_settings


Expand All @@ -25,12 +26,12 @@ def app():


@pytest.fixture
def testapp(app):
def testapp(app, settings):
"""Fixture that returns a Sambal WebTest app."""
return webtest.TestApp(
app,
extra_environ={
"HTTP_HOST": "example.com",
"HTTP_HOST": settings["http_host"],
},
)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def test_login_logout(testapp, settings):
}

response = testapp.post("/login/", login_form, status=302)
assert response.headers["location"] == parser.return_url
expected_url = "http://" + settings["http_host"] + parser.return_url
assert response.headers["location"] == expected_url

response = testapp.get("/", status=200)
assert "Sambal Login" not in response.text
Expand Down

0 comments on commit e528356

Please sign in to comment.