feat: SPA sites

This commit is contained in:
2026-04-25 19:10:19 +02:00
committed by Kleπek
parent 46a23d2ed0
commit f4f00a290c
9 changed files with 133 additions and 12 deletions
+40
View File
@@ -465,6 +465,29 @@ class TestRequestHandler(BaseHandlerTestCase):
):
handler.do_PUT()
def test_do_put_extract_with_spa(self) -> None:
handler = self._get_handler(
"/path", {"X-Token": "secret", "X-SPA": "index.html", "Content-Length": "1"}
)
handler.rfile.write(b"\0")
with (
self.mock_call(self.token_manager.is_valid, ["secret"], True), # noqa: FBT003
self.mock_call(
self.token_manager.is_valid_for_path,
["secret", "path"],
True, # noqa: FBT003
),
self.mock_call_unchecked(self.data_dir.extract_tar_bytes),
self.mock_call(self.registry.add, ["path"]),
self.mock_call(self.token_manager.set_token, ["path", "secret"]),
self.mock_call(self.registry.set_spa, ["path", "index.html"]),
self.expects_status_only(
handler, http.HTTPStatus.CREATED, "Resource /path/ updated"
),
self.seal_mocks(),
):
handler.do_PUT()
def test_do_put_redirect_with_content(self) -> None:
handler = self._get_handler(
"/path",
@@ -1166,6 +1189,23 @@ class TestRequestHandler(BaseHandlerTestCase):
"",
)
def test_translate_path_spa(self) -> None:
handler = self._get_handler()
with (
self.mock_call(
self.registry.get_from_path, ["path"], Page("path", spa="index.html")
),
self.patch_call(
"http.server.SimpleHTTPRequestHandler.translate_path",
["/path/index.html"],
),
self.seal_mocks(),
):
self.assertEqual(
handler.translate_path("/path/to/thing"),
None,
)
class TestUpgradeHandler(BaseHandlerTestCase):
@typing.override
+6
View File
@@ -33,3 +33,9 @@ class TestPage(BaseTestCase):
str(Page("test_1", with_index=True, host_only=True)),
"/test_1/ (host only)",
)
def test_repr_with_spa(self) -> None:
self.assertEqual(
str(Page("test_1", with_index=True, spa="index.html")),
"/test_1/ (spa: index.html)",
)
+36
View File
@@ -32,11 +32,13 @@ class TestRegistry(BaseTestCase):
["test_1", Registry.TOKEN_FILE],
["test_1", Registry.REDIRECT_FILE],
["test_1", Registry.PROXY_FILE],
["test_1", Registry.SPA_FILE],
["test_2", Registry.HOST_FILE],
["test_2", Registry.HOST_ONLY_FILE],
["test_2", Registry.TOKEN_FILE],
["test_2", Registry.REDIRECT_FILE],
["test_2", Registry.PROXY_FILE],
["test_2", Registry.SPA_FILE],
],
[
None,
@@ -46,9 +48,11 @@ class TestRegistry(BaseTestCase):
None,
None,
None,
None,
"test_2_token",
"test_2_redirect",
None,
None,
],
),
self.seal_mocks(),
@@ -257,6 +261,38 @@ class TestRegistry(BaseTestCase):
self.assertIn("test_1", self.registry.pages)
self.assertEqual(self.registry.pages["test_1"].proxy, "https://new-example.com")
def test_set_spa(self) -> None:
self.registry.pages["test_1"] = Page(
"test_1",
spa=None,
)
with (
self.mock_call(
self.data_dir.set_file,
["test_1", Registry.SPA_FILE, "new_value"],
),
self.seal_mocks(),
):
self.registry.set_spa("test_1", "new_value")
self.assertEqual(self.registry.pages["test_1"].spa, "new_value")
def test_set_spa_no_change(self) -> None:
self.registry.pages["test_1"] = Page(
"test_1",
spa="value",
)
with (
self.seal_mocks(),
):
self.registry.set_spa("test_1", "value")
self.assertEqual(self.registry.pages["test_1"].spa, "value")
def test_set_spa_not_found(self) -> None:
with (
self.seal_mocks(),
):
self.registry.set_spa("test_1", "value")
def test_remove(self) -> None:
self.registry.pages["test_1"] = Page(
"test_1",