diff --git a/src/sambal/views/auth.py b/src/sambal/views/auth.py index bf2d5e4..ec930e4 100644 --- a/src/sambal/views/auth.py +++ b/src/sambal/views/auth.py @@ -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(): diff --git a/tests/conftest.py b/tests/conftest.py index 1819834..93c8113 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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"], }, ) diff --git a/tests/test_login.py b/tests/test_login.py index 0936486..f1fa7e1 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -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