Exclude static asset extensions from auth redirect middleware

Agent-Logs-Url: https://github.com/christianlouis/dmarq/sessions/3e1fe3d2-54b1-4eb4-90d2-173a5e95d376

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-30 16:36:28 +00:00
parent 420975c1d7
commit 3fb90dbcf6
2 changed files with 56 additions and 0 deletions
+36
View File
@@ -293,3 +293,39 @@ class TestAuthDisabled:
# never be a 302 redirect from the middleware.
res = client.get("/settings", follow_redirects=False)
assert res.status_code != 302
# ── Static asset bypass ───────────────────────────────────────────────────────
class TestStaticAssetBypass:
"""Static assets must never be redirected to the login page."""
@staticmethod
def _logto_configured_mock():
mock_cfg = MagicMock()
mock_cfg.AUTH_DISABLED = False
mock_cfg.logto_configured = True
return mock_cfg
def test_favicon_not_redirected_to_login(self, client: TestClient):
"""GET /favicon.ico without a session must pass through (not redirect to /login)."""
with patch("app.core.config.get_settings") as mock_get_settings:
mock_get_settings.return_value = self._logto_configured_mock()
res = client.get("/favicon.ico", follow_redirects=False)
assert res.status_code != 302
def test_png_asset_not_redirected_to_login(self, client: TestClient):
"""GET /logo.png without a session must pass through."""
with patch("app.core.config.get_settings") as mock_get_settings:
mock_get_settings.return_value = self._logto_configured_mock()
res = client.get("/logo.png", follow_redirects=False)
assert res.status_code != 302
def test_protected_page_still_redirected(self, client: TestClient):
"""GET /dashboard without a session must still redirect to /login."""
with patch("app.core.config.get_settings") as mock_get_settings:
mock_get_settings.return_value = self._logto_configured_mock()
res = client.get("/dashboard", follow_redirects=False)
assert res.status_code == 302
assert res.headers["location"].startswith("/login")