fix(handlers): handle http certbot request

This commit is contained in:
2026-04-21 23:00:31 +02:00
committed by Kleπek
parent 155892a30e
commit 7c824ff1c0
3 changed files with 43 additions and 10 deletions
+36 -8
View File
@@ -1168,6 +1168,11 @@ class TestRequestHandler(BaseHandlerTestCase):
class TestUpgradeHandler(BaseHandlerTestCase):
@typing.override
def setUp(self) -> None:
self.data_dir = self.new_mock()
super().setUp()
def _get_handler(
self,
path: str = "/",
@@ -1183,6 +1188,8 @@ class TestUpgradeHandler(BaseHandlerTestCase):
"127.0.0.1",
unittest.mock.MagicMock(),
params=Parameters(),
registry=self.new_mock(),
token_manager=self.new_mock(),
)
handler.address_string = lambda: "127.0.0.1" # ty:ignore[invalid-assignment]
handler.requestline = f"{method} {path}"
@@ -1193,22 +1200,43 @@ class TestUpgradeHandler(BaseHandlerTestCase):
handler.rfile = rfile if rfile is not None else io.BytesIO()
handler.wfile = io.BytesIO()
handler.logger = unittest.mock.Mock(logging.Logger)
handler.data_dir = self.data_dir
return handler
def test_do_get(self) -> None:
handler = self._get_handler("/file")
with self.expects_status_only(
handler,
http.HTTPStatus.MOVED_PERMANENTLY,
headers={"Location": "https://localhost/file"},
with (
self.expects_status_only(
handler,
http.HTTPStatus.MOVED_PERMANENTLY,
headers={"Location": "https://localhost/file"},
),
self.patch(
"http.server.SimpleHTTPRequestHandler.do_GET",
count=0,
),
self.seal_mocks(),
):
handler.do_GET()
def test_do_get_certbot(self) -> None:
handler = self._get_handler("/.well-known/acme-challenge/abcde")
with (
self.patch(
"http.server.SimpleHTTPRequestHandler.do_GET",
),
self.seal_mocks(),
):
handler.do_GET()
def test_do_head(self) -> None:
handler = self._get_handler("/file")
with self.expects_status_only(
handler,
http.HTTPStatus.MOVED_PERMANENTLY,
headers={"Location": "https://localhost/file"},
with (
self.expects_status_only(
handler,
http.HTTPStatus.MOVED_PERMANENTLY,
headers={"Location": "https://localhost/file"},
),
self.seal_mocks(),
):
handler.do_HEAD()