~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: enforce invalid password-change rejection (#6932)
LearningCircuit14fd7ee4c577
diff --git a/tests/security/test_db_connection_change_password_edges.py b/tests/security/test_db_connection_change_password_edges.pyindex 5c67d575d6..bc6fc2ddc5 100644--- a/tests/security/test_db_connection_change_password_edges.py+++ b/tests/security/test_db_connection_change_password_edges.py@@ -1,4 +1,4 @@-"""``change_password`` edge cases: same-password, empty-new, wrong-old.+"""``change_password`` edge cases: same-password, invalid-new, wrong-old.Incident context (PR #5596): change_password is a credential-takingwrite path built from public pieces (close -> open(old) -> PRAGMA rekey@@ -9,18 +9,10 @@ the INPUT-validation edges:* AB1 rekey to the SAME password: succeeds (True), the single passwordkeeps working cold, data survives, exactly one cache entry afterreopen (no double caching);-* AB2 empty NEW password -- DATA-DESTRUCTION BUG, asserted as an- ``xfail(strict)`` on the correct behavior. ``change_password``- performs NO ``_is_valid_encryption_key`` check on ``new_password``- (the guard exists on create/open only -- ``create_user_database``- and ``open_user_database`` both call it).- The rekey derives a key from the empty string and SUCCEEDS, so the- call returns True -- and the database is then permanently UNOPENABLE:- the old password no longer matches the rekeyed file, and opening with- "" is refused by ``_is_valid_encryption_key`` on the open path. The- test asserts what MUST happen (refuse with False, leave the database- openable with the old password), so it flips to passing the moment the- guard lands.+* AB2 invalid NEW password: raises ValueError before touching the+ database, preserving the canary, salt and existing password. Empty,+ whitespace-only and missing passwords must all be rejected, matching+ the validation on create/open.* AB3 wrong OLD password: clean False (the open(old) inside fails), norekey (old password still opens, the would-be new one still fails),canary intact, salt bytes unchanged, nothing cached afterwards.@@ -112,36 +104,27 @@ def test_change_password_to_same_password_is_a_clean_no_op_rekey(manager):assert _salt_digest(manager, username) == salt_before- strict=True,- reason=(- "change_password must validate new_password with "- "_is_valid_encryption_key before rekeying; today it rekeys to a "- 'key derived from "" and returns True, permanently bricking the '- 'database because the open path refuses "". Fix: add the guard at '- "the top of encrypted_db.py::change_password, mirroring the "- "_is_valid_encryption_key calls in encrypted_db.py::"- "create_user_database and encrypted_db.py::open_user_database."- ),+ "new_password",+ ["", " \t\n", None],+ ids=["empty", "whitespace", "missing"],)-def test_change_password_refuses_an_empty_new_password(manager):- """AB2 (CORRECT behavior, currently unimplemented): an empty new- password must be refused BEFORE the rekey, leaving the database fully- intact and openable with the existing password. Anything else is- silent, unrecoverable data destruction: the rekey succeeds against a- key the open path will never accept again."""+def test_change_password_refuses_invalid_new_password(manager, new_password):+ """AB2: reject an invalid key before rekeying; old credentials work cold."""if not manager.has_encryption:pytest.skip("requires SQLCipher (encrypted mode) to be meaningful")username, password = _make_user(manager, "gap-AB2")salt_before = _salt_digest(manager, username)- assert manager.change_password(username, password, "") is False, (- "change_password accepted an empty new password -- the rekey has "- "already bricked the database at this point"- )+ with pytest.raises(+ ValueError, match="Invalid encryption key: new password"+ ):+ manager.change_password(username, password, new_password)- # The existing credential must still open the database and read data.+ # Reopen cold so a cached connection cannot hide an unwanted rekey.+ assert username not in manager.connections+ assert username not in manager._password_verifiersreopened = manager.open_user_database(username, password)assert reopened is not None, ("the old password no longer opens the database -- the refused "@@ -154,10 +137,9 @@ def test_change_password_refuses_an_empty_new_password(manager):).scalar()== "gap-AB2")- # The empty password is refused on the open path (this part holds- # today and must keep holding).+ # The invalid password must also remain rejected on the open path.with pytest.raises(ValueError, match="Invalid encryption key"):- manager.open_user_database(username, "")+ manager.open_user_database(username, new_password)assert _salt_digest(manager, username) == salt_before