Archived
Add formatting and type checks
This commit is contained in:
1 parent
c0d82eaf26
commit
24747866bc
38 files changed
+800
-265
No files matched your search
+40
-13
@@ -58,7 +58,9 @@ def test_legacy_custom_account_form_is_rejected(tmp_path: Path) -> None:
|
||||
)
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.post("/accounts", data={"mode": "custom", "hostname": "home.example.net", "claim_secret": "legacy"})
|
||||
response = client.post(
|
||||
"/accounts", data={"mode": "custom", "hostname": "home.example.net", "claim_secret": "legacy"}
|
||||
)
|
||||
|
||||
assert response.status_code == 404
|
||||
assert app.state.store.count_accounts() == 0
|
||||
@@ -174,14 +176,18 @@ def test_generated_hostname_must_be_activated_before_updates_work(tmp_path: Path
|
||||
account = app.state.store.get_account_by_management_slug(management_slug)
|
||||
|
||||
assert account["accepted_at"] is None
|
||||
assert client.get(f"/api/v1/router/update/{account['update_slug']}", params={"myip": "203.0.113.9"}).status_code == 404
|
||||
assert (
|
||||
client.get(f"/api/v1/router/update/{account['update_slug']}", params={"myip": "203.0.113.9"}).status_code == 404
|
||||
)
|
||||
|
||||
activated = client.post(f"/m/{management_slug}/activate", data={"csrf": _csrf(created.text)})
|
||||
|
||||
assert activated.status_code == 200
|
||||
assert "Hostname registered" in activated.text
|
||||
assert app.state.store.get_account_by_management_slug(management_slug)["accepted_at"]
|
||||
assert client.get(f"/api/v1/router/update/{account['update_slug']}", params={"myip": "203.0.113.9"}).status_code == 200
|
||||
assert (
|
||||
client.get(f"/api/v1/router/update/{account['update_slug']}", params={"myip": "203.0.113.9"}).status_code == 200
|
||||
)
|
||||
|
||||
|
||||
def test_old_magic_route_is_gone(tmp_path: Path) -> None:
|
||||
@@ -322,7 +328,10 @@ def test_management_dashboard_password_can_be_removed(tmp_path: Path) -> None:
|
||||
|
||||
unlock = client.post(
|
||||
f"/m/{account['management_slug']}/unlock",
|
||||
data={"csrf": _csrf(client.get(f"/m/{account['management_slug']}").text), "dashboard_password": "correct horse"},
|
||||
data={
|
||||
"csrf": _csrf(client.get(f"/m/{account['management_slug']}").text),
|
||||
"dashboard_password": "correct horse",
|
||||
},
|
||||
)
|
||||
assert unlock.status_code == 200
|
||||
|
||||
@@ -430,12 +439,18 @@ def test_management_dashboard_rotates_update_url(tmp_path: Path) -> None:
|
||||
assert "data-secret-toggle" in dashboard.text
|
||||
assert 'type="password"' in dashboard.text
|
||||
|
||||
rotated_update = client.post(f"/m/{account['management_slug']}/rotate", data={"csrf": _csrf(dashboard.text), "action": "update"})
|
||||
rotated_update = client.post(
|
||||
f"/m/{account['management_slug']}/rotate", data={"csrf": _csrf(dashboard.text), "action": "update"}
|
||||
)
|
||||
assert rotated_update.status_code == 200
|
||||
assert "Update URL changed. Update your router now." in rotated_update.text
|
||||
assert "data-secret-input" in rotated_update.text
|
||||
assert client.get(f"/api/v1/router/update/{account['update_slug']}", params={"myip": "203.0.113.9"}).status_code == 404
|
||||
statuses = {event["status"] for event in app.state.store.list_update_events_for_hostname("home.ddns.example.net", 10)}
|
||||
assert (
|
||||
client.get(f"/api/v1/router/update/{account['update_slug']}", params={"myip": "203.0.113.9"}).status_code == 404
|
||||
)
|
||||
statuses = {
|
||||
event["status"] for event in app.state.store.list_update_events_for_hostname("home.ddns.example.net", 10)
|
||||
}
|
||||
assert "dashboard_update_url_rotated" in statuses
|
||||
assert "dashboard_router_credentials_rotated" not in statuses
|
||||
|
||||
@@ -449,13 +464,19 @@ def test_management_dashboard_actions_are_scoped_to_slug_owner(tmp_path: Path) -
|
||||
client = TestClient(app)
|
||||
|
||||
dashboard = client.get(f"/m/{first['management_slug']}")
|
||||
rotated = client.post(f"/m/{first['management_slug']}/rotate", data={"csrf": _csrf(dashboard.text), "action": "update"})
|
||||
rotated = client.post(
|
||||
f"/m/{first['management_slug']}/rotate", data={"csrf": _csrf(dashboard.text), "action": "update"}
|
||||
)
|
||||
|
||||
assert rotated.status_code == 200
|
||||
assert store.get_account_by_hostname("first.ddns.example.net")["update_slug"] != first["update_slug"]
|
||||
assert store.get_account_by_hostname("second.ddns.example.net")["update_slug"] == second["update_slug"]
|
||||
assert client.get(f"/api/v1/router/update/{first['update_slug']}", params={"myip": "203.0.113.1"}).status_code == 404
|
||||
assert client.get(f"/api/v1/router/update/{second['update_slug']}", params={"myip": "203.0.113.2"}).status_code == 200
|
||||
assert (
|
||||
client.get(f"/api/v1/router/update/{first['update_slug']}", params={"myip": "203.0.113.1"}).status_code == 404
|
||||
)
|
||||
assert (
|
||||
client.get(f"/api/v1/router/update/{second['update_slug']}", params={"myip": "203.0.113.2"}).status_code == 200
|
||||
)
|
||||
|
||||
|
||||
def test_locked_dashboard_rejects_mutating_actions_without_unlock_cookie(tmp_path: Path) -> None:
|
||||
@@ -558,7 +579,10 @@ def test_public_examples_use_karldns_domain_and_no_shell_prompt(tmp_path: Path)
|
||||
assert "https://karldns.de/api/v1/router/update/<secret>" in response.text
|
||||
assert "http://127.0.0.1:8099/api/v1/router/update/<secret>" not in response.text
|
||||
assert "$ curl" not in response.text
|
||||
assert 'data-copy="curl -sS 'https://karldns.de/api/v1/router/update/<secret>?myip=203.0.113.10'"' in response.text
|
||||
assert (
|
||||
'data-copy="curl -sS 'https://karldns.de/api/v1/router/update/<secret>?myip=203.0.113.10'"'
|
||||
in response.text
|
||||
)
|
||||
|
||||
|
||||
def test_application_pages_use_stricter_script_csp(tmp_path: Path) -> None:
|
||||
@@ -579,7 +603,10 @@ def test_application_pages_use_stricter_script_csp(tmp_path: Path) -> None:
|
||||
assert "<style>" not in response.text
|
||||
assert "script-src 'self' 'unsafe-inline'" in response.headers["content-security-policy"]
|
||||
assert "style-src 'self'" in response.headers["content-security-policy"]
|
||||
assert "connect-src 'self' https://api4.ipify.org https://api6.ipify.org" in response.headers["content-security-policy"]
|
||||
assert (
|
||||
"connect-src 'self' https://api4.ipify.org https://api6.ipify.org"
|
||||
in response.headers["content-security-policy"]
|
||||
)
|
||||
assert "style-src 'self' 'unsafe-inline'" not in response.headers["content-security-policy"]
|
||||
bootstrap_css = client.get("/bootstrap-subset.css")
|
||||
assert bootstrap_css.status_code == 200
|
||||
@@ -622,7 +649,7 @@ def test_footer_links_and_privacy_page_are_available(tmp_path: Path) -> None:
|
||||
assert 'property="og:image:width" content="1200"' in response.text
|
||||
assert 'property="og:image:height" content="630"' in response.text
|
||||
assert 'name="twitter:card" content="summary_large_image"' in response.text
|
||||
assert 'application/ld+json' in response.text
|
||||
assert "application/ld+json" in response.text
|
||||
assert "NetworkingApplication" in response.text
|
||||
assert "Made with" in response.text
|
||||
assert "❤️" in response.text
|
||||
|
||||
Reference in new issue
Block a user