Tests: Check Location header and body for redirects

This commit is contained in:
Unrud 2022-01-16 13:09:13 +01:00
parent 402bd3580e
commit e0adecf30c
2 changed files with 10 additions and 5 deletions

View File

@ -53,10 +53,11 @@ permissions: RrWw""")
def test_root(self) -> None:
"""GET request at "/"."""
_, answer = self.get("/", check=302)
status, headers, answer = self.request("GET", "/", check=302)
assert headers.get("Location") == ".web"
assert answer == "Redirected to .web"
def test_script_name(self) -> None:
def test_root_script_name(self) -> None:
"""GET request at "/" with SCRIPT_NAME."""
_, answer = self.get("/", check=302, SCRIPT_NAME="/radicale")
assert answer == "Redirected to .web"
@ -65,9 +66,12 @@ permissions: RrWw""")
"""GET request with unsanitized paths."""
for path, sane_path in [("//", "/"), ("", "/"), ("/a//b", "/a/b"),
("/a//b/", "/a/b/")]:
_, answer = self.get(path, check=301)
_, headers, answer = self.request("GET", path, check=301)
assert headers.get("Location") == sane_path
assert answer == "Redirected to %s" % sane_path
_, answer = self.get(path, check=301, SCRIPT_NAME="/radicale")
_, headers, answer = self.request("GET", path, check=301,
SCRIPT_NAME="/radicale")
assert headers.get("Location") == "/radicale%s" % sane_path
assert answer == "Redirected to /radicale%s" % sane_path
def test_add_event(self) -> None:

View File

@ -26,8 +26,9 @@ class TestBaseWebRequests(BaseTest):
"""Test web plugin."""
def test_internal(self) -> None:
_, headers, _ = self.request("GET", "/.web", check=302)
_, headers, answer = self.request("GET", "/.web", check=302)
assert headers.get("Location") == ".web/"
assert answer == "Redirected to .web/"
_, answer = self.get("/.web/")
assert answer
self.post("/.web", check=405)