From b9618e57c5b1fcc04a35ae9d36f5f11ba1257ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 14 Nov 2023 16:55:01 +0100 Subject: [PATCH] fix exception when file does not exist fixes https://git.clan.lol/clan/clan-core/issues/488 --- pkgs/clan-cli/clan_cli/webui/routers/root.py | 2 ++ pkgs/clan-cli/tests/test_static_files.py | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 pkgs/clan-cli/tests/test_static_files.py diff --git a/pkgs/clan-cli/clan_cli/webui/routers/root.py b/pkgs/clan-cli/clan_cli/webui/routers/root.py index 77f460e08..550c6851a 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/root.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/root.py @@ -30,6 +30,8 @@ async def root(path_name: str) -> Response: if not filename.is_file(): log.error("File not found: %s", filename) return Response(status_code=404) + else: + return Response(status_code=404) content_type, _ = guess_type(filename) return Response(filename.read_bytes(), media_type=content_type) diff --git a/pkgs/clan-cli/tests/test_static_files.py b/pkgs/clan-cli/tests/test_static_files.py new file mode 100644 index 000000000..4db1e3aa2 --- /dev/null +++ b/pkgs/clan-cli/tests/test_static_files.py @@ -0,0 +1,10 @@ +import pytest +from api import TestClient + + +@pytest.mark.impure +def test_static_files(api: TestClient) -> None: + response = api.get("/") + assert response.headers["content-type"] == "text/html; charset=utf-8" + response = api.get("/does-no-exists.txt") + assert response.status_code == 404