Archived
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
import asyncio
|
|
|
|
from starlette.responses import HTMLResponse
|
|
|
|
from karldns.routers.management_passwords import (
|
|
_dashboard_password_error,
|
|
_dashboard_password_error_response,
|
|
_DashboardPasswordErrorContext,
|
|
)
|
|
|
|
|
|
def test_dashboard_password_error_requires_minimum_length() -> None:
|
|
assert _dashboard_password_error("short", "short") == "Password must be at least 8 characters."
|
|
|
|
|
|
def test_dashboard_password_error_requires_confirmation_match() -> None:
|
|
assert _dashboard_password_error("correct horse", "different horse") == "The passwords do not match."
|
|
|
|
|
|
def test_dashboard_password_error_accepts_valid_password() -> None:
|
|
assert _dashboard_password_error("correct horse", "correct horse") is None
|
|
|
|
|
|
def test_dashboard_password_error_response_renders_new_password_errors(monkeypatch) -> None:
|
|
async def fake_render_management_page_async(_service: object, context: object) -> str:
|
|
return f"message={context.message}"
|
|
|
|
monkeypatch.setattr(
|
|
"karldns.routers.management_passwords.render_management_page_async",
|
|
fake_render_management_page_async,
|
|
)
|
|
|
|
response = asyncio.run(
|
|
_dashboard_password_error_response(
|
|
object(),
|
|
_DashboardPasswordErrorContext(
|
|
management_slug="manage-secret",
|
|
account={"hostname": "home.example.net"},
|
|
form={"dashboard_password": ["short"], "dashboard_password_confirm": ["short"]},
|
|
request_ip="198.51.100.1",
|
|
current_password_error=None,
|
|
),
|
|
)
|
|
)
|
|
|
|
assert isinstance(response, HTMLResponse)
|
|
assert response.status_code == 400
|
|
assert b"Password must be at least 8 characters." in response.body
|