The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): cover whole prefix class — font URLs, native chooser, logout landing
Austin Pickett082fae8058b6
diff --git a/hermes_cli/dashboard_auth/login_page.py b/hermes_cli/dashboard_auth/login_page.pyindex b06bfe30651..099154764dd 100644--- a/hermes_cli/dashboard_auth/login_page.py+++ b/hermes_cli/dashboard_auth/login_page.py@@ -479,21 +479,42 @@ def render_login_html(*, next_path: str = "", prefix: str = "") -> str:password_script=_PASSWORD_FORM_SCRIPT if needs_password_script else "",)# Inject the reverse-proxy prefix so the password-login JS can read- # it from the <main> element's data attribute. ``str.replace``- # after ``str.format`` avoids interfering with the CSS ``{{ }}``- # doubling in the template.- if prefix:- html_out = html_out.replace("<main>", f'<main data-prefix="{prefix}">', 1)+ # it from the <main> element's data attribute, and rewrite the font+ # URLs to stay inside the mount. ``str.replace`` after ``str.format``+ # avoids interfering with the CSS ``{{ }}`` doubling in the template.+ return _apply_proxy_prefix(html_out, prefix)+++def _apply_proxy_prefix(html_out: str, prefix: str) -> str:+ """Rewrite a rendered login-family page for a reverse-proxy sub-path.++ Two rewrites, both no-ops when *prefix* is empty (bare-root deploys are+ byte-for-byte unaffected):++ * ``<main>`` gains ``data-prefix`` so the password-login JS (a plain+ string, never ``str.format``-aware) can prepend the prefix to its+ fetch target and post-login landing.+ * ``@font-face`` ``url('/fonts/...')`` becomes ``url('<prefix>/fonts/...')``+ so the fonts load from the mount instead of the origin root (404+ behind a prefix-stripping proxy).+ """+ if not prefix:+ return html_out+ html_out = html_out.replace("<main>", f'<main data-prefix="{prefix}">', 1)+ html_out = html_out.replace("url('/fonts/", f"url('{prefix}/fonts/")return html_outdef render_native_provider_choice_html(*, providers, authorize_path: str, code_challenge: str,- code_challenge_method: str, redirect_uri: str, state: str) -> str:+ code_challenge_method: str, redirect_uri: str, state: str,+ prefix: str = "") -> str:"""Provider picker for a native authorize request with more than one interactive provider.Every link re-enters ``/auth/native/authorize`` with the SAME desktop PKCE inputs plus an- explicit ``provider``, so the choice never leaves the validated native flow.+ explicit ``provider``, so the choice never leaves the validated native flow. ``prefix``+ (from ``X-Forwarded-Prefix``) rewrites the template's font URLs so the page works behind+ a reverse-proxy sub-path; the buttons' ``authorize_path`` is already prefixed by the caller."""common = {"code_challenge": code_challenge, "code_challenge_method": code_challenge_method,"redirect_uri": redirect_uri, "state": state}@@ -505,7 +526,10 @@ def render_native_provider_choice_html(f'Sign in with {html.escape(p.display_name)}</a>')if not buttons:return _EMPTY_HTML- return _LOGIN_HTML_TEMPLATE.format(provider_buttons="\n".join(buttons), password_script="")+ return _apply_proxy_prefix(+ _LOGIN_HTML_TEMPLATE.format(+ provider_buttons="\n".join(buttons), password_script=""),+ prefix)def _render_password_form(provider, next_path: str, *, prefix: str = "") -> str:diff --git a/hermes_cli/dashboard_auth/routes.py b/hermes_cli/dashboard_auth/routes.pyindex 2f8a5e385cb..d1bd6313eb4 100644--- a/hermes_cli/dashboard_auth/routes.py+++ b/hermes_cli/dashboard_auth/routes.py@@ -310,7 +310,8 @@ async def auth_native_authorize(authorize_path=f"{_prefix(request)}/auth/native/authorize",code_challenge=code_challenge,code_challenge_method=code_challenge_method,- redirect_uri=redirect_uri, state=state),+ redirect_uri=redirect_uri, state=state,+ prefix=_prefix(request)),headers=_NO_STORE)if p is None:raise _http(404, f"Unknown provider: {provider!r}")diff --git a/tests/hermes_cli/test_dashboard_auth_prefix.py b/tests/hermes_cli/test_dashboard_auth_prefix.pyindex d3c05110246..fbd7acf8e7f 100644--- a/tests/hermes_cli/test_dashboard_auth_prefix.py+++ b/tests/hermes_cli/test_dashboard_auth_prefix.py@@ -640,3 +640,88 @@ class TestPostLoginLandingPrefix:assert location == "/", (f"direct deploy should redirect to /, got {location!r}")+++# ---------------------------------------------------------------------------+# Whole-class coverage: every root-absolute URL the server-rendered auth+# pages emit (auth links, font URLs, logout landing) honours the prefix+# ---------------------------------------------------------------------------+++class TestLoginPageWholeClassPrefix:+ """Not just the three URLs named in the issue: the ENTIRE rendered page+ must stay inside the proxy mount, and the empty-prefix deploy must be+ byte-identical to today's output."""++ def test_login_page_fonts_prefixed_behind_proxy(self, gated_app_proxied):+ r = gated_app_proxied.get(+ "/login", headers={"X-Forwarded-Prefix": "/hermes"})+ assert r.status_code == 200+ assert "url('/fonts/" not in r.text+ assert "url('/hermes/fonts/" in r.text++ def test_login_page_byte_identical_without_prefix(self, gated_app_direct):+ # No X-Forwarded-Prefix: no data-prefix, no rewritten fonts,+ # bare-root hrefs — the direct deploy is unchanged.+ r = gated_app_direct.get("/login")+ assert r.status_code == 200+ assert "data-prefix" not in r.text+ assert "url('/fonts/" in r.text+ assert 'href="/auth/login?provider=' in r.text++ def test_password_form_script_reads_data_prefix(self, gated_app_proxied):+ """The fetch target is built in the browser from data-prefix; the+ emitted page must carry both the attribute and the JS that reads it+ (the PKCE cookie Path matches the mount, so a root-absolute POST+ would silently drop the cookie and break native login)."""+ r = gated_app_proxied.get(+ "/login", headers={"X-Forwarded-Prefix": "/hermes"})+ html = r.text+ assert "getAttribute('data-prefix')" in html+ assert "fetch(prefix + '/auth/password-login'" in html++ def test_native_chooser_fonts_prefixed_behind_proxy(self):+ """The RFC 8252 desktop provider chooser shares the login template,+ so its font URLs must honour the prefix too (rendered when more+ than one interactive provider is registered)."""+ from tests.hermes_cli.conftest_dashboard_auth import StubAuthProvider+ from hermes_cli.dashboard_auth.login_page import (+ render_native_provider_choice_html)++ class _SecondStub(StubAuthProvider):+ name = "stub2"+ display_name = "Second Stub (test only)"++ html = render_native_provider_choice_html(+ providers=[StubAuthProvider(), _SecondStub()],+ authorize_path="/hermes/auth/native/authorize",+ code_challenge="challenge",+ code_challenge_method="S256",+ redirect_uri="http://127.0.0.1:53123/cb",+ state="cli-state",+ prefix="/hermes",+ )+ assert "url('/fonts/" not in html+ assert "url('/hermes/fonts/" in html+ # The chooser buttons re-enter the mount, not the origin root.+ assert 'href="/hermes/auth/native/authorize?' in html++ def test_native_chooser_bare_root_without_prefix(self):+ from tests.hermes_cli.conftest_dashboard_auth import StubAuthProvider+ from hermes_cli.dashboard_auth.login_page import (+ render_native_provider_choice_html)++ class _SecondStub(StubAuthProvider):+ name = "stub2"+ display_name = "Second Stub (test only)"++ html = render_native_provider_choice_html(+ providers=[StubAuthProvider(), _SecondStub()],+ authorize_path="/auth/native/authorize",+ code_challenge="challenge",+ code_challenge_method="S256",+ redirect_uri="http://127.0.0.1:53123/cb",+ state="cli-state",+ )+ assert "data-prefix" not in html+ assert "url('/fonts/" in html