mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 09:45:24 -04:00
allow user who disable auth to use chat (#2548)
* allow user who disable auth to use chat * only check non user on verify session owner * fix import source * rollback 401 to 403 for unauthorized error due to unit test * change unauthenticated http code error to 401 and fix unit tests
This commit is contained in:
@@ -11,7 +11,7 @@ from core.session_manager import SessionManager
|
||||
from core.models import ChatMessage
|
||||
from src.request_models import SessionResponse
|
||||
from core.database import Session as DbSession, SessionLocal, Document, GalleryImage
|
||||
from src.auth_helpers import get_current_user, effective_user
|
||||
from src.auth_helpers import get_current_user, effective_user, _auth_disabled
|
||||
|
||||
|
||||
def _sanitize_export_filename(name: str) -> str:
|
||||
@@ -106,8 +106,8 @@ def _verify_session_owner(request: Request, session_id: str, session_manager=Non
|
||||
that only care about persisted sessions keep their exact prior behavior.
|
||||
"""
|
||||
user = effective_user(request)
|
||||
if not user:
|
||||
raise HTTPException(403, "Authentication required")
|
||||
if not user and not _auth_disabled():
|
||||
raise HTTPException(401, "Authentication required")
|
||||
db = SessionLocal()
|
||||
try:
|
||||
row = db.query(DbSession.owner).filter(DbSession.id == session_id).first()
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ def get_current_user(request: Request) -> Optional[str]:
|
||||
return getattr(request.state, 'current_user', None)
|
||||
|
||||
|
||||
def effective_user(request: Request):
|
||||
def effective_user(request: Request) -> Optional[str]:
|
||||
"""The real human behind the request, for ownership/attribution.
|
||||
|
||||
Cookie sessions resolve to the logged-in username. Bearer ``ody_`` callers
|
||||
|
||||
@@ -109,7 +109,7 @@ def test_unauthenticated_still_403(monkeypatch):
|
||||
sm = SimpleNamespace(sessions={"ghost": SimpleNamespace(owner=None)})
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
SR._verify_session_owner(_req(api_token=False, current_user=None), "ghost", sm)
|
||||
assert exc.value.status_code == 403
|
||||
assert exc.value.status_code == 401
|
||||
|
||||
|
||||
# --- manager layer: delete_session clears memory-only ghosts ---------------
|
||||
|
||||
@@ -136,4 +136,4 @@ def test_unauthenticated_caller_rejected(monkeypatch):
|
||||
req = _req(api_token=False, current_user=None)
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
SR._verify_session_owner(req, "sid")
|
||||
assert exc.value.status_code == 403
|
||||
assert exc.value.status_code == 401
|
||||
|
||||
Reference in New Issue
Block a user