Fix critical and high audit findings
Fixed findings from the audit reports (SECURITY, QUALITY, PERFORMANCE): - P-001 · Dashboard re-downloads the entire dataset every 5 seconds Re-synced the vendored shared/ snapshot from shared commit 199a5ef. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7dd0d34383
commit
a84a36349b
31 files changed
+653
-6055
No files matched your search
@@ -4,7 +4,13 @@ from fastapi import FastAPI, Request
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from shared_backend import authproxy as ap
|
||||
from shared_backend.authclient import APIError, AuthClient, PublicUser, SessionResult
|
||||
from shared_backend.authclient import (
|
||||
DEFAULT_COOKIE_NAME,
|
||||
APIError,
|
||||
AuthClient,
|
||||
PublicUser,
|
||||
SessionResult,
|
||||
)
|
||||
|
||||
|
||||
class _FakeStore(ap.ProxyStore):
|
||||
@@ -113,14 +119,32 @@ class AuthDisabledModeTests(unittest.TestCase):
|
||||
|
||||
|
||||
class AccessSettingsTests(unittest.TestCase):
|
||||
def test_get_and_put_round_trip_through_the_store(self) -> None:
|
||||
def test_get_is_public_and_put_requires_an_admin_session(self) -> None:
|
||||
store = _FakeStore(login_required=True)
|
||||
client = TestClient(_build_app(store))
|
||||
client = TestClient(_build_app(store, _RoleClient()))
|
||||
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
|
||||
|
||||
response = client.put("/api/auth/access", json={"loginRequired": False})
|
||||
self.assertEqual(response.status_code, 401)
|
||||
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
|
||||
|
||||
client.cookies.set(DEFAULT_COOKIE_NAME, "user-token")
|
||||
response = client.put("/api/auth/access", json={"loginRequired": False})
|
||||
self.assertEqual(response.status_code, 403)
|
||||
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
|
||||
|
||||
client.cookies.set(DEFAULT_COOKIE_NAME, "admin-token")
|
||||
response = client.put("/api/auth/access", json={"loginRequired": False})
|
||||
self.assertEqual(response.json(), {"loginRequired": False})
|
||||
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": False})
|
||||
|
||||
def test_anonymous_put_is_refused_when_authguard_is_not_configured(self) -> None:
|
||||
store = _FakeStore(login_required=True)
|
||||
client = TestClient(_build_app(store))
|
||||
response = client.put("/api/auth/access", json={"loginRequired": False})
|
||||
self.assertEqual(response.status_code, 401)
|
||||
self.assertEqual(client.get("/api/auth/access").json(), {"loginRequired": True})
|
||||
|
||||
def test_internal_update_disables_login_and_uses_admin_identity(self) -> None:
|
||||
store = _FakeStore(login_required=True)
|
||||
client = TestClient(
|
||||
@@ -180,6 +204,16 @@ class _FakeClient(AuthClient):
|
||||
return ["auth_session=; Path=/; Max-Age=0"]
|
||||
|
||||
|
||||
class _RoleClient(_FakeClient):
|
||||
"""Resolves two fixed session tokens to an administrator and an ordinary user."""
|
||||
|
||||
async def me(self, token: str) -> PublicUser:
|
||||
roles = {"admin-token": "superadmin", "user-token": "user"}
|
||||
if token not in roles:
|
||||
raise APIError(401, "unauthenticated")
|
||||
return PublicUser(id=1, username="a", email="a@b.com", role=roles[token])
|
||||
|
||||
|
||||
class EnabledModeSetupAndLoginTests(unittest.TestCase):
|
||||
"""Exercises the real (client is not None) path, including the
|
||||
setup-claim flag's interaction with the store."""
|
||||
|
||||
Reference in new issue
Block a user