Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.7 KB
Raw Blame
"""Registration auto-login must issue a browser-session cookie.

RememberMeMiddleware strips the session cookie's Max-Age only when
_remember_me is explicitly False. The register handler never set it, so
auto-login after registration persisted a 30-day cookie — main issued a
non-permanent (browser-session) cookie there.
"""

import uuid

import pytest
from fastapi.testclient import TestClient


@pytest.fixture(scope="module")
def client():
    from local_deep_research.web.fastapi_app import app

    return TestClient(app, raise_server_exceptions=False)


def _csrf(client):
    client.get("/auth/login")
    r = client.get("/auth/csrf-token")
    return r.json().get("csrf_token", "") if r.status_code == 200 else ""


def test_register_sets_non_persistent_session_cookie(client):
    user = f"cookie_{uuid.uuid4().hex[:8]}"
    pw = "TestPassword123!"  # noqa: S105

    resp = client.post(
        "/auth/register",
        data={
            "username": user,
            "password": pw,
            "confirm_password": pw,
            "acknowledge": "true",
            "csrf_token": _csrf(client),
        },
        follow_redirects=False,
    )
    if resp.status_code != 302:
        pytest.fail(
            f"Registration bootstrap failed: expected 302, got "
            f"{resp.status_code}: {resp.text[:500]}"
        )

    session_cookies = [
        v
        for k, v in resp.headers.multi_items()
        if k.lower() == "set-cookie" and v.lower().startswith("session=")
    ]
    assert session_cookies, "registration set no session cookie"
    cookie = session_cookies[0].lower()
    # A browser-session cookie carries neither Max-Age nor Expires.
    assert "max-age=" not in cookie
    assert "expires=" not in cookie