~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
test(security): add happy-path coverage to login_required test suite (#3779)
LearningCircuitb3726c702186
diff --git a/tests/security/test_login_required_boundaries.py b/tests/security/test_login_required_boundaries.pyindex 37ec0afea2..02519f7b27 100644--- a/tests/security/test_login_required_boundaries.py+++ b/tests/security/test_login_required_boundaries.py@@ -105,12 +105,34 @@ def client(app):@pytest.fixture(autouse=True)def patch_db_manager():- """Stub the auth db_manager so we don't touch a real database."""+ """Stub the auth db_manager so we don't touch a real database.++ Default is_user_connected=False so the unauthenticated-rejection+ tests don't need to opt in. Tests that want to exercise the+ authenticated 200 path use the `authenticated_client` fixture+ below, which flips this to True and seeds the session.+ """with patch("local_deep_research.web.auth.decorators.db_manager") as mock_dm:mock_dm.is_user_connected.return_value = Falseyield mock_dm+def authenticated_client(client, patch_db_manager):+ """Test client that passes both auth checks in `login_required`:+ a `username` in the session AND `db_manager.is_user_connected` True.++ Without this, every test in the file is one-sided (rejection-only)+ and a regression that breaks the *allow* path of the decorator —+ e.g. the post-rejection branch swallowing valid requests — would+ not be caught by any existing test.+ """+ patch_db_manager.is_user_connected.return_value = True+ with client.session_transaction() as sess:+ sess["username"] = "test-user"+ return client++class TestNewsPageRoutesRequireAuth:"""The four news page routes added in PR #3129 must redirect to loginwhen the caller has no session."""@@ -176,6 +198,82 @@ class TestNewsHealthRouteIsPublic:assert response.status_code == 200+class TestAuthenticatedRequestsArePassedThrough:+ """Happy-path coverage. Without these tests, the entire file only+ verifies that the decorator REJECTS — a regression where it stopped+ ALLOWING valid requests would slip through. Mirrors each rejection+ test class with a positive case at the same URL shape.+ """++ @pytest.mark.parametrize(+ "path",+ [+ "/news/",+ "/news/subscriptions",+ "/news/subscriptions/new",+ "/news/subscriptions/abc-123/edit",+ ],+ )+ def test_authenticated_page_returns_200(self, authenticated_client, path):+ response = authenticated_client.get(path)+ assert response.status_code == 200++ def test_authenticated_news_api_categories_returns_200(+ self, authenticated_client+ ):+ """Counterpart to test_unauthenticated_categories_returns_json_401."""+ response = authenticated_client.get("/news/api/categories")+ assert response.status_code == 200+ assert response.is_json+ assert response.json == {"categories": []}++ def test_authenticated_research_api_limits_returns_200(+ self, authenticated_client+ ):+ """Counterpart to test_unauthenticated_upload_limits_returns_json_401."""+ response = authenticated_client.get("/api/config/limits")+ assert response.status_code == 200+ assert response.is_json+ assert response.json == {"limit": 0}++ def test_authenticated_post_returns_200(self, authenticated_client):+ """Counterpart to test_unauthenticated_post_returns_json_401."""+ response = authenticated_client.post("/news/api/subscribe", json={})+ assert response.status_code == 200+ assert response.is_json+ assert response.json == {"ok": True}+++class TestAuthenticatedButDisconnectedDb:+ """Second branch of the decorator: `username` is in session but+ `db_manager.is_user_connected` is False. This happens when the+ session outlives the encrypted-DB connection (server restart with+ encrypted databases enabled). API paths must get JSON 401 with+ a different error message ("Database connection required") and+ page paths must redirect with the session cleared.+ """++ @pytest.fixture+ def session_without_db(self, client, patch_db_manager):+ # is_user_connected stays False (autouse default), but seed the+ # session so we hit the second decorator branch, not the first.+ patch_db_manager.is_user_connected.return_value = False+ with client.session_transaction() as sess:+ sess["username"] = "test-user"+ return client++ def test_api_path_returns_json_401_db_required(self, session_without_db):+ response = session_without_db.get("/news/api/categories")+ assert response.status_code == 401+ assert response.is_json+ assert response.json["error"] == "Database connection required"++ def test_page_path_redirects_to_login(self, session_without_db):+ response = session_without_db.get("/news/subscriptions")+ assert response.status_code == 302+ assert "/auth/login" in response.location++class TestUnauthorized401ErrorHandler:"""The 401 error handler in app_factory.register_error_handlers mustuse the same _is_api_path detection as the decorator, so that